1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
unit nvUtilities;
{$mode objfpc}{$H+}
// disable to remove debugging output
{$Define DEBUG}
interface
uses
Classes, SysUtils, fpg_base;
const
{ TODO -oGraeme : Should this change to LineEnding (platfrom dependant) }
EndLine= chr(13)+chr(10);
TwoEndLines= chr(13)+chr(10)+chr(13)+chr(10);
Quote = '''';
DoubleQuote = '"';
// Removes and returns the first value in a separated
// value list (removes quotes if found)
Function ExtractNextValue(
var S: string;
const Separator: string ): string;
Function ExtractNextValueNoTrim(
var S: string;
const Separator: string ): string;
// Alias method which is the same as Move() but with less confusing name
procedure MemCopy(const src; var dest; size: SizeInt);
// Allows for debug output and quite disable of output
procedure ProfileEvent(const AString: string);
// Return AFilename's size in bytes
function GetFileSize(const AFilename: string): integer;
function IsDigit(const AChar: TfpgChar): boolean;
function IsAlpha(const AChar: TfpgChar): boolean;
implementation
//uses
// character // from utf8tools package (pulls in LCL requirement which we MUST change)
// ;
Function ExtractNextValue( var S: string;
const Separator: string ): string;
begin
Result := ExtractNextValueNoTrim( S, Separator );
Result := trim( Result );
// Remove quotes if present
if Result <> '' then
if Result[ 1 ] = DoubleQuote then
Delete( Result, 1, 1 );
if Result <> '' then
if Result[ length( Result ) ] = DoubleQuote then
Delete( Result, length( Result ), 1 );
end;
Function ExtractNextValueNoTrim( var S: string;
const Separator: string ): string;
Var
SeparatorPos: integer;
Begin
SeparatorPos := Pos( Separator, S );
if SeparatorPos > 0 then
begin
Result := Copy( S, 1, SeparatorPos-1 );
Delete( S, 1, SeparatorPos + length( Separator ) - 1 );
end
else
begin
Result := S;
S := '';
end;
end;
procedure MemCopy(const src; var dest; size: SizeInt);
begin
Move(src, dest, size);
end;
procedure ProfileEvent(const AString: string);
begin
{$IFDEF DEBUG}
writeln('DEBUG: ', AString);
{$ENDIF}
end;
function GetFileSize(const AFilename: string): integer;
var
f: File;
begin
Result := 0;
Assign(f, AFileName);
{$i-}
Reset(f);
{$i+}
Result := FileSize(f);
CloseFile(f);
end;
function IsDigit(const AChar: TfpgChar): boolean;
begin
{ TODO -oGraeme -cunicode : Not utf-8 compliant. }
Result := ( AChar>='0' ) and ( AChar<='9' );
//Result := TCharacter.IsDigit(AChar);
end;
function IsAlpha(const AChar: TfpgChar): boolean;
var
UppercaseC: TfpgChar;
Begin
{ TODO -oGraeme -cunicode : Not utf-8 compliant. }
UppercaseC := UpperCase( AChar );
Result := ( UppercaseC >= 'A' ) and ( UppercaseC <= 'Z' );
//Result := TCharacter.IsLetter(AChar);
end;
end.
|