From ac6a07afa7d6c1e739683a6fd70febdebe6ff141 Mon Sep 17 00:00:00 2001 From: tobigun Date: Sat, 22 Mar 2008 11:55:59 +0000 Subject: 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 --- Game/Code/Classes/UCommon.pas | 66 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 65 insertions(+), 1 deletion(-) (limited to 'Game/Code') 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. -- cgit v1.2.3