source: branches/2.19_branch/NewView/CharUtilsUnit.pas@ 292

Last change on this file since 292 was 139, checked in by RBRi, 18 years ago

more refactoring

  • Property svn:eol-style set to native
File size: 1.9 KB
Line 
1Unit CharUtilsUnit;
2
3// NewView - a new OS/2 Help Viewer
4// Copyright 2006-2007 Ronald Brill (rbri at rbri dot de)
5// This software is released under the GNU Public License - see readme.txt
6
7// Helper functions to work with characters
8
9Interface
10
11uses
12 Classes;
13
14const
15 CharTAB = chr(9);
16 CharCR = chr(13);
17 CharLF = chr(10);
18 CharSingleQuote = '''';
19 CharDoubleQuote = '"';
20
21
22 TYPE
23 TSetOfChars = set of char;
24
25 // Returns true if aChar is a digit 0..9
26 Function CharIsDigit(const aChar : char) : boolean;
27
28 // Returns true if aChar is an alphabetic character a..z A..Z
29 Function CharIsAlpha(const aChar : char) : boolean;
30
31
32 // ---------------
33 // ---- PChar ----
34 // ---------------
35
36
37 // Converts a PChar into a String like StrPas
38 // but conversts at least the first aLength chars
39 Function StrPasWithLength(const aPChar: PChar; const aLength: integer) : String;
40
41 // Returns the difference of the pointers
42 Function PCharPointerDiff(const aMinuend: PChar; const aSubtrahend : PChar) : Longword;
43
44Implementation
45
46 uses
47 SysUtils;
48
49 Function CharIsDigit(const aChar : char) : boolean;
50 begin
51 Result := (aChar >= '0') and (aChar <= '9');
52 end;
53
54 Function CharIsAlpha(const aChar : char) : boolean;
55 begin
56 Result := ( (aChar >= 'A') and (aChar <= 'Z') ) or ((aChar >= 'a') and (aChar <= 'z'));
57 end;
58
59
60 // ---------------
61 // ---- PChar ----
62 // ---------------
63
64
65 // Converts a PChar into a String like StrPas
66 // but conversts at least the first aLength chars
67 Function StrPasWithLength(const aPChar: PChar; const aLength: integer) : String;
68 var
69 i: integer;
70 begin
71 Result := '';
72 i := 0;
73 while (aPChar[i] <> #0) and (i < aLength) do
74 begin
75 Result := Result + aPChar[i];
76 inc( i );
77 end;
78 end;
79
80
81 Function PCharPointerDiff(const aMinuend: PChar; const aSubtrahend : PChar) : Longword;
82 begin
83 Result := Longword(aMinuend) - Longword(aSubtrahend);
84 end;
85
86
87END.
Note: See TracBrowser for help on using the repository browser.