-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathASGRout3_unicode.pas
429 lines (385 loc) · 12.1 KB
/
ASGRout3_unicode.pas
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
{*_* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Author: Albert Drent
Description: ASGRout parser routines
Creation: Januari 1998
Version: 1.2.B
EMail: [email protected] (www.aducom.com)
Support: [email protected] (www.aducom.com)
Legal issues: Copyright (C) 2003 by Aducom Software
Aducom Software
Eckhartstr 61
9746 BN Groningen
Netherlands
This software is provided 'as-is', without any express or
implied warranty. In no event will the author be held liable
for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any
purpose, including commercial applications, and to alter it
and redistribute it freely, subject to the following
restrictions:
1. The origin of this software must not be misrepresented,
you must not claim that you wrote the original software.
If you use this software in a product, an acknowledgment
in the product documentation would be appreciated but is
not required.
2. Altered source versions must be plainly marked as such, and
must not be misrepresented as being the original software.
3. If you make changes which improves the component you must
mail these to aducom as the moderator of the components
complete with documentation for the benefits of the community.
4. You are not allowed to create commercial available components
using this software. If you use this source in any way to create
your own components, your source should be free of charge,
available to anyone. It's a far better idea to distribute your
changes through Aducom Software.
5. This notice may not be removed or altered from any source
distribution.
6. You must register this software by entering the support forum.
I like to keep track about where the components are used, so
sending a picture postcard to the author would be appreciated.
Use a nice stamp and mention your name, street
address, EMail address and any comment you like to say.
Modifications
26/5/2004 Function YYYYMMDDParser by JPierce, necessary for
locale independent datehandling in SQLite components.
1/9/2005 Changes to the StrToFloatX routine, now depending on
decimalseparator.
*_* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * }
{$I asqlite_def.inc}
{$WARNINGS OFF}
unit ASGRout3_unicode;
interface
uses SysUtils;
const
vtcIdentifier = 1;
vtcNumber = 2;
vtcAssignment = 3;
vtcQString = 4;
vtcDString = 5;
vtcRelOp = 6;
vtcFloat = 7;
vtcDelimiter = 8;
vtcEof = 9;
function GetWord(var InString: string; var StartPos: integer;
var VarType: integer): string;
function GetWordByDelim(var InString: string; var StartPos: integer;
var Delim: string): string;
function Recover(var InString: string; var StartPos: integer): boolean;
function StrToIntX(StrIn: string): integer;
function StrToFloatX(StrIn : string) : extended;
function StrToDateX(TheDate: string): TDateTime;
function StrToDateTimeX(const S: string): TDateTime;
function StrToTimeX(TheTime : string): TDateTime;
function YYYYMMDDParser(Str: PChar): TDateTime;
function FloatParser(Str: string): string;// jordi march
function WStrCopy(Dest: PWideChar; const Source: PWideChar): PWideChar;
implementation
function WStrCopy(Dest: PWideChar; const Source: PWideChar): PWideChar;
var
Src : PWideChar;
begin
Result := Dest;
Src := Source;
while (Src^ <> #$00) do begin
Dest^ := Src^;
Inc(Src);
Inc(Dest);
end;
Dest^ := #$00;
end;
function FloatParser(Str: string): string;// jordi march
var
Point: Byte;
begin
if {$IFDEF ASQLite_XEPLUS}FormatSettings.{$ENDIF}DecimalSeparator <> '.' then begin
Point := Pos ('.', Str);
if Point <> 0
then Str[Point] := {$IFDEF ASQLite_XEPLUS}FormatSettings.{$ENDIF}DecimalSeparator;
end;
Result := Str;
end;
//==============================================================================
// Convert dates to a correct datetime notation. Try several notations,
// starting with the system defaults
//==============================================================================
function StrToDateTimeX(const S: string): TDateTime;
begin
if S = '' then
StrToDateTimeX := 0
else begin
try
StrToDateTimeX := StrToDateTime(S);
except
StrToDateTimeX := StrToDateX(s);
end;
end;
end;
function StrToDateX(TheDate: string): TDateTime;
var
DateFormat: string;
DateSep: char;
function StrToDateDefX(TheDate : string) : TDateTime;
var p : integer;
begin
// first delete time part if there is some
p := pos(' ',TheDate);
if p > 0 then Delete(TheDate, p, 99);
result := StrToDateDef(TheDate, -1.5); //!!!Jure: This will not yield an exception, but will still detect if the conversion could not be done
end;
begin
DateFormat := {$IFDEF ASQLite_XEPLUS}FormatSettings.{$ENDIF}ShortDateFormat; // save current settings
DateSep := {$IFDEF ASQLite_XEPLUS}FormatSettings.{$ENDIF}DateSeparator;
try
StrToDateX := StrToDateDefX(TheDate);
if result = -1.5 then begin
{$IFDEF ASQLite_XEPLUS}FormatSettings.{$ENDIF}DateSeparator := '-';
{$IFDEF ASQLite_XEPLUS}FormatSettings.{$ENDIF}ShortDateFormat := 'dd-mm-yyyy';
result := StrToDateDefX(TheDate);
if result = -1.5 then begin
{$IFDEF ASQLite_XEPLUS}FormatSettings.{$ENDIF}ShortDateFormat := 'yyyy-mm-dd';
try
result := Trunc(StrToDateTime(TheDate));
except
result := StrToDateX('01-01-1900');
raise;
end;
end;
end;
finally
{$IFDEF ASQLite_XEPLUS}FormatSettings.{$ENDIF}ShortDateFormat := DateFormat;
{$IFDEF ASQLite_XEPLUS}FormatSettings.{$ENDIF}DateSeparator := DateSep;
end;
end;
function StrToTimeX(TheTime : string): TDateTime;
var p : integer;
begin
p := pos(' ', TheTime);
if p > 0 then Delete(TheTime, 1, p);
p := pos('.', TheTime);
if p > 0 then Delete(TheTime, p,99);
try
StrToTimeX := StrToTime(TheTime);
except
StrToTimeX := 0;
end;
end;
// Routine submitted by jpierce, modified to accept more types
// It requires that the date be in strict yyyy-mm-dd [hh:nn:[ss[:mmm]]]
function YYYYMMDDParser(Str: PChar): TDateTime;
var
Year, Month, Day, Hour, Min, Sec, MSec: Word;
begin
Result := 0;
try
if Length(Str) >= 10 then // 10 = Length of YYYY-MM-DD
begin
Year := StrToInt(Copy(Str, 1, 4));
Month := StrToInt(Copy(Str, 6, 2));
Day := StrToInt(Copy(Str, 9, 2));
Result := EncodeDate(Year, Month, Day);
end;
if Length(Str) > 10 then // it has a time
begin
Hour := StrToInt(Copy(Str, 12, 2));
Min := StrToInt(Copy(Str, 15, 2));
Sec := 0;
MSec := 0;
if Length(Str) > 16 then Sec := StrToInt(Copy(Str, 18, 2));
if Length(Str) > 19 then Msec := StrToInt(Copy(Str, 21, 3));
Result := Result + EncodeTime(Hour, Min, Sec, MSec);
end;
except
Result := 0;
end;
end;
function StrToIntX(StrIn: string): integer;
var
E: Integer;
begin
Val(StrIn, Result, E);
if E <> 0 then Result := 0;
end;
function StrToFloatX(StrIn : string) : extended;
begin
if not TextToFloat(PChar(StrIn), Result, fvExtended) then
Result := 0;
end;
function Recover(var InString: string;
var StartPos: integer): boolean;
begin
if (StartPos > Length(InString)) then
begin
Recover := false;
exit;
end;
while (Startpos < Length(InString)) and
( not (CharInSet(InString[StartPos], [ #10, #13]))) do
Inc(StartPos);
Recover := true;
end;
function GetWordByDelim(var InString: string;
var StartPos: integer;
var Delim: string): string;
var
Ret: string;
begin
Ret := '';
while (StartPos <= Length(InString)) and (InString[StartPos] = ' ') do
Inc(StartPos);
while (StartPos <= Length(InString)) and (Pos(InString[StartPos], Delim) = 0) do
begin
Ret := Ret + InString[StartPos];
Inc(StartPos);
end;
GetWordByDelim := Trim(Ret);
end;
function GetWord(var InString: string; var StartPos: integer;
var VarType: integer): string;
var
TheChar: char;
Rv: string;
begin
if (StartPos > Length(InString)) then
begin
GetWord := '';
VarType := vtcEof;
exit;
end;
while (StartPos <= Length(InString)) and (InString[StartPos] <= #32) do
Inc(StartPos);
TheChar := InString[StartPos];
Rv := '';
if CharInSet(TheChar, ['a'..'z', 'A'..'Z']) then
VarType := vtcIdentifier
else if CharInSet(TheChar, ['0'..'9', '-']) then
VarType := vtcNumber
else if TheChar = ':' then
VarType := vtcAssignment
else if TheChar = '"' then
VarType := vtcDString
else if TheChar = '''' then
VarType := vtcQString
else if CharInSet(TheChar, ['>', '=', '<']) then
VarType := vtcRelOp
else
begin
Inc(StartPos);
if TheChar = '!' then
begin
Recover(InString, StartPos);
Rv := GetWord(InString, StartPos, VarType);
GetWord := Rv;
end
else
begin
GetWord := TheChar;
end;
exit;
end;
case VarType of
vtcIdentifier:
begin
while CharInSet(InString[StartPos], ['a'..'z', 'A'..'Z', '_','0'..'9']) do
begin
Rv := Rv + InString[StartPos];
Inc(StartPos);
end;
end;
vtcNumber:
begin
while CharInSet(InString[StartPos], ['-', '0'..'9', '.']) do
begin
if InString[StartPos] = '.' then
VarType := vtcFloat;
Rv := Rv + InString[StartPos];
Inc(StartPos);
end;
if VarType = vtcFloat then
Rv := FloatToStr(StrToFloat(Rv))
else
Rv := IntToStr(StrToInt(Rv));
end;
vtcAssignment:
begin
Rv := InString[StartPos];
Inc(StartPos);
if InString[StartPos] = '=' then
begin
Inc(StartPos);
Rv := ':=';
end
else
begin
VarType := vtcDelimiter;
Rv := ':';
end;
end;
vtcQString:
begin
Inc(StartPos);
while InString[StartPos] <> '''' do
begin
Rv := Rv + InString[StartPos];
Inc(StartPos);
end;
Inc(StartPos);
end;
vtcDString:
begin
Inc(StartPos);
while InString[StartPos] <> '"' do
begin
Rv := Rv + InString[StartPos];
Inc(StartPos);
end;
Inc(StartPos);
end;
vtcRelOp:
begin
Rv := InString[StartPos];
if Rv = '<' then
begin
if CharInSet(InString[StartPos + 1], ['=', '>']) then
begin
Rv := Rv + InString[StartPos + 1];
StartPos := StartPos + 2;
end
else
begin
Inc(StartPos);
end;
end
else if Rv = '>' then
begin
if CharInSet(InString[StartPos + 1], ['=', '<']) then
begin
Rv := Rv + InString[StartPos + 1];
StartPos := StartPos + 2;
end
else
begin
Inc(StartPos);
end;
end
else
begin
Inc(StartPos);
end;
end;
end;
GetWord := Rv;
end;
{$IFDEF SQLite_Static}
Var
TZInfo :_TIME_ZONE_INFORMATION;
TZRes :Integer;
initialization
PInteger(@__timezone)^:=0;
PInteger(@__daylight)^:=0;
TZRes:=GetTimezoneInformation(TZInfo);
if TZRes>=0 Then
PInteger(@__timezone)^:=TZInfo.Bias*60;
if TZRes=TIME_ZONE_ID_DAYLIGHT Then
PInteger(@__daylight)^:=1;
{$ENDIF}
end.