6 ConstantsClass
, TypesClass
,
9 function AddressToString(Address
: Pointer): String;
10 function CartesianOfStrings(First
: String; Second
: TStrings
): TStrings
;
11 function CodeToHexadecimal(Input
: String): String;
12 function ContainsCharacter(Input
: String; Character
: Char): Boolean;
13 function CustomDataToHex(Input
: PChar
; Size
: Integer): String;
14 function CustomFloatToStr(Input
: PChar
; Size
: Integer): String;
15 function EqualBeforeFirstParser(First
, Second
: String; Parser
: Char): Boolean;
16 function IsAddress(Input
: String): Boolean;
17 function IsHexaChar(Input
: Char): Boolean;
18 function FloatType(Input
: PChar
; Size
: Integer): Integer;
19 function IsPrefixOf(Prefix
, OfWhat
: String): Boolean;
20 function MaxOf(First
, Second
: Integer): Integer;
21 function MergeStringTStrings(First
: String; Second
: TStrings
): TStrings
;
22 function MergeTStringsString(First
: TStrings
; Second
: String): TStrings
;
23 function MinOf(First
, Second
: Integer): Integer;
24 function MirrorString(Input
: String): String;
25 function NeutralizeDoubles(Input
: String; Character
: Char): String;
26 function OmmitAfter(Input
: String; Character
, What
: Char): String;
27 function OmmitBefore(Input
: String; Character
, What
: Char): String;
28 function OmmitEverywhere(Input
: String; Character
, What
: Char): String;
29 function ParseAfterFirst(Input
: String; Parser
: Char): String;
30 function ParseAfterLast(Input
: String; Parser
: Char): String;
31 function ParseBeforeFirst(Input
: String; Parser
: Char): String;
32 function ParseBeforeLast(Input
: String; Parser
: Char): String;
33 function ParseFirst(var Input
: String; Parser
: Char): String;
34 function ParseToStrings(Input
: PChar
; Parser
: Char): TStrings
;
35 function RemoveCharacter(Input
: String): String;
36 function RemoveExactString(From
: TStrings
; What
: String): TStrings
;
37 function RemovePrefix(Prefix
, From
: String): String;
38 function ReplaceCharacters(Input
: String; Find
, Replace
: Char): String;
39 function SeparateFloat(Input
: PChar
; Size
: Integer): TFloatRecord
;
40 function StringToAddress(Input
: String; Offset
: Integer = 0): Integer;
41 function StringBefore(Input
: String; Before
: Integer): String;
42 function StringCompare(First
, Second
: PChar
; Size
: Integer): Boolean;
43 function TrimCharacter(Input
: String; Character
: Char): String;
44 function TrimCharacterLeft(Input
: String; Character
: Char): String;
45 function TrimCharacterRight(Input
: String; Character
: Char): String;
46 function UpperCase(Input
: String): String;
47 function ZeroPaddedInteger(Input
: Integer; Padding
: Integer = 0): String;
48 procedure CustomHexToData(Input
: String; Data
: PChar
; Size
: Integer);
49 procedure CustomStrToFloat(Input
: String; Result
: PChar
; Size
: Integer);
53 function AddressToString(Address
: Pointer): String;
55 SetLength(Result
, SizeOf(Pointer));
56 PInteger(Result
)^ := Integer(Address
);
59 function CartesianOfStrings(First
: String; Second
: TStrings
): TStrings
;
64 for i
:= 0 to (Length(Second
) - 1) do
66 SetLength(Result
, Length(Result
) + 1);
67 Result
[Length(Result
) - 1] := First
+ Second
[i
];
71 function CodeToHexadecimal(Input
: String): String;
77 if (Input
= '') then Exit
;
78 for i
:= 1 to Length(Input
) do
80 lbyte
:= Ord(Input
[i
]);
81 Result
:= Result
+ CHARS_HEXA
[lbyte
shr 4] + CHARS_HEXA
[lbyte
and $F];
85 function ContainsCharacter(Input
: String; Character
: Char): Boolean;
90 if (Input
= '') then Exit
;
91 for i
:= 1 to Length(Input
) do
92 if (Input
[i
] = Character
) then
99 function CustomDataToHex(Input
: PChar
; Size
: Integer): String;
105 for i
:= (Size
- 1) downto 0 do
107 lbyte
:= Ord(Input
[i
]);
108 Result
:= Result
+ CHARS_HEXA
[lbyte
shr 4] + CHARS_HEXA
[lbyte
and $F];
112 function CustomFloatToStr(Input
: PChar
; Size
: Integer): String;
114 linput
: TFloatRecord
;
115 lcmp
: TSeparateConstants
;
120 10: lcmp
:= SEP_FP_10
;
124 linput
:= SeparateFloat(Input
, Size
);
127 if (Exponent
= lcmp
.ExponCmp
) then
128 if (Significand
= lcmp
.SigniCmp
) then
130 if Sign
then Result
:= DESC_NEG_INF
131 else Result
:= DESC_POS_INF
;
135 if (Significand
and lcmp
.SigniAnd
= 0) then
138 Result
:= DESC_NAN_Q
;
139 Result
:= Result
+ DESC_NAN
;
143 4: Result
:= FloatToStr(PSingle(Input
)^);
144 8: Result
:= FloatToStr(PDouble(Input
)^);
145 10: Result
:= FloatToStr(PExtended(Input
)^);
150 function EqualBeforeFirstParser(First
, Second
: String; Parser
: Char): Boolean;
152 if (ParseBeforeFirst(First
, Parser
) = ParseBeforeFirst(Second
, Parser
)) then
158 function IsAddress(Input
: String): Boolean;
163 Input
:= TrimCharacter(Input
, ' ');
164 if (Input
= '') then Exit
;
165 if not(Input
[1] in ['0'..'9', '+', '-']) then Exit
;
166 if (Input
[1] in ['+', '-']) and (Length(Input
) = 1) then Exit
;
167 for i
:= 2 to Length(Input
) do
168 if not(Input
[i
] in ['0'..'9']) then Exit
;
172 function IsHexaChar(Input
: Char): Boolean;
177 for i
:= 0 to (Length(CHARS_HEXA
) - 1) do
178 if (Input
= CHARS_HEXA
[i
]) then
185 function FloatType(Input
: PChar
; Size
: Integer): Integer;
190 lresult
:= CustomFloatToStr(Input
, Size
);
191 if (lresult
= '0') then Result
:= 0
192 else if (lresult
= DESC_NEG_INF
) or (lresult
= DESC_POS_INF
)
193 or (lresult
= DESC_QNAN
) or (lresult
= DESC_SNAN
) then Result
:= -1;
196 function IsPrefixOf(Prefix
, OfWhat
: String): Boolean;
201 if (Length(Prefix
) > Length(OfWhat
)) then Exit
;
202 for i
:= 1 to Length(Prefix
) do
203 if not(Prefix
[i
] = OfWhat
[i
]) then Exit
;
207 function MaxOf(First
, Second
: Integer): Integer;
209 if (First
> Second
) then Result
:= First
210 else Result
:= Second
;
213 function MergeStringTStrings(First
: String; Second
: TStrings
): TStrings
;
217 SetLength(Result
, Length(Second
) + 1);
219 for i
:= 0 to (Length(Second
) - 1) do
220 Result
[i
+ 1] := Second
[i
];
223 function MergeTStringsString(First
: TStrings
; Second
: String): TStrings
;
227 SetLength(Result
, Length(First
) + 1);
228 Result
[Length(First
)] := Second
;
229 for i
:= 0 to (Length(First
) - 1) do
230 Result
[i
] := First
[i
];
233 function MinOf(First
, Second
: Integer): Integer;
235 if (First
< Second
) then Result
:= First
236 else Result
:= Second
;
239 function MirrorString(Input
: String): String;
244 if (Input
= '') then Exit
;
245 for i
:= Length(Input
) downto 1 do
246 Result
:= Result
+ Input
[i
];
249 function NeutralizeDoubles(Input
: String; Character
: Char): String;
251 Result
:= OmmitAfter(Input
, Character
, Character
);
254 function OmmitAfter(Input
: String; Character
, What
: Char): String;
260 if (Input
= '') then Exit
;
261 llast
:= Chr(Ord(Character
) + 1);
262 for i
:= 1 to Length(Input
) do
263 if not((llast
= Character
) and (Input
[i
] = What
)) then
265 Result
:= Result
+ Input
[i
];
270 function OmmitBefore(Input
: String; Character
, What
: Char): String;
276 if (Input
= '') then Exit
;
277 llast
:= Chr(Ord(Character
) + 1);
278 for i
:= Length(Input
) downto 1 do
279 if not((llast
= Character
) and (Input
[i
] = What
)) then
281 Result
:= Result
+ Input
[i
];
284 Result
:= MirrorString(Result
);
287 function OmmitEverywhere(Input
: String; Character
, What
: Char): String;
289 Result
:= OmmitBefore(OmmitAfter(Input
, Character
, What
), Character
, What
);
292 function ParseAfterFirst(Input
: String; Parser
: Char): String;
297 if (Input
= '') then Exit
;
298 for i
:= 1 to Length(Input
) do
299 if (Input
[i
] = Parser
) then Break
;
301 for i
:= lpos
to Length(Input
) do
302 Result
:= Result
+ Input
[i
];
305 function ParseAfterLast(Input
: String; Parser
: Char): String;
310 if (Input
= '') then Exit
;
311 for i
:= Length(Input
) downto 1 do
312 if (Input
[i
] = Parser
) then Break
;
314 for i
:= lpos
to Length(Input
) do
315 Result
:= Result
+ Input
[i
];
318 function ParseBeforeFirst(Input
: String; Parser
: Char): String;
323 if (Input
= '') then Exit
;
324 for i
:= 1 to Length(Input
) do
325 if (Input
[i
] = Parser
) then Break
326 else Result
:= Result
+ Input
[i
];
329 function ParseBeforeLast(Input
: String; Parser
: Char): String;
334 if (Input
= '') then Exit
;
335 for i
:= Length(Input
) downto 1 do
336 if (Input
[i
] = Parser
) then Break
;
338 for i
:= 1 to lpos
do
339 Result
:= Result
+ Input
[i
];
342 function ParseFirst(var Input
: String; Parser
: Char): String;
344 Result
:= ParseAfterFirst(Input
, Parser
);
345 Input
:= ParseBeforeFirst(Input
, Parser
);
348 function ParseToStrings(Input
: PChar
; Parser
: Char): TStrings
;
351 llast
, lstring
: PChar
;
353 SetLength(Result
, 0);
354 if (Length(Input
) = 0) then Exit
;
356 lstring
:= GetMemory(Length(Input
) + 1);
357 Move(Input
^, lstring
^, Length(Input
) + 1);
359 while (i
< Length(Input
)) do
361 if (Input
[i
] = Parser
) then
364 SetLength(Result
, Length(Result
) + 1);
365 Result
[Length(Result
) - 1] := String(llast
);
366 llast
:= @lstring
[i
+ 1];
370 SetLength(Result
, Length(Result
) + 1);
371 Result
[Length(Result
) - 1] := String(llast
);
375 function RemoveCharacter(Input
: String): String;
378 if (Input
= '') then Exit
;
380 SetLength(Result
, Length(Input
) - 1);
383 function RemoveExactString(From
: TStrings
; What
: String): TStrings
;
387 SetLength(Result
, 0);
388 for i
:= 0 to (Length(From
) - 1) do
389 if not(From
[i
] = What
) then
391 SetLength(Result
, Length(Result
) + 1);
392 Result
[Length(Result
) - 1] := From
[i
];
396 function RemovePrefix(Prefix
, From
: String): String;
401 if not IsPrefixOf(Prefix
, From
) then Exit
;
402 for i
:= (Length(Prefix
) + 1) to Length(From
) do
403 Result
:= Result
+ From
[i
];
406 function ReplaceCharacters(Input
: String; Find
, Replace
: Char): String;
411 if (Input
= '') then Exit
;
412 for i
:= 1 to Length(Input
) do
413 if (Input
[i
] = Find
) then
414 Result
:= Result
+ Replace
416 Result
:= Result
+ Input
[i
];
419 function SeparateFloat(Input
: PChar
; Size
: Integer): TFloatRecord
;
424 Result
.Significand
:= PInteger(Input
)^ and $7FFFFF;
425 Result
.Exponent
:= (PWord(Integer(Input
) + 2)^ shr 7) and $FF;
426 Result
.Sign
:= not((PByte(Integer(Input
) + 3)^ and $80) = 0);
430 Result
.Significand
:= PInt64(Input
)^ and $FFFFFFFFFFFFF;
431 Result
.Exponent
:= (PWord(Integer(Input
) + 6)^ shr 4) and $7FF;
432 Result
.Sign
:= not((PByte(Integer(Input
) + 7)^ and $80) = 0);
436 Result
.Significand
:= PInt64(Input
)^;
437 Result
.Exponent
:= PWord(Integer(Input
) + 8)^ and $7FFF;
438 Result
.Sign
:= not((PByte(Integer(Input
) + 9)^ and $80) = 0);
443 function StringToAddress(Input
: String; Offset
: Integer = 0): Integer;
445 i
, lstart
, lmul
: Integer;
447 Input
:= TrimCharacter(Input
, ' ');
464 for i
:= lstart
to Length(Input
) do
465 Result
:= (10 * Result
) + Ord(Input
[i
]) - Ord(CHARS_HEXA
[0]);
466 Result
:= (Result
* lmul
) + Offset
;
469 function StringBefore(Input
: String; Before
: Integer): String;
474 for i
:= 1 to Before
do
475 Result
:= Result
+ Input
[i
];
478 function StringCompare(First
, Second
: PChar
; Size
: Integer): Boolean;
483 for i
:= 0 to (Size
- 1) do
484 if not(First
[i
] = Second
[i
]) then Exit
;
488 function TrimCharacter(Input
: String; Character
: Char): String;
490 Result
:= TrimCharacterLeft(TrimCharacterRight(Input
, Character
), Character
);
493 function TrimCharacterLeft(Input
: String; Character
: Char): String;
498 if (Input
= '') then Exit
;
499 for i
:= 1 to Length(Input
) do
500 if not(Input
[i
] = Character
) then Break
;
502 for i
:= lstart
to Length(Input
) do
503 Result
:= Result
+ Input
[i
];
506 function TrimCharacterRight(Input
: String; Character
: Char): String;
511 if (Input
= '') then Exit
;
512 for i
:= Length(Input
) downto 1 do
513 if not(Input
[i
] = Character
) then Break
;
515 for i
:= 1 to lend
do
516 Result
:= Result
+ Input
[i
];
519 function UpperCase(Input
: String): String;
524 if (Input
= '') then Exit
;
525 for i
:= 1 to Length(Input
) do
526 Result
:= Result
+ UpCase(Input
[i
]);
529 function ZeroPaddedInteger(Input
, Padding
: Integer): String;
540 else lminus
:= False;
543 Result
:= Result
+ CHARS_HEXA
[Input
mod 10];
544 Input
:= Input
div 10;
546 for i
:= Length(Result
) to (Padding
- 1) do
547 Result
:= Result
+ CHARS_HEXA
[0];
548 if lminus
then Result
:= Result
+ '-';
549 Result
:= MirrorString(Result
);
552 procedure ConstantToFloat(Input
: String; Result
: PChar
; Size
: Integer);
554 if not(Length(Input
) = Size
) then Exit
;
555 Move(PChar(Input
)[0], Result
^, Size
);
558 procedure CustomHexToData(Input
: String; Data
: PChar
; Size
: Integer);
563 Input
:= MirrorString(UpperCase(TrimCharacter(Input
, ' ')));
564 if not(Length(Input
) = Size
* 2) then Exit
;
565 for i
:= 1 to Length(Input
) do
566 if not IsHexaChar(Input
[i
]) then Exit
;
567 for i
:= 1 to Size
do
570 for j
:= 0 to (Length(CHARS_HEXA
) - 1) do
571 if (CHARS_HEXA
[j
] = Input
[2 * i
]) then
576 lbyte
:= lbyte
shl 4;
577 for j
:= 0 to (Length(CHARS_HEXA
) - 1) do
578 if (CHARS_HEXA
[j
] = Input
[(2 * i
) - 1]) then
583 Data
[i
- 1] := Chr(lbyte
);
587 procedure CustomStrToFloat(Input
: String; Result
: PChar
; Size
: Integer);
589 ltrans
: TTranslateConstants
;
592 4: ltrans
:= TRANS_FP_4
;
593 8: ltrans
:= TRANS_FP_8
;
594 10: ltrans
:= TRANS_FP_10
;
598 Input
:= UpperCase(TrimCharacter(Input
, ' '));
599 if (Input
= '') then Exit
;
600 if (Input
= DESC_NEG_INF
) then
602 ConstantToFloat(ltrans
.NegInf
, Result
, Size
);
605 if (Input
= DESC_POS_INF
) or (Input
= DESC_INF
) then
607 ConstantToFloat(ltrans
.PosInf
, Result
, Size
);
610 if (Input
= DESC_QNAN
) or (Input
= DESC_NAN
) then
612 ConstantToFloat(ltrans
.QNaN
, Result
, Size
);
615 if (Input
= DESC_SNAN
) then
617 ConstantToFloat(ltrans
.SNaN
, Result
, Size
);
622 4: PSingle(Result
)^ := StrToFloat(Input
);
623 8: PDouble(Result
)^ := StrToFloat(Input
);
624 10: PExtended(Result
)^ := StrToFloat(Input
);
629 4: PSingle(Result
)^ := 0;
630 8: PDouble(Result
)^ := 0;
631 10: PExtended(Result
)^ := 0;
637 DecimalSeparator
:= '.';