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
;
147 type TItemArr
= array of ItemT
;
157 constructor Create (const aitems
: TItemArr
; acount
: Integer);
158 function MoveNext
: Boolean;
159 function getCurrent (): ItemT
;
160 property Current
: ItemT read getCurrent
;
165 mCount
: Integer; // can be less than `mItems` size
168 function getAt (idx
: Integer): ItemT
; inline;
169 procedure setAt (idx
: Integer; const it
: ItemT
); inline;
171 function getCapacity (): Integer; inline;
172 procedure setCapacity (v
: Integer); inline;
175 constructor Create (acapacity
: Integer=-1);
176 destructor Destroy (); override;
178 //WARNING! don't change list contents in `for ... in`!
179 function GetEnumerator (): TEnumerator
;
181 procedure reset (); inline; // won't resize `mItems`
182 procedure clear (); inline;
184 procedure append (constref it
: ItemT
); inline;
187 property count
: Integer read mCount
;
188 property capacity
: Integer read getCapacity write setCapacity
;
189 property at
[idx
: Integer]: ItemT read getAt write setAt
; default
;
196 // ////////////////////////////////////////////////////////////////////////// //
197 constructor TSimpleList
.TEnumerator
.Create (const aitems
: TItemArr
; acount
: Integer);
204 function TSimpleList
.TEnumerator
.MoveNext
: Boolean;
207 result
:= (mCurrent
< mCount
);
210 function TSimpleList
.TEnumerator
.getCurrent (): ItemT
;
212 result
:= mItems
[mCurrent
];
216 // ////////////////////////////////////////////////////////////////////////// //
217 constructor TSimpleList
.Create (acapacity
: Integer=-1);
220 if (acapacity
> 0) then SetLength(mItems
, acapacity
);
225 destructor TSimpleList
.Destroy ();
232 function TSimpleList
.getCapacity (): Integer; inline;
234 result
:= Length(mItems
);
238 procedure TSimpleList
.setCapacity (v
: Integer); inline;
240 if (v
< mCount
) then v
:= mCount
;
241 if (v
<> Length(mItems
)) then SetLength(mItems
, v
);
245 function TSimpleList
.GetEnumerator (): TEnumerator
;
247 if (Length(mItems
) > 0) then result
:= TEnumerator
.Create(mItems
, mCount
)
248 else result
:= TEnumerator
.Create(nil, -1);
252 procedure TSimpleList
.reset (); inline;
258 procedure TSimpleList
.clear (); inline;
265 function TSimpleList
.getAt (idx
: Integer): ItemT
; inline;
267 if (idx
>= 0) and (idx
< mCount
) then result
:= mItems
[idx
] else result
:= Default(ItemT
);
271 procedure TSimpleList
.setAt (idx
: Integer; const it
: ItemT
); inline;
273 if (idx
>= 0) and (idx
< mCount
) then mItems
[idx
] := it
;
277 procedure TSimpleList
.append (constref it
: ItemT
); inline;
279 if (mCount
= Length(mItems
)) then
281 if (mCount
= 0) then SetLength(mItems
, 128) else SetLength(mItems
, mCount
*2);
283 mItems
[mCount
] := it
;
288 // ////////////////////////////////////////////////////////////////////////// //
290 wc2shitmap
: array[0..65535] of AnsiChar;
291 wc2shitmapInited
: Boolean = false;
294 // ////////////////////////////////////////////////////////////////////////// //
296 cp1251
: array[0..127] of Word = (
297 $0402,$0403,$201A,$0453,$201E,$2026,$2020,$2021,$20AC,$2030,$0409,$2039,$040A,$040C,$040B,$040F,
298 $0452,$2018,$2019,$201C,$201D,$2022,$2013,$2014,$003F,$2122,$0459,$203A,$045A,$045C,$045B,$045F,
299 $00A0,$040E,$045E,$0408,$00A4,$0490,$00A6,$00A7,$0401,$00A9,$0404,$00AB,$00AC,$00AD,$00AE,$0407,
300 $00B0,$00B1,$0406,$0456,$0491,$00B5,$00B6,$00B7,$0451,$2116,$0454,$00BB,$0458,$0405,$0455,$0457,
301 $0410,$0411,$0412,$0413,$0414,$0415,$0416,$0417,$0418,$0419,$041A,$041B,$041C,$041D,$041E,$041F,
302 $0420,$0421,$0422,$0423,$0424,$0425,$0426,$0427,$0428,$0429,$042A,$042B,$042C,$042D,$042E,$042F,
303 $0430,$0431,$0432,$0433,$0434,$0435,$0436,$0437,$0438,$0439,$043A,$043B,$043C,$043D,$043E,$043F,
304 $0440,$0441,$0442,$0443,$0444,$0445,$0446,$0447,$0448,$0449,$044A,$044B,$044C,$044D,$044E,$044F
308 procedure initShitMap ();
312 for f
:= 0 to High(wc2shitmap
) do wc2shitmap
[f
] := '?';
313 for f
:= 0 to 127 do wc2shitmap
[f
] := AnsiChar(f
);
314 for f
:= 0 to 127 do wc2shitmap
[cp1251
[f
]] := AnsiChar(f
+128);
315 wc2shitmapInited
:= true;
319 // ////////////////////////////////////////////////////////////////////////// //
320 // fast state-machine based UTF-8 decoder; using 8 bytes of memory
321 // code points from invalid range will never be valid, this is the property of the state machine
323 // see http://bjoern.hoehrmann.de/utf-8/decoder/dfa/
324 utf8dfa
: array[0..$16c-1] of Byte = (
325 // maps bytes to character classes
326 $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00, // 00-0f
327 $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00, // 10-1f
328 $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00, // 20-2f
329 $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00, // 30-3f
330 $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00, // 40-4f
331 $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00, // 50-5f
332 $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00, // 60-6f
333 $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00, // 70-7f
334 $01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01, // 80-8f
335 $09,$09,$09,$09,$09,$09,$09,$09,$09,$09,$09,$09,$09,$09,$09,$09, // 90-9f
336 $07,$07,$07,$07,$07,$07,$07,$07,$07,$07,$07,$07,$07,$07,$07,$07, // a0-af
337 $07,$07,$07,$07,$07,$07,$07,$07,$07,$07,$07,$07,$07,$07,$07,$07, // b0-bf
338 $08,$08,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02, // c0-cf
339 $02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02, // d0-df
340 $0a,$03,$03,$03,$03,$03,$03,$03,$03,$03,$03,$03,$03,$04,$03,$03, // e0-ef
341 $0b,$06,$06,$06,$05,$08,$08,$08,$08,$08,$08,$08,$08,$08,$08,$08, // f0-ff
342 // maps a combination of a state of the automaton and a character class to a state
343 $00,$0c,$18,$24,$3c,$60,$54,$0c,$0c,$0c,$30,$48,$0c,$0c,$0c,$0c, // 100-10f
344 $0c,$0c,$0c,$0c,$0c,$0c,$0c,$0c,$0c,$00,$0c,$0c,$0c,$0c,$0c,$00, // 110-11f
345 $0c,$00,$0c,$0c,$0c,$18,$0c,$0c,$0c,$0c,$0c,$18,$0c,$18,$0c,$0c, // 120-12f
346 $0c,$0c,$0c,$0c,$0c,$0c,$0c,$18,$0c,$0c,$0c,$0c,$0c,$18,$0c,$0c, // 130-13f
347 $0c,$0c,$0c,$0c,$0c,$18,$0c,$0c,$0c,$0c,$0c,$0c,$0c,$0c,$0c,$24, // 140-14f
348 $0c,$24,$0c,$0c,$0c,$24,$0c,$0c,$0c,$0c,$0c,$24,$0c,$24,$0c,$0c, // 150-15f
349 $0c,$24,$0c,$0c,$0c,$0c,$0c,$0c,$0c,$0c,$0c,$0c);
352 // ////////////////////////////////////////////////////////////////////////// //
353 constructor TUtf8DecoderFast
.Create (v
: Boolean{fuck you, fpc}); begin state
:= Accept
; codepoint
:= 0; end;
355 procedure TUtf8DecoderFast
.reset (); inline; begin state
:= Accept
; codepoint
:= 0; end;
357 function TUtf8DecoderFast
.complete (): Boolean; inline; begin result
:= (state
= Accept
); end;
358 function TUtf8DecoderFast
.invalid (): Boolean; inline; begin result
:= (state
= Reject
); end;
359 function TUtf8DecoderFast
.completeOrInvalid (): Boolean; inline; begin result
:= (state
= Accept
) or (state
= Reject
); end;
361 function TUtf8DecoderFast
.decode (c
: AnsiChar): Boolean; inline; overload
; begin result
:= decode(Byte(c
)); end;
363 function TUtf8DecoderFast
.decode (b
: Byte): Boolean; inline; overload
;
367 if (state
= Reject
) then begin state
:= Accept
; codepoint
:= 0; end;
369 if (state
<> Accept
) then codepoint
:= (b
and $3f) or (codepoint
shl 6) else codepoint
:= ($ff shr tp
) and b
;
370 state
:= utf8dfa
[256+state
+tp
];
371 if (state
= Reject
) then begin codepoint
:= Replacement
; state
:= Accept
; end;
372 result
:= (state
= Accept
);
376 // ////////////////////////////////////////////////////////////////////////// //
377 function wchar2win (wc
: WideChar): AnsiChar; inline;
379 if not wc2shitmapInited
then initShitMap();
380 if (LongWord(wc
) > 65535) then result
:= '?' else result
:= wc2shitmap
[LongWord(wc
)];
384 // ////////////////////////////////////////////////////////////////////////// //
385 function utf2win (const s
: AnsiString): AnsiString;
388 ud
: TUtf8DecoderFast
;
390 for f
:= 1 to Length(s
) do
392 if (Byte(s
[f
]) > 127) then
394 ud
:= TUtf8DecoderFast
.Create(true);
396 for c
:= 1 to Length(s
) do
398 if ud
.decode(s
[c
]) then result
+= wchar2win(WideChar(ud
.codepoint
));
407 function win2utf (const s
: AnsiString): AnsiString;
411 function utf8Encode (code
: Integer): AnsiString;
413 if (code
< 0) or (code
> $10FFFF) then begin result
:= '?'; exit
; end;
414 if (code
<= $7f) then
416 result
:= Char(code
and $ff);
418 else if (code
<= $7FF) then
420 result
:= Char($C0 or (code
shr 6));
421 result
+= Char($80 or (code
and $3F));
423 else if (code
<= $FFFF) then
425 result
:= Char($E0 or (code
shr 12));
426 result
+= Char($80 or ((code
shr 6) and $3F));
427 result
+= Char($80 or (code
and $3F));
429 else if (code
<= $10FFFF) then
431 result
:= Char($F0 or (code
shr 18));
432 result
+= Char($80 or ((code
shr 12) and $3F));
433 result
+= Char($80 or ((code
shr 6) and $3F));
434 result
+= Char($80 or (code
and $3F));
443 for f
:= 1 to Length(s
) do
445 if (Byte(s
[f
]) > 127) then
448 for c
:= 1 to Length(s
) do
450 if (Byte(s
[c
]) < 128) then
456 result
+= utf8Encode(cp1251
[Byte(s
[c
])-128])
466 // ////////////////////////////////////////////////////////////////////////// //
467 function digitInBase (ch
: AnsiChar; base
: Integer): Integer;
470 if (base
< 1) or (base
> 36) then exit
;
471 if (ch
< '0') then exit
;
474 if (Integer(ch
) >= 48+base
) then exit
;
475 result
:= Integer(ch
)-48;
479 if (ch
>= '0') and (ch
<= '9') then begin result
:= Integer(ch
)-48; exit
; end;
480 if (ch
>= 'a') and (ch
<= 'z') then Dec(ch
, 32); // poor man's tolower()
481 if (ch
< 'A') or (Integer(ch
) >= 65+(base
-10)) then exit
;
482 result
:= Integer(ch
)-65+10;
487 // ////////////////////////////////////////////////////////////////////////// //
488 function quoteStr (const s
: AnsiString): AnsiString;
490 function squote (const s
: AnsiString): AnsiString;
495 for f
:= 1 to Length(s
) do
497 if (s
[f
] = '''') then result
+= '''';
503 function dquote (const s
: AnsiString): AnsiString;
509 for f
:= 1 to Length(s
) do
512 if (ch
= #0) then result
+= '\z'
513 else if (ch
= #9) then result
+= '\t'
514 else if (ch
= #10) then result
+= '\n'
515 else if (ch
= #13) then result
+= '\r'
516 else if (ch
= #27) then result
+= '\e'
517 else if (ch
< ' ') or (ch
= #127) then
520 result
+= LowerCase(IntToHex(Integer(ch
), 2));
522 else if (ch
= '"') or (ch
= '\') then
536 needSingle
: Boolean = false;
539 for f
:= 1 to Length(s
) do
541 if (s
[f
] = '''') then begin needSingle
:= true; continue
; end;
542 if (s
[f
] < ' ') or (s
[f
] = #127) then begin result
:= dquote(s
); exit
; end;
544 if needSingle
then result
:= squote(s
) else result
:= ''''+s
+'''';
548 // ////////////////////////////////////////////////////////////////////////// //
549 function hasWadExtension (fn
: AnsiString): Boolean;
551 fn
:= ExtractFileExt(fn
);
552 result
:= StrEquCI1251(fn
, '.wad') or StrEquCI1251(fn
, '.pk3') or StrEquCI1251(fn
, '.zip');
556 function addWadExtension (fn
: AnsiString): AnsiString;
559 if not hasWadExtension(result
) then result
:= result
+'.wad';
563 function isWadPath (fn
: AnsiString): Boolean;
572 if (p
= 0) or (length(fn
)-p
< 1) then break
;
573 if (p
-4 > 1) and (fn
[p
-4] = '.') and ((fn
[p
+1] = '\') or (fn
[p
+1] = '/')) then
575 s
:= Copy(fn
, p
-4, 4);
576 if StrEquCI1251(s
, '.wad') or StrEquCI1251(s
, '.pk3') or StrEquCI1251(s
, '.zip') then
587 function Int64ToStrComma (i
: Int64): AnsiString;
592 f
:= Length(result
)+1;
595 Dec(f
, 3); Insert(',', result
, f
);
600 function UpCase1251 (ch
: Char): Char;
604 if (ch
>= 'a') and (ch
<= 'z') then Dec(ch
, 32);
608 if (ch
>= #224) and (ch
<= #255) then
615 #184, #186, #191: Dec(ch
, 16);
624 function LoCase1251 (ch
: Char): Char;
628 if (ch
>= 'A') and (ch
<= 'Z') then Inc(ch
, 32);
632 if (ch
>= #192) and (ch
<= #223) then
639 #168, #170, #175: Inc(ch
, 16);
648 function StrEquCI1251 (const s0
, s1
: AnsiString): Boolean;
653 if length(s0
) <> length(s1
) then exit
;
654 for i
:= 1 to length(s0
) do if UpCase1251(s0
[i
]) <> UpCase1251(s1
[i
]) then exit
;
659 // ////////////////////////////////////////////////////////////////////////// //
663 function utf8CodeLen (ch
: Word): Integer;
665 if ch
< $80 then begin result
:= 1; exit
; end;
666 if (ch
and $FE) = $FC then begin result
:= 6; exit
; end;
667 if (ch
and $FC) = $F8 then begin result
:= 5; exit
; end;
668 if (ch
and $F8) = $F0 then begin result
:= 4; exit
; end;
669 if (ch
and $F0) = $E0 then begin result
:= 3; exit
; end;
670 if (ch
and $E0) = $C0 then begin result
:= 2; exit
; end;
671 result
:= -1; // invalid
675 function utf8Valid (const s
: AnsiString): Boolean;
681 while pos
<= length(s
) do
683 len
:= utf8CodeLen(Byte(s
[pos
]));
684 if len
< 1 then exit
; // invalid sequence start
685 if pos
+len
-1 > length(s
) then exit
; // out of chars in string
688 // check other sequence bytes
691 if (Byte(s
[pos
]) and $C0) <> $80 then exit
;
700 // ////////////////////////////////////////////////////////////////////////// //
702 uni2wint
: array [128..255] of Word = (
703 $0402,$0403,$201A,$0453,$201E,$2026,$2020,$2021,$20AC,$2030,$0409,$2039,$040A,$040C,$040B,$040F,
704 $0452,$2018,$2019,$201C,$201D,$2022,$2013,$2014,$003F,$2122,$0459,$203A,$045A,$045C,$045B,$045F,
705 $00A0,$040E,$045E,$0408,$00A4,$0490,$00A6,$00A7,$0401,$00A9,$0404,$00AB,$00AC,$00AD,$00AE,$0407,
706 $00B0,$00B1,$0406,$0456,$0491,$00B5,$00B6,$00B7,$0451,$2116,$0454,$00BB,$0458,$0405,$0455,$0457,
707 $0410,$0411,$0412,$0413,$0414,$0415,$0416,$0417,$0418,$0419,$041A,$041B,$041C,$041D,$041E,$041F,
708 $0420,$0421,$0422,$0423,$0424,$0425,$0426,$0427,$0428,$0429,$042A,$042B,$042C,$042D,$042E,$042F,
709 $0430,$0431,$0432,$0433,$0434,$0435,$0436,$0437,$0438,$0439,$043A,$043B,$043C,$043D,$043E,$043F,
710 $0440,$0441,$0442,$0443,$0444,$0445,$0446,$0447,$0448,$0449,$044A,$044B,$044C,$044D,$044E,$044F
714 function decodeUtf8Char (s
: AnsiString; var pos
: Integer): char;
718 (* The following encodings are valid, except for the 5 and 6 byte
722 * 1110xxxx 10xxxxxx 10xxxxxx
723 * 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
724 * 111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
725 * 1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
728 if pos
> length(s
) then exit
;
732 if b
< $80 then begin result
:= char(b
); exit
; end;
734 // mask out unused bits
735 if (b
and $FE) = $FC then b
:= b
and $01
736 else if (b
and $FC) = $F8 then b
:= b
and $03
737 else if (b
and $F8) = $F0 then b
:= b
and $07
738 else if (b
and $F0) = $E0 then b
:= b
and $0F
739 else if (b
and $E0) = $C0 then b
:= b
and $1F
740 else exit
; // invalid utf8
743 while pos
<= length(s
) do
746 if (c
and $C0) <> $80 then break
; // no more
748 b
:= b
or (c
and $3F);
753 for c
:= 128 to 255 do if uni2wint
[c
] = b
then begin result
:= char(c
and $FF); exit
; end;
758 function utf8to1251 (s
: AnsiString): AnsiString;
762 if not utf8Valid(s
) then begin result
:= s
; exit
; end;
764 while pos
<= length(s
) do
766 if Byte(s
[pos
]) >= $80 then break
;
769 if pos
> length(s
) then begin result
:= s
; exit
; end; // nothing to do here
772 while pos
<= length(s
) do result
:= result
+decodeUtf8Char(s
, pos
);
776 // ////////////////////////////////////////////////////////////////////////// //
777 // `pathname` will be modified if path is valid
778 // `lastIsDir` should be `true` if we are searching for directory
779 // nobody cares about shitdoze, so i'll use the same code path for it
780 function findFileCI (var pathname
: AnsiString; lastIsDir
: Boolean=false): Boolean;
784 newname
: AnsiString = '';
791 result
:= (length(npt
) > 0);
792 if (length(npt
) > 0) and ((npt
[1] = '/') or (npt
[1] = '\')) then newname
:= '/';
793 while length(npt
) > 0 do
795 // remove trailing slashes
796 while (length(npt
) > 0) and ((npt
[1] = '/') or (npt
[1] = '\')) do Delete(npt
, 1, 1);
797 if length(npt
) = 0 then break
;
800 while (length(npt
) > 0) and (npt
[1] <> '/') and (npt
[1] <> '\') do
802 curname
:= curname
+npt
[1];
805 // remove trailing slashes again
806 while (length(npt
) > 0) and ((npt
[1] = '/') or (npt
[1] = '\')) do Delete(npt
, 1, 1);
807 wantdir
:= lastIsDir
or (length(npt
) > 0); // do we want directory here?
808 //writeln(Format('npt=[%s]; newname=[%s]; curname=[%s]; wantdir=%d', [npt, newname, curname, Integer(wantdir)]));
809 // try the easiest case first
810 attr
:= FileGetAttr(newname
+curname
);
813 if wantdir
= ((attr
and faDirectory
) <> 0) then
816 newname
:= newname
+curname
;
817 if wantdir
then newname
:= newname
+'/';
821 //writeln(Format('npt=[%s]; newname=[%s]; curname=[%s]; wantdir=%d', [npt, newname, curname, Integer(wantdir)]));
822 // alas, either not found, or invalid attributes
825 if FindFirst(newname
+'*', faAnyFile
, sr
) = 0 then
827 if (wantdir
= ((sr
.attr
and faDirectory
) <> 0)) and StrEquCI1251(sr
.name
, curname
) then
830 newname
:= newname
+sr
.name
;
831 if wantdir
then newname
:= newname
+'/';
835 until FindNext(sr
) <> 0;
839 if not foundher
then begin newname
:= ''; result
:= false; break
; end;
841 if result
then pathname
:= newname
;
845 function openDiskFileRO (pathname
: AnsiString): TStream
;
847 if not findFileCI(pathname
) then raise Exception
.Create('can''t open file "'+pathname
+'"');
848 result
:= TFileStream
.Create(pathname
, fmOpenRead
or {fmShareDenyWrite}fmShareDenyNone
);
851 function createDiskFile (pathname
: AnsiString): TStream
;
855 path
:= ExtractFilePath(pathname
);
856 if length(path
) > 0 then
858 if not findFileCI(path
, true) then raise Exception
.Create('can''t create file "'+pathname
+'"');
860 result
:= TFileStream
.Create(path
+ExtractFileName(pathname
), fmCreate
);
864 procedure writeIntegerLE (st
: TStream
; vp
: Pointer; size
: Integer);
865 {$IFDEF ENDIAN_LITTLE}
867 st
.writeBuffer(vp
^, size
);
873 p
:= PByte(vp
)+size
-1;
876 st
.writeBuffer(p
^, 1);
883 procedure writeIntegerBE (st
: TStream
; vp
: Pointer; size
: Integer);
884 {$IFDEF ENDIAN_LITTLE}
888 p
:= PByte(vp
)+size
-1;
891 st
.writeBuffer(p
^, 1);
898 st
.writeBuffer(vp
^, size
);
902 procedure writeInt (st
: TStream
; v
: Byte); overload
; begin writeIntegerLE(st
, @v
, 1); end;
903 procedure writeInt (st
: TStream
; v
: ShortInt); overload
; begin writeIntegerLE(st
, @v
, 1); end;
904 procedure writeInt (st
: TStream
; v
: Word); overload
; begin writeIntegerLE(st
, @v
, 2); end;
905 procedure writeInt (st
: TStream
; v
: SmallInt); overload
; begin writeIntegerLE(st
, @v
, 2); end;
906 procedure writeInt (st
: TStream
; v
: LongWord); overload
; begin writeIntegerLE(st
, @v
, 4); end;
907 procedure writeInt (st
: TStream
; v
: LongInt); overload
; begin writeIntegerLE(st
, @v
, 4); end;
908 procedure writeInt (st
: TStream
; v
: Int64); overload
; begin writeIntegerLE(st
, @v
, 8); end;
909 procedure writeInt (st
: TStream
; v
: UInt64); overload
; begin writeIntegerLE(st
, @v
, 8); end;
911 procedure writeIntBE (st
: TStream
; v
: Byte); overload
; begin writeIntegerBE(st
, @v
, 1); end;
912 procedure writeIntBE (st
: TStream
; v
: ShortInt); overload
; begin writeIntegerBE(st
, @v
, 1); end;
913 procedure writeIntBE (st
: TStream
; v
: Word); overload
; begin writeIntegerBE(st
, @v
, 2); end;
914 procedure writeIntBE (st
: TStream
; v
: SmallInt); overload
; begin writeIntegerBE(st
, @v
, 2); end;
915 procedure writeIntBE (st
: TStream
; v
: LongWord); overload
; begin writeIntegerBE(st
, @v
, 4); end;
916 procedure writeIntBE (st
: TStream
; v
: LongInt); overload
; begin writeIntegerBE(st
, @v
, 4); end;
917 procedure writeIntBE (st
: TStream
; v
: Int64); overload
; begin writeIntegerBE(st
, @v
, 8); end;
918 procedure writeIntBE (st
: TStream
; v
: UInt64); overload
; begin writeIntegerBE(st
, @v
, 8); end;
921 procedure readIntegerLE (st
: TStream
; vp
: Pointer; size
: Integer);
922 {$IFDEF ENDIAN_LITTLE}
924 st
.readBuffer(vp
^, size
);
930 p
:= PByte(vp
)+size
-1;
933 st
.readBuffer(p
^, 1);
940 procedure readIntegerBE (st
: TStream
; vp
: Pointer; size
: Integer);
941 {$IFDEF ENDIAN_LITTLE}
945 p
:= PByte(vp
)+size
-1;
948 st
.readBuffer(p
^, 1);
955 st
.readBuffer(vp
^, size
);
959 function readByte (st
: TStream
): Byte; begin readIntegerLE(st
, @result
, 1); end;
960 function readShortInt (st
: TStream
): ShortInt; begin readIntegerLE(st
, @result
, 1); end;
961 function readWord (st
: TStream
): Word; begin readIntegerLE(st
, @result
, 2); end;
962 function readSmallInt (st
: TStream
): SmallInt; begin readIntegerLE(st
, @result
, 2); end;
963 function readLongWord (st
: TStream
): LongWord; begin readIntegerLE(st
, @result
, 4); end;
964 function readLongInt (st
: TStream
): LongInt; begin readIntegerLE(st
, @result
, 4); end;
965 function readInt64 (st
: TStream
): Int64; begin readIntegerLE(st
, @result
, 8); end;
966 function readUInt64 (st
: TStream
): UInt64; begin readIntegerLE(st
, @result
, 8); end;
968 function readByteBE (st
: TStream
): Byte; begin readIntegerBE(st
, @result
, 1); end;
969 function readShortIntBE (st
: TStream
): ShortInt; begin readIntegerBE(st
, @result
, 1); end;
970 function readWordBE (st
: TStream
): Word; begin readIntegerBE(st
, @result
, 2); end;
971 function readSmallIntBE (st
: TStream
): SmallInt; begin readIntegerBE(st
, @result
, 2); end;
972 function readLongWordBE (st
: TStream
): LongWord; begin readIntegerBE(st
, @result
, 4); end;
973 function readLongIntBE (st
: TStream
): LongInt; begin readIntegerBE(st
, @result
, 4); end;
974 function readInt64BE (st
: TStream
): Int64; begin readIntegerBE(st
, @result
, 8); end;
975 function readUInt64BE (st
: TStream
): UInt64; begin readIntegerBE(st
, @result
, 8); end;
978 // ////////////////////////////////////////////////////////////////////////// //
980 function snprintf (buf
: PAnsiChar; bufsize
: SizeUInt
; const fmt
: PAnsiChar): SizeUInt
; cdecl; varargs
; external 'msvcrt.dll' name
'_snprintf';
982 function snprintf (buf
: PAnsiChar; bufsize
: SizeUInt
; const fmt
: PAnsiChar): SizeUInt
; cdecl; varargs
; external 'libc' name
'snprintf';
987 procedure conwriter (constref buf; len: SizeUInt);
993 if (len < 1) then exit;
997 if (len > 255) then slen := 255 else slen := Integer(len);
998 Move(b^, ss[1], len);
999 ss[0] := AnsiChar(slen);
1008 function formatstrf (const fmt
: AnsiString; args
: array of const; writerCB
: TFormatStrFCallback
=nil): AnsiString;
1010 PadSpaces
: AnsiString = ' ';
1011 PadZeroes
: AnsiString = '00000000000000000000000000000000000000000000000000000000000000000000000';
1013 curarg
: Integer = 0; // current arg in `args`
1014 sign
, fmtch
: AnsiChar;
1016 width
, prec
: Integer; // width and precision
1017 spos
, epos
: Integer;
1019 strbuf
: array[0..256] of AnsiChar;
1021 fmtbuf
: array[0..256] of AnsiChar;
1026 procedure writer (constref buf
; len
: SizeUInt
);
1032 if (len
< 1) then exit
;
1034 if assigned(writerCB
) then
1042 if (len
> 255) then slen
:= 255 else slen
:= Integer(len
);
1043 Move(b
^, ss
[1], slen
);
1044 ss
[0] := AnsiChar(slen
);
1052 procedure xwrite (const s
: AnsiString);
1054 if (Length(s
) > 0) then writer(PAnsiChar(s
)^, Length(s
));
1057 procedure putFmtChar (ch
: AnsiChar);
1059 fmtbuf
[fmtblen
] := ch
;
1063 procedure putFmtInt (n
: Integer);
1067 len
:= snprintf(@fmtbuf
[fmtblen
], Length(fmtbuf
)-fmtblen
, '%d', n
);
1068 if (len
> 0) then Inc(fmtblen
, len
);
1071 procedure buildCFormat (const pfx
: AnsiString='');
1076 for f
:= 1 to Length(pfx
) do putFmtChar(pfx
[f
]);
1078 if (sign
<> ' ') then putFmtChar(sign
);
1079 if (width
>= 0) then
1081 if (zeropad
) then putFmtChar('0');
1090 fmtbuf
[fmtblen
] := #0;
1093 procedure writeStrBuf ();
1095 if (strblen
> 0) then writer(strbuf
, strblen
);
1098 function i642str (n
: Int64; hex
: Boolean; hexup
: Boolean): PAnsiChar;
1103 if (n
= $8000000000000000) then
1105 if hex
then snprintf(@strbuf
[0], Length(strbuf
), '-8000000000000000')
1106 else snprintf(@strbuf
[0], Length(strbuf
), '-9223372036854775808');
1107 result
:= @strbuf
[0];
1112 if neg
then n
:= -n
;
1113 xpos
:= High(strbuf
);
1114 strbuf
[xpos
] := #0; Dec(xpos
);
1118 strbuf
[xpos
] := AnsiChar((n
mod 10)+48);
1124 if (n
mod 16 > 9) then
1126 strbuf
[xpos
] := AnsiChar((n
mod 16)+48+7);
1127 if not hexup
then Inc(strbuf
[xpos
], 32);
1129 else strbuf
[xpos
] := AnsiChar((n
mod 16)+48);
1134 if neg
then begin strbuf
[xpos
] := '-'; Dec(xpos
); end;
1135 result
:= @strbuf
[xpos
+1];
1139 function ui642str (n
: UInt64; hex
: Boolean; hexup
: Boolean): PAnsiChar;
1143 xpos
:= High(strbuf
);
1144 strbuf
[xpos
] := #0; Dec(xpos
);
1148 strbuf
[xpos
] := AnsiChar((n
mod 10)+48);
1154 if (n
mod 16 > 9) then
1156 strbuf
[xpos
] := AnsiChar((n
mod 16)+48+7);
1157 if not hexup
then Inc(strbuf
[xpos
], 32);
1159 else strbuf
[xpos
] := AnsiChar((n
mod 16)+48);
1164 result
:= @strbuf
[xpos
+1];
1167 procedure indent (len
: Integer);
1173 if (len
> Length(PadSpaces
)) then ilen
:= Length(PadSpaces
) else ilen
:= len
;
1174 writer(PAnsiChar(PadSpaces
)^, ilen
);
1179 procedure indent0 (len
: Integer);
1185 if (len
> Length(PadZeroes
)) then ilen
:= Length(PadZeroes
) else ilen
:= len
;
1186 writer(PAnsiChar(PadZeroes
)^, ilen
);
1194 while (spos
<= Length(fmt
)) do
1196 // print literal part
1198 while (epos
<= Length(fmt
)) and (fmt
[epos
] <> '%') do Inc(epos
);
1199 // output literal part
1200 if (epos
> spos
) then
1202 if (epos
> Length(fmt
)) then
1204 writer((PAnsiChar(fmt
)+spos
-1)^, epos
-spos
);
1207 if (epos
+1 > Length(fmt
)) then Inc(epos
) // last percent, output literally
1208 else if (fmt
[epos
+1] = '%') then // special case
1211 writer((PAnsiChar(fmt
)+spos
-1)^, epos
-spos
);
1216 writer((PAnsiChar(fmt
)+spos
-1)^, epos
-spos
);
1221 // check if we have argument for this format string
1222 if (curarg
> High(args
)) then
1224 xwrite('<OUT OF ARGS>');
1225 writer((PAnsiChar(fmt
)+spos
-1)^, Length(fmt
)-spos
+1);
1229 if (spos
+1 > Length(fmt
)) then break
; // oops
1230 assert(fmt
[spos
] = '%');
1232 // parse format; check for sign
1233 if (fmt
[spos
] = '-') then begin sign
:= '-'; Inc(spos
); end
1234 else if (fmt
[spos
] = '+') then begin sign
:= '+'; Inc(spos
); end
1237 if (spos
> Length(fmt
)) then begin xwrite('<INVALID FORMAT>'); break
; end;
1238 if (sign
<> ' ') or ((fmt
[spos
] >= '0') and (fmt
[spos
] <= '9')) then
1240 if (fmt
[spos
] < '0') or (fmt
[spos
] > '9') then begin xwrite('<INVALID FORMAT>'); writer((PAnsiChar(fmt
)+spos
-1)^, Length(fmt
)-spos
+1); break
; end;
1241 zeropad
:= (fmt
[spos
] = '0');
1243 while (spos
<= Length(fmt
)) do
1246 if (ch
< '0') or (ch
> '9') then break
;
1247 width
:= width
*10+Integer(ch
)-48;
1258 if (spos
<= Length(fmt
)) and (fmt
[spos
] = '.') then
1261 if (spos
> Length(fmt
)) then begin xwrite('<INVALID FORMAT>'); break
; end;
1262 if (fmt
[spos
] < '0') or (fmt
[spos
] > '9') then begin xwrite('<INVALID FORMAT>'); writer((PAnsiChar(fmt
)+spos
-1)^, Length(fmt
)-spos
+1); break
; end;
1264 while (spos
<= Length(fmt
)) do
1267 if (ch
< '0') or (ch
> '9') then break
;
1268 prec
:= prec
*10+Integer(ch
)-48;
1273 if (spos
> Length(fmt
)) then begin xwrite('<INVALID FORMAT>'); break
; end;
1276 // done parsing format, check for valid format chars
1277 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;
1278 // now write formatted string
1279 case args
[curarg
].VType
of
1280 vtInteger
: // args[curarg].VInteger
1282 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;
1283 if (fmtch
= 's') then fmtch
:= 'd';
1285 strblen
:= snprintf(@strbuf
[0], Length(strbuf
), @fmtbuf
[0], args
[curarg
].VInteger
);
1288 vtBoolean
: // args[curarg].VBoolean
1293 if args
[curarg
].VBoolean
then strblen
:= snprintf(@strbuf
[0], Length(strbuf
), @fmtbuf
[0], 'true')
1294 else strblen
:= snprintf(@strbuf
[0], Length(strbuf
), @fmtbuf
[0], 'false');
1300 if args
[curarg
].VBoolean
then strblen
:= snprintf(@strbuf
[0], Length(strbuf
), @fmtbuf
[0], AnsiChar('t'))
1301 else strblen
:= snprintf(@strbuf
[0], Length(strbuf
), @fmtbuf
[0], AnsiChar('f'));
1307 strblen
:= snprintf(@strbuf
[0], Length(strbuf
), @fmtbuf
[0], Integer(args
[curarg
].VBoolean
));
1312 xwrite('<INVALID FORMAT CHAR>');
1313 writer((PAnsiChar(fmt
)+spos
-1)^, Length(fmt
)-spos
+1);
1317 vtChar
: // args[curarg].VChar
1323 strblen
:= snprintf(@strbuf
[0], Length(strbuf
), @fmtbuf
[0], args
[curarg
].VChar
);
1329 strblen
:= snprintf(@strbuf
[0], Length(strbuf
), @fmtbuf
[0], Integer(args
[curarg
].VChar
));
1334 xwrite('<INVALID FORMAT CHAR>');
1335 writer((PAnsiChar(fmt
)+spos
-1)^, Length(fmt
)-spos
+1);
1339 //vtWideChar: begin end; // args[curarg].VWideChar (WideChar)
1340 vtExtended
: // args[curarg].VExtended^
1346 strblen
:= snprintf(@strbuf
[0], Length(strbuf
), @fmtbuf
[0], Double(args
[curarg
].VExtended
^));
1352 strblen
:= snprintf(@strbuf
[0], Length(strbuf
), @fmtbuf
[0], Double(args
[curarg
].VExtended
^));
1358 strblen
:= snprintf(@strbuf
[0], Length(strbuf
), @fmtbuf
[0], Integer(trunc(args
[curarg
].VExtended
^)));
1364 strblen
:= snprintf(@strbuf
[0], Length(strbuf
), @fmtbuf
[0], LongWord(trunc(args
[curarg
].VExtended
^)));
1369 xwrite('<INVALID FORMAT CHAR>');
1370 writer((PAnsiChar(fmt
)+spos
-1)^, Length(fmt
)-spos
+1);
1374 vtString
: // args[curarg].VString^ (PShortString)
1376 if (sign
<> '-') then indent(width
-Length(args
[curarg
].VString
^));
1377 writer(args
[curarg
].VString
^[1], Length(args
[curarg
].VString
^));
1378 if (sign
= '-') then indent(width
-Length(args
[curarg
].VString
^));
1380 vtPointer
: // args[curarg].VPointer
1385 if (width
< 8) then width
:= 8;
1388 strblen
:= snprintf(@strbuf
[0], Length(strbuf
), @fmtbuf
[0], PtrUInt(args
[curarg
].VPointer
));
1391 'u', 'd', 'x', 'p', 'X':
1393 if (fmtch
= 'p') then fmtch
:= 'x';
1394 if (width
< 8) then width
:= 8;
1397 strblen
:= snprintf(@strbuf
[0], Length(strbuf
), @fmtbuf
[0], PtrUInt(args
[curarg
].VPointer
));
1402 xwrite('<INVALID FORMAT CHAR>');
1403 writer((PAnsiChar(fmt
)+spos
-1)^, Length(fmt
)-spos
+1);
1407 vtPChar
: // args[curarg].VPChar
1408 if (args
[curarg
].VPChar
= nil) then
1410 if (sign
<> '-') then indent(width
-3);
1412 if (sign
= '-') then indent(width
-3);
1417 while (args
[curarg
].VPChar
[pclen
] <> #0) do Inc(pclen
);
1418 if (sign
<> '-') then indent(width
-pclen
);
1419 writer(args
[curarg
].VPChar
^, pclen
);
1420 if (sign
= '-') then indent(width
-pclen
);
1422 vtObject
: // args[curarg].VObject.Classname (TObject)
1424 if (sign
<> '-') then indent(width
-Length(args
[curarg
].VObject
.Classname
));
1425 xwrite(args
[curarg
].VObject
.Classname
);
1426 if (sign
= '-') then indent(width
-Length(args
[curarg
].VObject
.Classname
));
1428 vtClass
: // args[curarg].VClass.Classname (TClass)
1430 if (sign
<> '-') then indent(width
-Length(args
[curarg
].VClass
.Classname
));
1431 xwrite(args
[curarg
].VClass
.Classname
);
1432 if (sign
= '-') then indent(width
-Length(args
[curarg
].VClass
.Classname
));
1434 //vtPWideChar: begin end; // args[curarg].VPWideChar (PWideChar)
1435 vtAnsiString
: // AnsiString(args[curarg].VAnsiString) (Pointer)
1437 if (sign
<> '-') then indent(width
-Length(AnsiString(args
[curarg
].VAnsiString
)));
1438 xwrite(AnsiString(args
[curarg
].VAnsiString
));
1439 if (sign
= '-') then indent(width
-Length(AnsiString(args
[curarg
].VAnsiString
)));
1441 //vtCurrency: begin end; // args[curarg].VCurrency (PCurrency)
1442 //vtVariant: begin end; // args[curarg].VVariant^ (PVariant)
1443 //vtInterface: begin end; // args[curarg].VInterface (Pointer);
1444 //vtWideString: begin end; // args[curarg].VWideString (Pointer);
1445 vtInt64
: // args[curarg].VInt64^ (PInt64)
1448 's','d','u': pc
:= i642str(args
[curarg
].VInt64
^, false, false);
1449 'x': pc
:= i642str(args
[curarg
].VInt64
^, true, false);
1450 'X': pc
:= i642str(args
[curarg
].VInt64
^, true, true);
1451 else begin xwrite('<INVALID FORMAT CHAR>'); writer((PAnsiChar(fmt
)+spos
-1)^, Length(fmt
)-spos
+1); break
; end;
1454 while (pc
[pclen
] <> #0) do Inc(pclen
);
1455 if (sign
<> '-') and (width
> pclen
) then
1459 if (pc
[0] = '-') or (pc
[0] = '+') then
1462 indent0(width
-pclen
-1);
1468 indent0(width
-pclen
);
1473 indent(width
-pclen
);
1477 if (sign
= '-') then indent(width
-pclen
);
1479 vtQWord
: // args[curarg].VQWord^ (PQWord)
1482 's','d','u': pc
:= ui642str(args
[curarg
].VInt64
^, false, false);
1483 'x': pc
:= ui642str(args
[curarg
].VInt64
^, true, false);
1484 'X': pc
:= ui642str(args
[curarg
].VInt64
^, true, true);
1485 else begin xwrite('<INVALID FORMAT CHAR>'); writer((PAnsiChar(fmt
)+spos
-1)^, Length(fmt
)-spos
+1); break
; end;
1488 while (pc
[pclen
] <> #0) do Inc(pclen
);
1489 if (sign
<> '-') then begin if zeropad
then indent0(width
-pclen
) else indent(width
-pclen
); end;
1491 if (sign
= '-') then indent(width
-pclen
);
1495 xwrite('<INVALID TYPE>');
1496 writer((PAnsiChar(fmt
)+spos
-1)^, Length(fmt
)-spos
+1);
1509 i64: Int64 = -$A000000000;
1510 ui64: UInt64 = $A000000000;
1512 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']);
1513 writef(conwriter, 'test float:<%s;%u;%f;%g>'#10, [666.6942, 666.6942, 666.6942, 666.6942]);
1516 writef(conwriter, 'test ss:<%5s;%040s>'#10, [ss, ss]);
1517 writef(conwriter, 'test ls:<%5s;%040s>'#10, [ls, ls]);
1518 writef(conwriter, 'test pointer:<%s;%x;%p>'#10, [@ss, @ss, @ss]);
1519 writef(conwriter, 'test i64:<%s;%x;%015d;%u;%X>'#10, [i64, i64, i64, i64, i64]);
1520 writef(conwriter, 'test ui64:<%s;%x;%15d;%015u;%X>'#10, [ui64, ui64, ui64, ui64, ui64]);