aboutsummaryrefslogtreecommitdiffstats
path: root/unicode/src/base
diff options
context:
space:
mode:
Diffstat (limited to 'unicode/src/base')
-rw-r--r--unicode/src/base/UCommon.pas40
-rw-r--r--unicode/src/base/UUnicodeUtils.pas129
2 files changed, 129 insertions, 40 deletions
diff --git a/unicode/src/base/UCommon.pas b/unicode/src/base/UCommon.pas
index 234e4ddb..f5697916 100644
--- a/unicode/src/base/UCommon.pas
+++ b/unicode/src/base/UCommon.pas
@@ -46,28 +46,26 @@ uses
type
TMessageType = ( mtInfo, mtError );
-procedure ShowMessage( const msg : String; msgType: TMessageType = mtInfo );
+procedure ShowMessage(const msg : String; msgType: TMessageType = mtInfo);
procedure ConsoleWriteLn(const msg: string);
function RWopsFromStream(Stream: TStream): PSDL_RWops;
{$IFDEF FPC}
-function RandomRange(aMin: Integer; aMax: Integer) : Integer;
+function RandomRange(aMin: Integer; aMax: Integer): Integer;
{$ENDIF}
-function StringReplaceW(text : WideString; search, rep: WideChar):WideString;
-function AdaptFilePaths( const aPath : widestring ): widestring;
-
procedure DisableFloatingPointExceptions();
procedure SetDefaultNumericLocale();
procedure RestoreNumericLocale();
{$IFNDEF MSWINDOWS}
- procedure ZeroMemory( Destination: Pointer; Length: DWORD );
+ procedure ZeroMemory(Destination: Pointer; Length: DWORD);
function MakeLong(a, b: Word): Longint;
{$ENDIF}
+function AdaptFilePaths(const aPath: widestring): widestring;
function FileExistsInsensitive(var FileName: string): boolean;
// A stable alternative to TList.Sort() (use TList.Sort() if applicable, see below)
@@ -84,7 +82,8 @@ uses
{$IFDEF Delphi}
Dialogs,
{$ENDIF}
- UMain;
+ UMain,
+ UUnicodeUtils;
// data used by the ...Locale() functions
@@ -207,33 +206,6 @@ begin
exOverflow, exUnderflow, exPrecision]);
end;
-function StringReplaceW(text : WideString; search, rep: WideChar) : WideString;
-var
- iPos : integer;
-// sTemp : WideString;
-begin
-(*
- result := text;
- iPos := Pos(search, result);
- while (iPos > 0) do
- begin
- sTemp := copy(result, iPos + length(search), length(result));
- result := copy(result, 1, iPos - 1) + rep + sTEmp;
- iPos := Pos(search, result);
- end;
-*)
- result := text;
-
- if search = rep then
- exit;
-
- for iPos := 1 to length(result) do
- begin
- if result[iPos] = search then
- result[iPos] := rep;
- end;
-end;
-
function AdaptFilePaths( const aPath : widestring ): widestring;
begin
result := StringReplaceW( aPath, '\', PathDelim );//, [rfReplaceAll] );
diff --git a/unicode/src/base/UUnicodeUtils.pas b/unicode/src/base/UUnicodeUtils.pas
index 3608444e..01c279bd 100644
--- a/unicode/src/base/UUnicodeUtils.pas
+++ b/unicode/src/base/UUnicodeUtils.pas
@@ -43,11 +43,20 @@ uses
* Character classes
*)
-function IsAlphaChar(ch: WideChar): boolean;
-function IsNumericChar(ch: WideChar): boolean;
-function IsAlphaNumericChar(ch: WideChar): boolean;
-function IsPunctuationChar(ch: WideChar): boolean;
-function IsControlChar(ch: WideChar): boolean;
+function IsAlphaChar(ch: WideChar): boolean; overload;
+function IsAlphaChar(ch: UCS4Char): boolean; overload;
+
+function IsNumericChar(ch: WideChar): boolean; overload;
+function IsNumericChar(ch: UCS4Char): boolean; overload;
+
+function IsAlphaNumericChar(ch: WideChar): boolean; overload;
+function IsAlphaNumericChar(ch: UCS4Char): boolean; overload;
+
+function IsPunctuationChar(ch: WideChar): boolean; overload;
+function IsPunctuationChar(ch: UCS4Char): boolean; overload;
+
+function IsControlChar(ch: WideChar): boolean; overload;
+function IsControlChar(ch: UCS4Char): boolean; overload;
{*
* String format conversion
@@ -62,6 +71,17 @@ function UCS4ToUTF8String(ch: UCS4Char): UTF8String; overload;
*}
function LengthUTF8(const str: UTF8String): integer;
+function UTF8CompareStr(const S1, S2: UTF8String): integer;
+function UTF8CompareText(const S1, S2: UTF8String): integer;
+
+function UTF8StartsText(const SubText, Text: UTF8String): boolean;
+
+function UTF8ContainsStr(const Text, SubText: UTF8String): boolean;
+function UTF8ContainsText(const Text, SubText: UTF8String): boolean;
+
+function UTF8UpperCase(const str: UTF8String): UTF8String;
+function UTF8LowerCase(const str: UTF8String): UTF8String;
+
{**
* Converts a UCS-4 char ch to its upper-case representation.
*}
@@ -91,10 +111,10 @@ function UCS4CharToString(ch: UCS4Char): UCS4String;
function WideStringUpperCase(const str: WideString) : WideString; overload;
function WideStringUpperCase(ch: WideChar): WideString; overload;
+function StringReplaceW(const text : WideString; search, rep: WideChar): WideString;
implementation
-
function IsAlphaChar(ch: WideChar): boolean;
begin
{$IFDEF MSWINDOWS}
@@ -115,6 +135,11 @@ begin
{$ENDIF}
end;
+function IsAlphaChar(ch: UCS4Char): boolean;
+begin
+ Result := IsAlphaChar(WideChar(Ord(ch)));
+end;
+
function IsNumericChar(ch: WideChar): boolean;
begin
// ignore non-arabic numerals as we do not want to handle them
@@ -126,11 +151,21 @@ begin
end;
end;
+function IsNumericChar(ch: UCS4Char): boolean;
+begin
+ Result := IsNumericChar(WideChar(Ord(ch)));
+end;
+
function IsAlphaNumericChar(ch: WideChar): boolean;
begin
Result := (IsAlphaChar(ch) or IsNumericChar(ch));
end;
+function IsAlphaNumericChar(ch: UCS4Char): boolean;
+begin
+ Result := (IsAlphaChar(ch) or IsNumericChar(ch));
+end;
+
function IsPunctuationChar(ch: WideChar): boolean;
begin
// TODO: add chars > 255?
@@ -143,6 +178,11 @@ begin
end;
end;
+function IsPunctuationChar(ch: UCS4Char): boolean;
+begin
+ Result := IsPunctuationChar(WideChar(Ord(ch)));
+end;
+
function IsControlChar(ch: WideChar): boolean;
begin
case ch of
@@ -154,6 +194,11 @@ begin
end;
end;
+function IsControlChar(ch: UCS4Char): boolean;
+begin
+ Result := IsControlChar(WideChar(Ord(ch)));
+end;
+
function UTF8ToUCS4String(const str: UTF8String): UCS4String;
begin
Result := WideStringToUCS4String(UTF8Decode(str));
@@ -174,6 +219,51 @@ begin
Result := Length(UTF8ToUCS4String(str));
end;
+function UTF8CompareStr(const S1, S2: UTF8String): integer;
+begin
+ // FIXME
+ Result := WideCompareStr(UTF8Decode(S1), UTF8Decode(S2));
+end;
+
+function UTF8CompareText(const S1, S2: UTF8String): integer;
+begin
+ // FIXME
+ Result := WideCompareText(UTF8Decode(S1), UTF8Decode(S2));
+end;
+
+function UTF8StartsStr(const SubText, Text: UTF8String): boolean;
+begin
+ // TODO: use WideSameStr ()?
+ Result := (Pos(SubText, Text) = 1);
+end;
+
+function UTF8StartsText(const SubText, Text: UTF8String): boolean;
+begin
+ // TODO: use WideSameText?
+ Result := (Pos(UTF8UpperCase(SubText), UTF8UpperCase(Text)) = 1);
+end;
+
+function UTF8ContainsStr(const Text, SubText: UTF8String): boolean;
+begin
+ Result := Pos(SubText, Text) > 0;
+end;
+
+function UTF8ContainsText(const Text, SubText: UTF8String): boolean;
+begin
+ Result := Pos(UTF8UpperCase(SubText), UTF8UpperCase(Text)) > 0;
+end;
+
+function UTF8UpperCase(const str: UTF8String): UTF8String;
+begin
+ Result := UTF8Encode(WideStringUpperCase(UTF8Decode(str)));
+end;
+
+function UTF8LowerCase(const str: UTF8String): UTF8String;
+begin
+ // FIXME
+ Result := UTF8Encode(WideLowerCase(UTF8Decode(str)));
+end;
+
function UCS4UpperCase(ch: UCS4Char): UCS4Char;
begin
Result := UCS4UpperCase(UCS4CharToString(ch))[0];
@@ -226,4 +316,31 @@ begin
{$ENDIF}
end;
+function StringReplaceW(const text : WideString; search, rep: WideChar) : WideString;
+var
+ iPos : integer;
+// sTemp : WideString;
+begin
+(*
+ result := text;
+ iPos := Pos(search, result);
+ while (iPos > 0) do
+ begin
+ sTemp := copy(result, iPos + length(search), length(result));
+ result := copy(result, 1, iPos - 1) + rep + sTEmp;
+ iPos := Pos(search, result);
+ end;
+*)
+ result := text;
+
+ if search = rep then
+ exit;
+
+ for iPos := 1 to length(result) do
+ begin
+ if result[iPos] = search then
+ result[iPos] := rep;
+ end;
+end;
+
end.