1 | Unit 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 |
|
---|
9 | Interface
|
---|
10 |
|
---|
11 | uses
|
---|
12 | Classes;
|
---|
13 |
|
---|
14 | const
|
---|
15 | CharTAB = chr(9);
|
---|
16 | CharCR = chr(13);
|
---|
17 | CharLF = chr(10);
|
---|
18 |
|
---|
19 |
|
---|
20 | TYPE
|
---|
21 | TSetOfChars = set of char;
|
---|
22 |
|
---|
23 | // Returns true if aChar is a digit 0..9
|
---|
24 | Function CharIsDigit(const aChar : char) : boolean;
|
---|
25 |
|
---|
26 | // Returns true if aChar is an alphabetic character a..z A..Z
|
---|
27 | Function CharIsAlpha(const aChar : char) : boolean;
|
---|
28 |
|
---|
29 |
|
---|
30 | // ---------------
|
---|
31 | // ---- PChar ----
|
---|
32 | // ---------------
|
---|
33 |
|
---|
34 |
|
---|
35 | // Converts a PChar into a String like StrPas
|
---|
36 | // but conversts at least the first aLength chars
|
---|
37 | Function StrPasWithLength(const aPChar: PChar; const aLength: integer) : String;
|
---|
38 |
|
---|
39 | // Returns the difference of the pointers
|
---|
40 | Function PCharPointerDiff(const aMinuend: PChar; const aSubtrahend : PChar) : Longword;
|
---|
41 |
|
---|
42 | Implementation
|
---|
43 |
|
---|
44 | uses
|
---|
45 | SysUtils;
|
---|
46 |
|
---|
47 | Function CharIsDigit(const aChar : char) : boolean;
|
---|
48 | begin
|
---|
49 | Result := (aChar >= '0') and (aChar <= '9');
|
---|
50 | end;
|
---|
51 |
|
---|
52 | Function CharIsAlpha(const aChar : char) : boolean;
|
---|
53 | begin
|
---|
54 | Result := ( (aChar >= 'A') and (aChar <= 'Z') ) or ((aChar >= 'a') and (aChar <= 'z'));
|
---|
55 | end;
|
---|
56 |
|
---|
57 |
|
---|
58 | // ---------------
|
---|
59 | // ---- PChar ----
|
---|
60 | // ---------------
|
---|
61 |
|
---|
62 |
|
---|
63 | // Converts a PChar into a String like StrPas
|
---|
64 | // but conversts at least the first aLength chars
|
---|
65 | Function StrPasWithLength(const aPChar: PChar; const aLength: integer) : String;
|
---|
66 | var
|
---|
67 | i: integer;
|
---|
68 | begin
|
---|
69 | Result := '';
|
---|
70 | i := 0;
|
---|
71 | while (aPChar[i] <> #0) and (i < aLength) do
|
---|
72 | begin
|
---|
73 | Result := Result + aPChar[i];
|
---|
74 | inc( i );
|
---|
75 | end;
|
---|
76 | end;
|
---|
77 |
|
---|
78 |
|
---|
79 | Function PCharPointerDiff(const aMinuend: PChar; const aSubtrahend : PChar) : Longword;
|
---|
80 | begin
|
---|
81 | Result := Longword(aMinuend) - Longword(aSubtrahend);
|
---|
82 | end;
|
---|
83 |
|
---|
84 |
|
---|
85 | END.
|
---|