aboutsummaryrefslogtreecommitdiffstats
path: root/Game/Code/Classes
diff options
context:
space:
mode:
authortobigun <tobigun@b956fd51-792f-4845-bead-9b4dfca2ff2c>2008-03-22 11:55:59 +0000
committertobigun <tobigun@b956fd51-792f-4845-bead-9b4dfca2ff2c>2008-03-22 11:55:59 +0000
commitac6a07afa7d6c1e739683a6fd70febdebe6ff141 (patch)
tree15279fdcae83d44d89b40297862e39bcf50d3361 /Game/Code/Classes
parent2b61bc56091f285f69a6450162cc920448546991 (diff)
downloadusdx-ac6a07afa7d6c1e739683a6fd70febdebe6ff141.tar.gz
usdx-ac6a07afa7d6c1e739683a6fd70febdebe6ff141.tar.xz
usdx-ac6a07afa7d6c1e739683a6fd70febdebe6ff141.zip
Added functions to determine to which character-class (alpha(=letter), numeric, punctuation etc.) a character belongs. Neither delphi's nor fpc's RTL (in contrast to Java) has such a function, has it?
git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@968 b956fd51-792f-4845-bead-9b4dfca2ff2c
Diffstat (limited to 'Game/Code/Classes')
-rw-r--r--Game/Code/Classes/UCommon.pas66
1 files changed, 65 insertions, 1 deletions
diff --git a/Game/Code/Classes/UCommon.pas b/Game/Code/Classes/UCommon.pas
index abff538f..c5dde0c8 100644
--- a/Game/Code/Classes/UCommon.pas
+++ b/Game/Code/Classes/UCommon.pas
@@ -66,6 +66,17 @@ function AdaptFilePaths( const aPath : widestring ): widestring;
// eddie: FindFirstW etc are now in UPlatformWindows.pas
+(*
+ * 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;
+
+
implementation
function StringReplaceW(text : WideString; search, rep: WideChar):WideString;
@@ -138,7 +149,7 @@ var
iCount : Integer;
begin
result := nil;
-
+
for iCount := 0 to LazarusResources.count -1 do
begin
if ( LazarusResources.items[ iCount ].Name = aName ) AND
@@ -214,4 +225,57 @@ end;
{$ENDIF} // IFDEF FPC
+function IsAlphaChar(ch: WideChar): boolean;
+begin
+ // TODO: add chars > 255 when unicode-fonts work?
+ case ch of
+ 'A'..'Z', // A-Z
+ 'a'..'z', // a-z
+ #170,#181,#186,
+ #192..#214,
+ #216..#246,
+ #248..#255:
+ Result := true;
+ else
+ Result := false;
+ end;
+end;
+
+function IsNumericChar(ch: WideChar): boolean;
+begin
+ case ch of
+ '0'..'9':
+ Result := true;
+ else
+ Result := false;
+ end;
+end;
+
+function IsAlphaNumericChar(ch: WideChar): boolean;
+begin
+ Result := (IsAlphaChar(ch) or IsNumericChar(ch));
+end;
+
+function IsPunctuationChar(ch: WideChar): boolean;
+begin
+ // TODO: add chars outside of Latin1 basic (0..127)?
+ case ch of
+ ' '..'/',':'..'@','['..'`','{'..'~':
+ Result := true;
+ else
+ Result := false;
+ end;
+end;
+
+function IsControlChar(ch: WideChar): boolean;
+begin
+ case ch of
+ #0..#31,
+ #127..#159:
+ Result := true;
+ else
+ Result := false;
+ end;
+end;
+
end.