aboutsummaryrefslogtreecommitdiffstats
path: root/unicode
diff options
context:
space:
mode:
authortobigun <tobigun@b956fd51-792f-4845-bead-9b4dfca2ff2c>2008-11-08 11:45:31 +0000
committertobigun <tobigun@b956fd51-792f-4845-bead-9b4dfca2ff2c>2008-11-08 11:45:31 +0000
commit9d8f99daaf1a165634775f3a338c528e9c15bc32 (patch)
treec45842ed3c112cffe55788d5a217c3161dfaaeb1 /unicode
parenta2e503feafa5c964573cf9854f89f047ae389b41 (diff)
downloadusdx-9d8f99daaf1a165634775f3a338c528e9c15bc32.tar.gz
usdx-9d8f99daaf1a165634775f3a338c528e9c15bc32.tar.xz
usdx-9d8f99daaf1a165634775f3a338c528e9c15bc32.zip
FPC still does not convert the #0 char to a WideString with length 1. WideStringUpperCase overloaded to handle this correctly (was WideCharUpperCase previously)
git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/branches/experimental@1512 b956fd51-792f-4845-bead-9b4dfca2ff2c
Diffstat (limited to 'unicode')
-rw-r--r--unicode/src/base/UUnicodeUtils.pas24
1 files changed, 21 insertions, 3 deletions
diff --git a/unicode/src/base/UUnicodeUtils.pas b/unicode/src/base/UUnicodeUtils.pas
index c39ec211..3608444e 100644
--- a/unicode/src/base/UUnicodeUtils.pas
+++ b/unicode/src/base/UUnicodeUtils.pas
@@ -88,7 +88,8 @@ function UCS4CharToString(ch: UCS4Char): UCS4String;
* character access, convert to UCS-4 where each character is represented by
* one UCS4Char.
*)
-function WideStringUpperCase(const str: WideString) : WideString;
+function WideStringUpperCase(const str: WideString) : WideString; overload;
+function WideStringUpperCase(ch: WideChar): WideString; overload;
implementation
@@ -193,18 +194,35 @@ begin
Result[1] := 0;
end;
+function WideStringUpperCase(ch: WideChar): WideString;
+begin
+ // If WideChar #0 is converted to a WideString in Delphi, a string with
+ // length 1 and a single char #0 is returned. In FPC an empty (length=0)
+ // string will be returned. This will crash, if a non printable key was
+ // pressed, its char code (#0) is translated to upper-case and the the first
+ // character is accessed with Result[1].
+ // We cannot catch this error in the WideString parameter variant as the string
+ // has length 0 already.
+
+ // Force min. string length of 1
+ if (ch = #0) then
+ Result := #0
+ else
+ Result := WideStringUpperCase(WideString(ch));
+end;
+
function WideStringUpperCase(const str: WideString): WideString;
begin
// On Linux and MacOSX the cwstring unit is necessary for Unicode function-calls.
// Otherwise you will get an EIntOverflow exception (thrown by unimplementedwidestring()).
// The Unicode manager cwstring does not work with MacOSX at the moment because
- // of missing references to iconv. So we have to use Ansi... for the moment.
+ // of missing references to iconv.
{.$IFNDEF DARWIN}
{$IFDEF NOIGNORE}
Result := WideUpperCase(str)
{$ELSE}
- Result := UTF8Decode(AnsiUpperCase(UTF8Encode(str)));
+ Result := UTF8Decode(UpperCase(UTF8Encode(str)));
{$ENDIF}
end;