1 (* Copyright (C) DooM 2D:Forever Developers
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 {$INCLUDE a_modes.inc}
25 // ////////////////////////////////////////////////////////////////////////// //
27 TUtf8DecoderFast
= packed record
29 const Replacement
= $FFFD; // replacement char for invalid unicode
37 codepoint
: LongWord; // decoded codepoint (valid only when decoder is in "complete" state)
40 constructor Create (v
: Boolean{fuck you, fpc});
42 procedure reset (); inline;
44 function complete (): Boolean; inline; // is current character complete? take `codepoint` then
45 function invalid (): Boolean; inline;
46 function completeOrInvalid (): Boolean; inline;
48 // process one byte, return `true` if codepoint is ready
49 function decode (b
: Byte): Boolean; inline; overload
;
50 function decode (c
: AnsiChar): Boolean; inline; overload
;
54 // ////////////////////////////////////////////////////////////////////////// //
55 // does filename have one of ".wad", ".pk3", ".zip" extensions?
56 function hasWadExtension (fn
: AnsiString): Boolean;
58 // does filepath have ".XXX:\" in it?
59 function isWadPath (fn
: AnsiString): Boolean;
61 // adds ".wad" extension if filename doesn't have one of ".wad", ".pk3", ".zip"
62 function addWadExtension (fn
: AnsiString): AnsiString;
64 // convert number to strig with nice commas
65 function Int64ToStrComma (i
: Int64): AnsiString;
67 function UpCase1251 (ch
: Char): Char;
68 function LoCase1251 (ch
: Char): Char;
70 // `true` if strings are equal; ignoring case for cp1251
71 function StrEquCI1251 (const s0
, s1
: AnsiString): Boolean;
73 function utf8Valid (const s
: AnsiString): Boolean;
75 function utf8to1251 (s
: AnsiString): AnsiString;
77 // `pathname` will be modified if path is valid
78 // `lastIsDir` should be `true` if we are searching for directory
79 // nobody cares about shitdoze, so i'll use the same code path for it
80 function findFileCI (var pathname
: AnsiString; lastIsDir
: Boolean=false): Boolean;
83 function openDiskFileRO (pathname
: AnsiString): TStream
;
84 function createDiskFile (pathname
: AnsiString): TStream
;
87 procedure writeInt (st
: TStream
; v
: Byte); overload
;
88 procedure writeInt (st
: TStream
; v
: ShortInt); overload
;
89 procedure writeInt (st
: TStream
; v
: Word); overload
;
90 procedure writeInt (st
: TStream
; v
: SmallInt); overload
;
91 procedure writeInt (st
: TStream
; v
: LongWord); overload
;
92 procedure writeInt (st
: TStream
; v
: LongInt); overload
;
93 procedure writeInt (st
: TStream
; v
: Int64); overload
;
94 procedure writeInt (st
: TStream
; v
: UInt64); overload
;
96 function readByte (st
: TStream
): Byte;
97 function readShortInt (st
: TStream
): ShortInt;
98 function readWord (st
: TStream
): Word;
99 function readSmallInt (st
: TStream
): SmallInt;
100 function readLongWord (st
: TStream
): LongWord;
101 function readLongInt (st
: TStream
): LongInt;
102 function readInt64 (st
: TStream
): Int64;
103 function readUInt64 (st
: TStream
): UInt64;
106 procedure writeIntBE (st
: TStream
; v
: Byte); overload
;
107 procedure writeIntBE (st
: TStream
; v
: ShortInt); overload
;
108 procedure writeIntBE (st
: TStream
; v
: Word); overload
;
109 procedure writeIntBE (st
: TStream
; v
: SmallInt); overload
;
110 procedure writeIntBE (st
: TStream
; v
: LongWord); overload
;
111 procedure writeIntBE (st
: TStream
; v
: LongInt); overload
;
112 procedure writeIntBE (st
: TStream
; v
: Int64); overload
;
113 procedure writeIntBE (st
: TStream
; v
: UInt64); overload
;
115 function readByteBE (st
: TStream
): Byte;
116 function readShortIntBE (st
: TStream
): ShortInt;
117 function readWordBE (st
: TStream
): Word;
118 function readSmallIntBE (st
: TStream
): SmallInt;
119 function readLongWordBE (st
: TStream
): LongWord;
120 function readLongIntBE (st
: TStream
): LongInt;
121 function readInt64BE (st
: TStream
): Int64;
122 function readUInt64BE (st
: TStream
): UInt64;
126 TFormatStrFCallback
= procedure (constref buf
; len
: SizeUInt
);
128 // returns formatted string if `writerCB` is `nil`, empty string otherwise
129 function formatstrf (const fmt
: AnsiString; args
: array of const; writerCB
: TFormatStrFCallback
=nil): AnsiString;
131 function wchar2win (wc
: WideChar): AnsiChar; inline;
132 function utf2win (const s
: AnsiString): AnsiString;
133 function win2utf (const s
: AnsiString): AnsiString;
134 function digitInBase (ch
: AnsiChar; base
: Integer): Integer;
136 // returns string in single or double quotes
137 // single quotes supports only pascal-style '' for single quote char
138 // double quotes supports c-style escapes
139 // function will select quote mode automatically
140 function quoteStr (const s
: AnsiString): AnsiString;
144 generic TSimpleList
<ItemT
> = class
146 type PItemT
= ^ItemT
;
156 constructor Create (aitems
: PItemT
; acount
: Integer);
157 function MoveNext
: Boolean;
158 function getCurrent (): ItemT
;
159 property Current
: ItemT read getCurrent
;
163 mItems
: array of ItemT
;
164 mCount
: Integer; // can be less than `mItems` size
167 function getAt (idx
: Integer): ItemT
; inline;
168 procedure setAt (idx
: Integer; const it
: ItemT
); inline;
170 function getCapacity (): Integer; inline;
171 procedure setCapacity (v
: Integer); inline;
174 constructor Create (acapacity
: Integer=-1);
175 destructor Destroy (); override;
177 //WARNING! don't change list contents in `for ... in`!
178 function GetEnumerator (): TEnumerator
;
180 procedure reset (); inline; // won't resize `mItems`
181 procedure clear (); inline;
183 procedure append (constref it
: ItemT
); inline;
186 property count
: Integer read mCount
;
187 property capacity
: Integer read getCapacity write setCapacity
;
188 property at
[idx
: Integer]: ItemT read getAt write setAt
; default
;
195 // ////////////////////////////////////////////////////////////////////////// //
196 constructor TSimpleList
.TEnumerator
.Create (aitems
: PItemT
; acount
: Integer);
203 function TSimpleList
.TEnumerator
.MoveNext
: Boolean;
206 result
:= (mCurrent
< mCount
);
209 function TSimpleList
.TEnumerator
.getCurrent (): ItemT
;
211 result
:= mItems
[mCurrent
];
215 // ////////////////////////////////////////////////////////////////////////// //
216 constructor TSimpleList
.Create (acapacity
: Integer=-1);
219 if (acapacity
> 0) then SetLength(mItems
, acapacity
);
224 destructor TSimpleList
.Destroy ();
231 function TSimpleList
.getCapacity (): Integer; inline;
233 result
:= Length(mItems
);
237 procedure TSimpleList
.setCapacity (v
: Integer); inline;
239 if (v
< mCount
) then v
:= mCount
;
240 if (v
<> Length(mItems
)) then SetLength(mItems
, v
);
244 function TSimpleList
.GetEnumerator (): TEnumerator
;
246 if (Length(mItems
) > 0) then result
:= TEnumerator
.Create(@mItems
[0], mCount
)
247 else result
:= TEnumerator
.Create(nil, -1);
251 procedure TSimpleList
.reset (); inline;
257 procedure TSimpleList
.clear (); inline;
264 function TSimpleList
.getAt (idx
: Integer): ItemT
; inline;
266 if (idx
>= 0) and (idx
< mCount
) then result
:= mItems
[idx
] else result
:= Default(ItemT
);
270 procedure TSimpleList
.setAt (idx
: Integer; const it
: ItemT
); inline;
272 if (idx
>= 0) and (idx
< mCount
) then mItems
[idx
] := it
;
276 procedure TSimpleList
.append (constref it
: ItemT
); inline;
278 if (mCount
= Length(mItems
)) then
280 if (mCount
= 0) then SetLength(mItems
, 128) else SetLength(mItems
, mCount
*2);
282 mItems
[mCount
] := it
;
287 // ////////////////////////////////////////////////////////////////////////// //
289 wc2shitmap
: array[0..65535] of AnsiChar;
290 wc2shitmapInited
: Boolean = false;
293 // ////////////////////////////////////////////////////////////////////////// //
295 cp1251
: array[0..127] of Word = (
296 $0402,$0403,$201A,$0453,$201E,$2026,$2020,$2021,$20AC,$2030,$0409,$2039,$040A,$040C,$040B,$040F,
297 $0452,$2018,$2019,$201C,$201D,$2022,$2013,$2014,$003F,$2122,$0459,$203A,$045A,$045C,$045B,$045F,
298 $00A0,$040E,$045E,$0408,$00A4,$0490,$00A6,$00A7,$0401,$00A9,$0404,$00AB,$00AC,$00AD,$00AE,$0407,
299 $00B0,$00B1,$0406,$0456,$0491,$00B5,$00B6,$00B7,$0451,$2116,$0454,$00BB,$0458,$0405,$0455,$0457,
300 $0410,$0411,$0412,$0413,$0414,$0415,$0416,$0417,$0418,$0419,$041A,$041B,$041C,$041D,$041E,$041F,
301 $0420,$0421,$0422,$0423,$0424,$0425,$0426,$0427,$0428,$0429,$042A,$042B,$042C,$042D,$042E,$042F,
302 $0430,$0431,$0432,$0433,$0434,$0435,$0436,$0437,$0438,$0439,$043A,$043B,$043C,$043D,$043E,$043F,
303 $0440,$0441,$0442,$0443,$0444,$0445,$0446,$0447,$0448,$0449,$044A,$044B,$044C,$044D,$044E,$044F
307 procedure initShitMap ();
311 for f
:= 0 to High(wc2shitmap
) do wc2shitmap
[f
] := '?';
312 for f
:= 0 to 127 do wc2shitmap
[f
] := AnsiChar(f
);
313 for f
:= 0 to 127 do wc2shitmap
[cp1251
[f
]] := AnsiChar(f
+128);
314 wc2shitmapInited
:= true;
318 // ////////////////////////////////////////////////////////////////////////// //
319 // fast state-machine based UTF-8 decoder; using 8 bytes of memory
320 // code points from invalid range will never be valid, this is the property of the state machine
322 // see http://bjoern.hoehrmann.de/utf-8/decoder/dfa/
323 utf8dfa
: array[0..$16c-1] of Byte = (
324 // maps bytes to character classes
325 $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00, // 00-0f
326 $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00, // 10-1f
327 $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00, // 20-2f
328 $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00, // 30-3f
329 $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00, // 40-4f
330 $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00, // 50-5f
331 $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00, // 60-6f
332 $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00, // 70-7f
333 $01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01, // 80-8f
334 $09,$09,$09,$09,$09,$09,$09,$09,$09,$09,$09,$09,$09,$09,$09,$09, // 90-9f
335 $07,$07,$07,$07,$07,$07,$07,$07,$07,$07,$07,$07,$07,$07,$07,$07, // a0-af
336 $07,$07,$07,$07,$07,$07,$07,$07,$07,$07,$07,$07,$07,$07,$07,$07, // b0-bf
337 $08,$08,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02, // c0-cf
338 $02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02, // d0-df
339 $0a,$03,$03,$03,$03,$03,$03,$03,$03,$03,$03,$03,$03,$04,$03,$03, // e0-ef
340 $0b,$06,$06,$06,$05,$08,$08,$08,$08,$08,$08,$08,$08,$08,$08,$08, // f0-ff
341 // maps a combination of a state of the automaton and a character class to a state
342 $00,$0c,$18,$24,$3c,$60,$54,$0c,$0c,$0c,$30,$48,$0c,$0c,$0c,$0c, // 100-10f
343 $0c,$0c,$0c,$0c,$0c,$0c,$0c,$0c,$0c,$00,$0c,$0c,$0c,$0c,$0c,$00, // 110-11f
344 $0c,$00,$0c,$0c,$0c,$18,$0c,$0c,$0c,$0c,$0c,$18,$0c,$18,$0c,$0c, // 120-12f
345 $0c,$0c,$0c,$0c,$0c,$0c,$0c,$18,$0c,$0c,$0c,$0c,$0c,$18,$0c,$0c, // 130-13f
346 $0c,$0c,$0c,$0c,$0c,$18,$0c,$0c,$0c,$0c,$0c,$0c,$0c,$0c,$0c,$24, // 140-14f
347 $0c,$24,$0c,$0c,$0c,$24,$0c,$0c,$0c,$0c,$0c,$24,$0c,$24,$0c,$0c, // 150-15f
348 $0c,$24,$0c,$0c,$0c,$0c,$0c,$0c,$0c,$0c,$0c,$0c);
351 // ////////////////////////////////////////////////////////////////////////// //
352 constructor TUtf8DecoderFast
.Create (v
: Boolean{fuck you, fpc}); begin state
:= Accept
; codepoint
:= 0; end;
354 procedure TUtf8DecoderFast
.reset (); inline; begin state
:= Accept
; codepoint
:= 0; end;
356 function TUtf8DecoderFast
.complete (): Boolean; inline; begin result
:= (state
= Accept
); end;
357 function TUtf8DecoderFast
.invalid (): Boolean; inline; begin result
:= (state
= Reject
); end;
358 function TUtf8DecoderFast
.completeOrInvalid (): Boolean; inline; begin result
:= (state
= Accept
) or (state
= Reject
); end;
360 function TUtf8DecoderFast
.decode (c
: AnsiChar): Boolean; inline; overload
; begin result
:= decode(Byte(c
)); end;
362 function TUtf8DecoderFast
.decode (b
: Byte): Boolean; inline; overload
;
366 if (state
= Reject
) then begin state
:= Accept
; codepoint
:= 0; end;
368 if (state
<> Accept
) then codepoint
:= (b
and $3f) or (codepoint
shl 6) else codepoint
:= ($ff shr tp
) and b
;
369 state
:= utf8dfa
[256+state
+tp
];
370 if (state
= Reject
) then begin codepoint
:= Replacement
; state
:= Accept
; end;
371 result
:= (state
= Accept
);
375 // ////////////////////////////////////////////////////////////////////////// //
376 function wchar2win (wc
: WideChar): AnsiChar; inline;
378 if not wc2shitmapInited
then initShitMap();
379 if (LongWord(wc
) > 65535) then result
:= '?' else result
:= wc2shitmap
[LongWord(wc
)];
383 // ////////////////////////////////////////////////////////////////////////// //
384 function utf2win (const s
: AnsiString): AnsiString;
387 ud
: TUtf8DecoderFast
;
389 for f
:= 1 to Length(s
) do
391 if (Byte(s
[f
]) > 127) then
393 ud
:= TUtf8DecoderFast
.Create(true);
395 for c
:= 1 to Length(s
) do
397 if ud
.decode(s
[c
]) then result
+= wchar2win(WideChar(ud
.codepoint
));
406 function win2utf (const s
: AnsiString): AnsiString;
410 function utf8Encode (code
: Integer): AnsiString;
412 if (code
< 0) or (code
> $10FFFF) then begin result
:= '?'; exit
; end;
413 if (code
<= $7f) then
415 result
:= Char(code
and $ff);
417 else if (code
<= $7FF) then
419 result
:= Char($C0 or (code
shr 6));
420 result
+= Char($80 or (code
and $3F));
422 else if (code
<= $FFFF) then
424 result
:= Char($E0 or (code
shr 12));
425 result
+= Char($80 or ((code
shr 6) and $3F));
426 result
+= Char($80 or (code
and $3F));
428 else if (code
<= $10FFFF) then
430 result
:= Char($F0 or (code
shr 18));
431 result
+= Char($80 or ((code
shr 12) and $3F));
432 result
+= Char($80 or ((code
shr 6) and $3F));
433 result
+= Char($80 or (code
and $3F));
442 for f
:= 1 to Length(s
) do
444 if (Byte(s
[f
]) > 127) then
447 for c
:= 1 to Length(s
) do
449 if (Byte(s
[c
]) < 128) then
455 result
+= utf8Encode(cp1251
[Byte(s
[c
])-128])
465 // ////////////////////////////////////////////////////////////////////////// //
466 function digitInBase (ch
: AnsiChar; base
: Integer): Integer;
469 if (base
< 1) or (base
> 36) then exit
;
470 if (ch
< '0') then exit
;
473 if (Integer(ch
) >= 48+base
) then exit
;
474 result
:= Integer(ch
)-48;
478 if (ch
>= '0') and (ch
<= '9') then begin result
:= Integer(ch
)-48; exit
; end;
479 if (ch
>= 'a') and (ch
<= 'z') then Dec(ch
, 32); // poor man's tolower()
480 if (ch
< 'A') or (Integer(ch
) >= 65+(base
-10)) then exit
;
481 result
:= Integer(ch
)-65+10;
486 // ////////////////////////////////////////////////////////////////////////// //
487 function quoteStr (const s
: AnsiString): AnsiString;
489 function squote (const s
: AnsiString): AnsiString;
494 for f
:= 1 to Length(s
) do
496 if (s
[f
] = '''') then result
+= '''';
502 function dquote (const s
: AnsiString): AnsiString;
508 for f
:= 1 to Length(s
) do
511 if (ch
= #0) then result
+= '\z'
512 else if (ch
= #9) then result
+= '\t'
513 else if (ch
= #10) then result
+= '\n'
514 else if (ch
= #13) then result
+= '\r'
515 else if (ch
= #27) then result
+= '\e'
516 else if (ch
< ' ') or (ch
= #127) then
519 result
+= LowerCase(IntToHex(Integer(ch
), 2));
521 else if (ch
= '"') or (ch
= '\') then
535 needSingle
: Boolean = false;
538 for f
:= 1 to Length(s
) do
540 if (s
[f
] = '''') then begin needSingle
:= true; continue
; end;
541 if (s
[f
] < ' ') or (s
[f
] = #127) then begin result
:= dquote(s
); exit
; end;
543 if needSingle
then result
:= squote(s
) else result
:= ''''+s
+'''';
547 // ////////////////////////////////////////////////////////////////////////// //
548 function hasWadExtension (fn
: AnsiString): Boolean;
550 fn
:= ExtractFileExt(fn
);
551 result
:= StrEquCI1251(fn
, '.wad') or StrEquCI1251(fn
, '.pk3') or StrEquCI1251(fn
, '.zip');
555 function addWadExtension (fn
: AnsiString): AnsiString;
558 if not hasWadExtension(result
) then result
:= result
+'.wad';
562 function isWadPath (fn
: AnsiString): Boolean;
571 if (p
= 0) or (length(fn
)-p
< 1) then break
;
572 if (p
-4 > 1) and (fn
[p
-4] = '.') and ((fn
[p
+1] = '\') or (fn
[p
+1] = '/')) then
574 s
:= Copy(fn
, p
-4, 4);
575 if StrEquCI1251(s
, '.wad') or StrEquCI1251(s
, '.pk3') or StrEquCI1251(s
, '.zip') then
586 function Int64ToStrComma (i
: Int64): AnsiString;
591 f
:= Length(result
)+1;
594 Dec(f
, 3); Insert(',', result
, f
);
599 function UpCase1251 (ch
: Char): Char;
603 if (ch
>= 'a') and (ch
<= 'z') then Dec(ch
, 32);
607 if (ch
>= #224) and (ch
<= #255) then
614 #184, #186, #191: Dec(ch
, 16);
623 function LoCase1251 (ch
: Char): Char;
627 if (ch
>= 'A') and (ch
<= 'Z') then Inc(ch
, 32);
631 if (ch
>= #192) and (ch
<= #223) then
638 #168, #170, #175: Inc(ch
, 16);
647 function StrEquCI1251 (const s0
, s1
: AnsiString): Boolean;
652 if length(s0
) <> length(s1
) then exit
;
653 for i
:= 1 to length(s0
) do if UpCase1251(s0
[i
]) <> UpCase1251(s1
[i
]) then exit
;
658 // ////////////////////////////////////////////////////////////////////////// //
662 function utf8CodeLen (ch
: Word): Integer;
664 if ch
< $80 then begin result
:= 1; exit
; end;
665 if (ch
and $FE) = $FC then begin result
:= 6; exit
; end;
666 if (ch
and $FC) = $F8 then begin result
:= 5; exit
; end;
667 if (ch
and $F8) = $F0 then begin result
:= 4; exit
; end;
668 if (ch
and $F0) = $E0 then begin result
:= 3; exit
; end;
669 if (ch
and $E0) = $C0 then begin result
:= 2; exit
; end;
670 result
:= -1; // invalid
674 function utf8Valid (const s
: AnsiString): Boolean;
680 while pos
<= length(s
) do
682 len
:= utf8CodeLen(Byte(s
[pos
]));
683 if len
< 1 then exit
; // invalid sequence start
684 if pos
+len
-1 > length(s
) then exit
; // out of chars in string
687 // check other sequence bytes
690 if (Byte(s
[pos
]) and $C0) <> $80 then exit
;
699 // ////////////////////////////////////////////////////////////////////////// //
701 uni2wint
: array [128..255] of Word = (
702 $0402,$0403,$201A,$0453,$201E,$2026,$2020,$2021,$20AC,$2030,$0409,$2039,$040A,$040C,$040B,$040F,
703 $0452,$2018,$2019,$201C,$201D,$2022,$2013,$2014,$003F,$2122,$0459,$203A,$045A,$045C,$045B,$045F,
704 $00A0,$040E,$045E,$0408,$00A4,$0490,$00A6,$00A7,$0401,$00A9,$0404,$00AB,$00AC,$00AD,$00AE,$0407,
705 $00B0,$00B1,$0406,$0456,$0491,$00B5,$00B6,$00B7,$0451,$2116,$0454,$00BB,$0458,$0405,$0455,$0457,
706 $0410,$0411,$0412,$0413,$0414,$0415,$0416,$0417,$0418,$0419,$041A,$041B,$041C,$041D,$041E,$041F,
707 $0420,$0421,$0422,$0423,$0424,$0425,$0426,$0427,$0428,$0429,$042A,$042B,$042C,$042D,$042E,$042F,
708 $0430,$0431,$0432,$0433,$0434,$0435,$0436,$0437,$0438,$0439,$043A,$043B,$043C,$043D,$043E,$043F,
709 $0440,$0441,$0442,$0443,$0444,$0445,$0446,$0447,$0448,$0449,$044A,$044B,$044C,$044D,$044E,$044F
713 function decodeUtf8Char (s
: AnsiString; var pos
: Integer): char;
717 (* The following encodings are valid, except for the 5 and 6 byte
721 * 1110xxxx 10xxxxxx 10xxxxxx
722 * 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
723 * 111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
724 * 1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
727 if pos
> length(s
) then exit
;
731 if b
< $80 then begin result
:= char(b
); exit
; end;
733 // mask out unused bits
734 if (b
and $FE) = $FC then b
:= b
and $01
735 else if (b
and $FC) = $F8 then b
:= b
and $03
736 else if (b
and $F8) = $F0 then b
:= b
and $07
737 else if (b
and $F0) = $E0 then b
:= b
and $0F
738 else if (b
and $E0) = $C0 then b
:= b
and $1F
739 else exit
; // invalid utf8
742 while pos
<= length(s
) do
745 if (c
and $C0) <> $80 then break
; // no more
747 b
:= b
or (c
and $3F);
752 for c
:= 128 to 255 do if uni2wint
[c
] = b
then begin result
:= char(c
and $FF); exit
; end;
757 function utf8to1251 (s
: AnsiString): AnsiString;
761 if not utf8Valid(s
) then begin result
:= s
; exit
; end;
763 while pos
<= length(s
) do
765 if Byte(s
[pos
]) >= $80 then break
;
768 if pos
> length(s
) then begin result
:= s
; exit
; end; // nothing to do here
771 while pos
<= length(s
) do result
:= result
+decodeUtf8Char(s
, pos
);
775 // ////////////////////////////////////////////////////////////////////////// //
776 // `pathname` will be modified if path is valid
777 // `lastIsDir` should be `true` if we are searching for directory
778 // nobody cares about shitdoze, so i'll use the same code path for it
779 function findFileCI (var pathname
: AnsiString; lastIsDir
: Boolean=false): Boolean;
783 newname
: AnsiString = '';
790 result
:= (length(npt
) > 0);
791 if (length(npt
) > 0) and ((npt
[1] = '/') or (npt
[1] = '\')) then newname
:= '/';
792 while length(npt
) > 0 do
794 // remove trailing slashes
795 while (length(npt
) > 0) and ((npt
[1] = '/') or (npt
[1] = '\')) do Delete(npt
, 1, 1);
796 if length(npt
) = 0 then break
;
799 while (length(npt
) > 0) and (npt
[1] <> '/') and (npt
[1] <> '\') do
801 curname
:= curname
+npt
[1];
804 // remove trailing slashes again
805 while (length(npt
) > 0) and ((npt
[1] = '/') or (npt
[1] = '\')) do Delete(npt
, 1, 1);
806 wantdir
:= lastIsDir
or (length(npt
) > 0); // do we want directory here?
807 //writeln(Format('npt=[%s]; newname=[%s]; curname=[%s]; wantdir=%d', [npt, newname, curname, Integer(wantdir)]));
808 // try the easiest case first
809 attr
:= FileGetAttr(newname
+curname
);
812 if wantdir
= ((attr
and faDirectory
) <> 0) then
815 newname
:= newname
+curname
;
816 if wantdir
then newname
:= newname
+'/';
820 //writeln(Format('npt=[%s]; newname=[%s]; curname=[%s]; wantdir=%d', [npt, newname, curname, Integer(wantdir)]));
821 // alas, either not found, or invalid attributes
824 if FindFirst(newname
+'*', faAnyFile
, sr
) = 0 then
826 if (wantdir
= ((sr
.attr
and faDirectory
) <> 0)) and StrEquCI1251(sr
.name
, curname
) then
829 newname
:= newname
+sr
.name
;
830 if wantdir
then newname
:= newname
+'/';
834 until FindNext(sr
) <> 0;
838 if not foundher
then begin newname
:= ''; result
:= false; break
; end;
840 if result
then pathname
:= newname
;
844 function openDiskFileRO (pathname
: AnsiString): TStream
;
846 if not findFileCI(pathname
) then raise Exception
.Create('can''t open file "'+pathname
+'"');
847 result
:= TFileStream
.Create(pathname
, fmOpenRead
or {fmShareDenyWrite}fmShareDenyNone
);
850 function createDiskFile (pathname
: AnsiString): TStream
;
854 path
:= ExtractFilePath(pathname
);
855 if length(path
) > 0 then
857 if not findFileCI(path
, true) then raise Exception
.Create('can''t create file "'+pathname
+'"');
859 result
:= TFileStream
.Create(path
+ExtractFileName(pathname
), fmCreate
);
863 procedure writeIntegerLE (st
: TStream
; vp
: Pointer; size
: Integer);
864 {$IFDEF ENDIAN_LITTLE}
866 st
.writeBuffer(vp
^, size
);
872 p
:= PByte(vp
)+size
-1;
875 st
.writeBuffer(p
^, 1);
882 procedure writeIntegerBE (st
: TStream
; vp
: Pointer; size
: Integer);
883 {$IFDEF ENDIAN_LITTLE}
887 p
:= PByte(vp
)+size
-1;
890 st
.writeBuffer(p
^, 1);
897 st
.writeBuffer(vp
^, size
);
901 procedure writeInt (st
: TStream
; v
: Byte); overload
; begin writeIntegerLE(st
, @v
, 1); end;
902 procedure writeInt (st
: TStream
; v
: ShortInt); overload
; begin writeIntegerLE(st
, @v
, 1); end;
903 procedure writeInt (st
: TStream
; v
: Word); overload
; begin writeIntegerLE(st
, @v
, 2); end;
904 procedure writeInt (st
: TStream
; v
: SmallInt); overload
; begin writeIntegerLE(st
, @v
, 2); end;
905 procedure writeInt (st
: TStream
; v
: LongWord); overload
; begin writeIntegerLE(st
, @v
, 4); end;
906 procedure writeInt (st
: TStream
; v
: LongInt); overload
; begin writeIntegerLE(st
, @v
, 4); end;
907 procedure writeInt (st
: TStream
; v
: Int64); overload
; begin writeIntegerLE(st
, @v
, 8); end;
908 procedure writeInt (st
: TStream
; v
: UInt64); overload
; begin writeIntegerLE(st
, @v
, 8); end;
910 procedure writeIntBE (st
: TStream
; v
: Byte); overload
; begin writeIntegerBE(st
, @v
, 1); end;
911 procedure writeIntBE (st
: TStream
; v
: ShortInt); overload
; begin writeIntegerBE(st
, @v
, 1); end;
912 procedure writeIntBE (st
: TStream
; v
: Word); overload
; begin writeIntegerBE(st
, @v
, 2); end;
913 procedure writeIntBE (st
: TStream
; v
: SmallInt); overload
; begin writeIntegerBE(st
, @v
, 2); end;
914 procedure writeIntBE (st
: TStream
; v
: LongWord); overload
; begin writeIntegerBE(st
, @v
, 4); end;
915 procedure writeIntBE (st
: TStream
; v
: LongInt); overload
; begin writeIntegerBE(st
, @v
, 4); end;
916 procedure writeIntBE (st
: TStream
; v
: Int64); overload
; begin writeIntegerBE(st
, @v
, 8); end;
917 procedure writeIntBE (st
: TStream
; v
: UInt64); overload
; begin writeIntegerBE(st
, @v
, 8); end;
920 procedure readIntegerLE (st
: TStream
; vp
: Pointer; size
: Integer);
921 {$IFDEF ENDIAN_LITTLE}
923 st
.readBuffer(vp
^, size
);
929 p
:= PByte(vp
)+size
-1;
932 st
.readBuffer(p
^, 1);
939 procedure readIntegerBE (st
: TStream
; vp
: Pointer; size
: Integer);
940 {$IFDEF ENDIAN_LITTLE}
944 p
:= PByte(vp
)+size
-1;
947 st
.readBuffer(p
^, 1);
954 st
.readBuffer(vp
^, size
);
958 function readByte (st
: TStream
): Byte; begin readIntegerLE(st
, @result
, 1); end;
959 function readShortInt (st
: TStream
): ShortInt; begin readIntegerLE(st
, @result
, 1); end;
960 function readWord (st
: TStream
): Word; begin readIntegerLE(st
, @result
, 2); end;
961 function readSmallInt (st
: TStream
): SmallInt; begin readIntegerLE(st
, @result
, 2); end;
962 function readLongWord (st
: TStream
): LongWord; begin readIntegerLE(st
, @result
, 4); end;
963 function readLongInt (st
: TStream
): LongInt; begin readIntegerLE(st
, @result
, 4); end;
964 function readInt64 (st
: TStream
): Int64; begin readIntegerLE(st
, @result
, 8); end;
965 function readUInt64 (st
: TStream
): UInt64; begin readIntegerLE(st
, @result
, 8); end;
967 function readByteBE (st
: TStream
): Byte; begin readIntegerBE(st
, @result
, 1); end;
968 function readShortIntBE (st
: TStream
): ShortInt; begin readIntegerBE(st
, @result
, 1); end;
969 function readWordBE (st
: TStream
): Word; begin readIntegerBE(st
, @result
, 2); end;
970 function readSmallIntBE (st
: TStream
): SmallInt; begin readIntegerBE(st
, @result
, 2); end;
971 function readLongWordBE (st
: TStream
): LongWord; begin readIntegerBE(st
, @result
, 4); end;
972 function readLongIntBE (st
: TStream
): LongInt; begin readIntegerBE(st
, @result
, 4); end;
973 function readInt64BE (st
: TStream
): Int64; begin readIntegerBE(st
, @result
, 8); end;
974 function readUInt64BE (st
: TStream
): UInt64; begin readIntegerBE(st
, @result
, 8); end;
977 // ////////////////////////////////////////////////////////////////////////// //
979 function snprintf (buf
: PAnsiChar; bufsize
: SizeUInt
; const fmt
: PAnsiChar): SizeUInt
; cdecl; varargs
; external 'msvcrt.dll' name
'_snprintf';
981 function snprintf (buf
: PAnsiChar; bufsize
: SizeUInt
; const fmt
: PAnsiChar): SizeUInt
; cdecl; varargs
; external 'libc' name
'snprintf';
986 procedure conwriter (constref buf; len: SizeUInt);
992 if (len < 1) then exit;
996 if (len > 255) then slen := 255 else slen := Integer(len);
997 Move(b^, ss[1], len);
998 ss[0] := AnsiChar(slen);
1007 function formatstrf (const fmt
: AnsiString; args
: array of const; writerCB
: TFormatStrFCallback
=nil): AnsiString;
1009 PadSpaces
: AnsiString = ' ';
1010 PadZeroes
: AnsiString = '00000000000000000000000000000000000000000000000000000000000000000000000';
1012 curarg
: Integer = 0; // current arg in `args`
1013 sign
, fmtch
: AnsiChar;
1015 width
, prec
: Integer; // width and precision
1016 spos
, epos
: Integer;
1018 strbuf
: array[0..256] of AnsiChar;
1020 fmtbuf
: array[0..256] of AnsiChar;
1025 procedure writer (constref buf
; len
: SizeUInt
);
1031 if (len
< 1) then exit
;
1033 if assigned(writerCB
) then
1041 if (len
> 255) then slen
:= 255 else slen
:= Integer(len
);
1042 Move(b
^, ss
[1], slen
);
1043 ss
[0] := AnsiChar(slen
);
1051 procedure xwrite (const s
: AnsiString);
1053 if (Length(s
) > 0) then writer(PAnsiChar(s
)^, Length(s
));
1056 procedure putFmtChar (ch
: AnsiChar);
1058 fmtbuf
[fmtblen
] := ch
;
1062 procedure putFmtInt (n
: Integer);
1066 len
:= snprintf(@fmtbuf
[fmtblen
], Length(fmtbuf
)-fmtblen
, '%d', n
);
1067 if (len
> 0) then Inc(fmtblen
, len
);
1070 procedure buildCFormat (const pfx
: AnsiString='');
1075 for f
:= 1 to Length(pfx
) do putFmtChar(pfx
[f
]);
1077 if (sign
<> ' ') then putFmtChar(sign
);
1078 if (width
>= 0) then
1080 if (zeropad
) then putFmtChar('0');
1089 fmtbuf
[fmtblen
] := #0;
1092 procedure writeStrBuf ();
1094 if (strblen
> 0) then writer(strbuf
, strblen
);
1097 function i642str (n
: Int64; hex
: Boolean; hexup
: Boolean): PAnsiChar;
1102 if (n
= $8000000000000000) then
1104 if hex
then snprintf(@strbuf
[0], Length(strbuf
), '-8000000000000000')
1105 else snprintf(@strbuf
[0], Length(strbuf
), '-9223372036854775808');
1106 result
:= @strbuf
[0];
1111 if neg
then n
:= -n
;
1112 xpos
:= High(strbuf
);
1113 strbuf
[xpos
] := #0; Dec(xpos
);
1117 strbuf
[xpos
] := AnsiChar((n
mod 10)+48);
1123 if (n
mod 16 > 9) then
1125 strbuf
[xpos
] := AnsiChar((n
mod 16)+48+7);
1126 if not hexup
then Inc(strbuf
[xpos
], 32);
1128 else strbuf
[xpos
] := AnsiChar((n
mod 16)+48);
1133 if neg
then begin strbuf
[xpos
] := '-'; Dec(xpos
); end;
1134 result
:= @strbuf
[xpos
+1];
1138 function ui642str (n
: UInt64; hex
: Boolean; hexup
: Boolean): PAnsiChar;
1142 xpos
:= High(strbuf
);
1143 strbuf
[xpos
] := #0; Dec(xpos
);
1147 strbuf
[xpos
] := AnsiChar((n
mod 10)+48);
1153 if (n
mod 16 > 9) then
1155 strbuf
[xpos
] := AnsiChar((n
mod 16)+48+7);
1156 if not hexup
then Inc(strbuf
[xpos
], 32);
1158 else strbuf
[xpos
] := AnsiChar((n
mod 16)+48);
1163 result
:= @strbuf
[xpos
+1];
1166 procedure indent (len
: Integer);
1172 if (len
> Length(PadSpaces
)) then ilen
:= Length(PadSpaces
) else ilen
:= len
;
1173 writer(PAnsiChar(PadSpaces
)^, ilen
);
1178 procedure indent0 (len
: Integer);
1184 if (len
> Length(PadZeroes
)) then ilen
:= Length(PadZeroes
) else ilen
:= len
;
1185 writer(PAnsiChar(PadZeroes
)^, ilen
);
1193 while (spos
<= Length(fmt
)) do
1195 // print literal part
1197 while (epos
<= Length(fmt
)) and (fmt
[epos
] <> '%') do Inc(epos
);
1198 // output literal part
1199 if (epos
> spos
) then
1201 if (epos
> Length(fmt
)) then
1203 writer((PAnsiChar(fmt
)+spos
-1)^, epos
-spos
);
1206 if (epos
+1 > Length(fmt
)) then Inc(epos
) // last percent, output literally
1207 else if (fmt
[epos
+1] = '%') then // special case
1210 writer((PAnsiChar(fmt
)+spos
-1)^, epos
-spos
);
1215 writer((PAnsiChar(fmt
)+spos
-1)^, epos
-spos
);
1220 // check if we have argument for this format string
1221 if (curarg
> High(args
)) then
1223 xwrite('<OUT OF ARGS>');
1224 writer((PAnsiChar(fmt
)+spos
-1)^, Length(fmt
)-spos
+1);
1228 if (spos
+1 > Length(fmt
)) then break
; // oops
1229 assert(fmt
[spos
] = '%');
1231 // parse format; check for sign
1232 if (fmt
[spos
] = '-') then begin sign
:= '-'; Inc(spos
); end
1233 else if (fmt
[spos
] = '+') then begin sign
:= '+'; Inc(spos
); end
1236 if (spos
> Length(fmt
)) then begin xwrite('<INVALID FORMAT>'); break
; end;
1237 if (sign
<> ' ') or ((fmt
[spos
] >= '0') and (fmt
[spos
] <= '9')) then
1239 if (fmt
[spos
] < '0') or (fmt
[spos
] > '9') then begin xwrite('<INVALID FORMAT>'); writer((PAnsiChar(fmt
)+spos
-1)^, Length(fmt
)-spos
+1); break
; end;
1240 zeropad
:= (fmt
[spos
] = '0');
1242 while (spos
<= Length(fmt
)) do
1245 if (ch
< '0') or (ch
> '9') then break
;
1246 width
:= width
*10+Integer(ch
)-48;
1257 if (spos
<= Length(fmt
)) and (fmt
[spos
] = '.') then
1260 if (spos
> Length(fmt
)) then begin xwrite('<INVALID FORMAT>'); break
; end;
1261 if (fmt
[spos
] < '0') or (fmt
[spos
] > '9') then begin xwrite('<INVALID FORMAT>'); writer((PAnsiChar(fmt
)+spos
-1)^, Length(fmt
)-spos
+1); break
; end;
1263 while (spos
<= Length(fmt
)) do
1266 if (ch
< '0') or (ch
> '9') then break
;
1267 prec
:= prec
*10+Integer(ch
)-48;
1272 if (spos
> Length(fmt
)) then begin xwrite('<INVALID FORMAT>'); break
; end;
1275 // done parsing format, check for valid format chars
1276 if not (fmtch
in ['s','u','d','x','X','p','f','g','c']) then begin xwrite('<INVALID FORMAT CHAR>'); writer((PAnsiChar(fmt
)+spos
-1)^, Length(fmt
)-spos
+1); break
; end;
1277 // now write formatted string
1278 case args
[curarg
].VType
of
1279 vtInteger
: // args[curarg].VInteger
1281 if not (fmtch
in ['s','u','d','x','X']) then begin xwrite('<INVALID FORMAT CHAR>'); writer((PAnsiChar(fmt
)+spos
-1)^, Length(fmt
)-spos
+1); break
; end;
1282 if (fmtch
= 's') then fmtch
:= 'd';
1284 strblen
:= snprintf(@strbuf
[0], Length(strbuf
), @fmtbuf
[0], args
[curarg
].VInteger
);
1287 vtBoolean
: // args[curarg].VBoolean
1292 if args
[curarg
].VBoolean
then strblen
:= snprintf(@strbuf
[0], Length(strbuf
), @fmtbuf
[0], 'true')
1293 else strblen
:= snprintf(@strbuf
[0], Length(strbuf
), @fmtbuf
[0], 'false');
1299 if args
[curarg
].VBoolean
then strblen
:= snprintf(@strbuf
[0], Length(strbuf
), @fmtbuf
[0], AnsiChar('t'))
1300 else strblen
:= snprintf(@strbuf
[0], Length(strbuf
), @fmtbuf
[0], AnsiChar('f'));
1306 strblen
:= snprintf(@strbuf
[0], Length(strbuf
), @fmtbuf
[0], Integer(args
[curarg
].VBoolean
));
1311 xwrite('<INVALID FORMAT CHAR>');
1312 writer((PAnsiChar(fmt
)+spos
-1)^, Length(fmt
)-spos
+1);
1316 vtChar
: // args[curarg].VChar
1322 strblen
:= snprintf(@strbuf
[0], Length(strbuf
), @fmtbuf
[0], args
[curarg
].VChar
);
1328 strblen
:= snprintf(@strbuf
[0], Length(strbuf
), @fmtbuf
[0], Integer(args
[curarg
].VChar
));
1333 xwrite('<INVALID FORMAT CHAR>');
1334 writer((PAnsiChar(fmt
)+spos
-1)^, Length(fmt
)-spos
+1);
1338 //vtWideChar: begin end; // args[curarg].VWideChar (WideChar)
1339 vtExtended
: // args[curarg].VExtended^
1345 strblen
:= snprintf(@strbuf
[0], Length(strbuf
), @fmtbuf
[0], Double(args
[curarg
].VExtended
^));
1351 strblen
:= snprintf(@strbuf
[0], Length(strbuf
), @fmtbuf
[0], Double(args
[curarg
].VExtended
^));
1357 strblen
:= snprintf(@strbuf
[0], Length(strbuf
), @fmtbuf
[0], Integer(trunc(args
[curarg
].VExtended
^)));
1363 strblen
:= snprintf(@strbuf
[0], Length(strbuf
), @fmtbuf
[0], LongWord(trunc(args
[curarg
].VExtended
^)));
1368 xwrite('<INVALID FORMAT CHAR>');
1369 writer((PAnsiChar(fmt
)+spos
-1)^, Length(fmt
)-spos
+1);
1373 vtString
: // args[curarg].VString^ (PShortString)
1375 if (sign
<> '-') then indent(width
-Length(args
[curarg
].VString
^));
1376 writer(args
[curarg
].VString
^[1], Length(args
[curarg
].VString
^));
1377 if (sign
= '-') then indent(width
-Length(args
[curarg
].VString
^));
1379 vtPointer
: // args[curarg].VPointer
1384 if (width
< 8) then width
:= 8;
1387 strblen
:= snprintf(@strbuf
[0], Length(strbuf
), @fmtbuf
[0], PtrUInt(args
[curarg
].VPointer
));
1390 'u', 'd', 'x', 'p', 'X':
1392 if (fmtch
= 'p') then fmtch
:= 'x';
1393 if (width
< 8) then width
:= 8;
1396 strblen
:= snprintf(@strbuf
[0], Length(strbuf
), @fmtbuf
[0], PtrUInt(args
[curarg
].VPointer
));
1401 xwrite('<INVALID FORMAT CHAR>');
1402 writer((PAnsiChar(fmt
)+spos
-1)^, Length(fmt
)-spos
+1);
1406 vtPChar
: // args[curarg].VPChar
1407 if (args
[curarg
].VPChar
= nil) then
1409 if (sign
<> '-') then indent(width
-3);
1411 if (sign
= '-') then indent(width
-3);
1416 while (args
[curarg
].VPChar
[pclen
] <> #0) do Inc(pclen
);
1417 if (sign
<> '-') then indent(width
-pclen
);
1418 writer(args
[curarg
].VPChar
^, pclen
);
1419 if (sign
= '-') then indent(width
-pclen
);
1421 vtObject
: // args[curarg].VObject.Classname (TObject)
1423 if (sign
<> '-') then indent(width
-Length(args
[curarg
].VObject
.Classname
));
1424 xwrite(args
[curarg
].VObject
.Classname
);
1425 if (sign
= '-') then indent(width
-Length(args
[curarg
].VObject
.Classname
));
1427 vtClass
: // args[curarg].VClass.Classname (TClass)
1429 if (sign
<> '-') then indent(width
-Length(args
[curarg
].VClass
.Classname
));
1430 xwrite(args
[curarg
].VClass
.Classname
);
1431 if (sign
= '-') then indent(width
-Length(args
[curarg
].VClass
.Classname
));
1433 //vtPWideChar: begin end; // args[curarg].VPWideChar (PWideChar)
1434 vtAnsiString
: // AnsiString(args[curarg].VAnsiString) (Pointer)
1436 if (sign
<> '-') then indent(width
-Length(AnsiString(args
[curarg
].VAnsiString
)));
1437 xwrite(AnsiString(args
[curarg
].VAnsiString
));
1438 if (sign
= '-') then indent(width
-Length(AnsiString(args
[curarg
].VAnsiString
)));
1440 //vtCurrency: begin end; // args[curarg].VCurrency (PCurrency)
1441 //vtVariant: begin end; // args[curarg].VVariant^ (PVariant)
1442 //vtInterface: begin end; // args[curarg].VInterface (Pointer);
1443 //vtWideString: begin end; // args[curarg].VWideString (Pointer);
1444 vtInt64
: // args[curarg].VInt64^ (PInt64)
1447 's','d','u': pc
:= i642str(args
[curarg
].VInt64
^, false, false);
1448 'x': pc
:= i642str(args
[curarg
].VInt64
^, true, false);
1449 'X': pc
:= i642str(args
[curarg
].VInt64
^, true, true);
1450 else begin xwrite('<INVALID FORMAT CHAR>'); writer((PAnsiChar(fmt
)+spos
-1)^, Length(fmt
)-spos
+1); break
; end;
1453 while (pc
[pclen
] <> #0) do Inc(pclen
);
1454 if (sign
<> '-') and (width
> pclen
) then
1458 if (pc
[0] = '-') or (pc
[0] = '+') then
1461 indent0(width
-pclen
-1);
1467 indent0(width
-pclen
);
1472 indent(width
-pclen
);
1476 if (sign
= '-') then indent(width
-pclen
);
1478 vtQWord
: // args[curarg].VQWord^ (PQWord)
1481 's','d','u': pc
:= ui642str(args
[curarg
].VInt64
^, false, false);
1482 'x': pc
:= ui642str(args
[curarg
].VInt64
^, true, false);
1483 'X': pc
:= ui642str(args
[curarg
].VInt64
^, true, true);
1484 else begin xwrite('<INVALID FORMAT CHAR>'); writer((PAnsiChar(fmt
)+spos
-1)^, Length(fmt
)-spos
+1); break
; end;
1487 while (pc
[pclen
] <> #0) do Inc(pclen
);
1488 if (sign
<> '-') then begin if zeropad
then indent0(width
-pclen
) else indent(width
-pclen
); end;
1490 if (sign
= '-') then indent(width
-pclen
);
1494 xwrite('<INVALID TYPE>');
1495 writer((PAnsiChar(fmt
)+spos
-1)^, Length(fmt
)-spos
+1);
1508 i64: Int64 = -$A000000000;
1509 ui64: UInt64 = $A000000000;
1511 writef(conwriter, 'test int:<%s> bool:<%s:%02d:%c> bool:<%s:%02d:%c>; char:<%2s;%c;%d>!'#10, [42, true, true, true, false, false, false, 'A', 'A', 'A']);
1512 writef(conwriter, 'test float:<%s;%u;%f;%g>'#10, [666.6942, 666.6942, 666.6942, 666.6942]);
1515 writef(conwriter, 'test ss:<%5s;%040s>'#10, [ss, ss]);
1516 writef(conwriter, 'test ls:<%5s;%040s>'#10, [ls, ls]);
1517 writef(conwriter, 'test pointer:<%s;%x;%p>'#10, [@ss, @ss, @ss]);
1518 writef(conwriter, 'test i64:<%s;%x;%015d;%u;%X>'#10, [i64, i64, i64, i64, i64]);
1519 writef(conwriter, 'test ui64:<%s;%x;%15d;%015u;%X>'#10, [ui64, ui64, ui64, ui64, ui64]);