syshelp.inc 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983
  1. {%mainunit syshelpers.pp}
  2. { ---------------------------------------------------------------------
  3. TGUIDHelper
  4. ---------------------------------------------------------------------}
  5. Procedure NotImplemented(S : String);
  6. begin
  7. Raise Exception.Create('Not yet implemented : '+S);
  8. end;
  9. Class function TGUIDHelper.Create(const Data; BigEndian: Boolean): TGUID; overload; static;
  10. Const
  11. GUIDSize = SizeOf(TGUID);
  12. Var
  13. B : Array[1..GUIDSize] of Byte;
  14. begin
  15. Move(Data,B,GUIDSize);
  16. Result:=Create(B,0,BigEndian);
  17. end;
  18. class function TGUIDHelper.Create(const Data: array of Byte; AStartIndex: Cardinal; BigEndian: Boolean): TGUID; overload; static;
  19. Var
  20. A : Cardinal;
  21. B,C : Word;
  22. begin
  23. if ((System.Length(Data)-AStartIndex)<16) then
  24. raise EArgumentException.CreateFmt('The length of a GUID array must be at least %d',[]);
  25. Move(Data[AStartIndex],A,SizeOf(Cardinal));
  26. Move(Data[AStartIndex+4],B,SizeOf(Word));
  27. Move(Data[AStartIndex+6],C,SizeOf(Word));
  28. // Writeln('BigEndian : ',BigEndian,', CPU bigendian : ',(CPUendian=TEndian.Big));
  29. if BigEndian<>(CPUendian=TEndian.Big) then
  30. begin
  31. // Writeln('Swapping');
  32. A:=SwapEndian(A);
  33. B:=SwapEndian(B);
  34. C:=SwapEndian(C);
  35. end;
  36. Result:=Create(A,B,C,Data[AStartIndex+8],Data[AStartIndex+9],Data[AStartIndex+10],Data[AStartIndex+11],Data[AStartIndex+12],Data[AStartIndex+13],Data[AStartIndex+14],Data[AStartIndex+15]);
  37. end;
  38. Class Function TGUIDHelper.Create(const Data; DataEndian: TEndian = CPUEndian): TGUID; overload; static; inline;
  39. begin
  40. Result:=Create(Data,DataEndian=TEndian.Big)
  41. end;
  42. Class Function TGUIDHelper.Create(const B: TBytes; DataEndian: TEndian = CPUEndian): TGUID; overload; static; inline;
  43. begin
  44. Result:=Create(B,0,DataEndian);
  45. end;
  46. Class Function TGUIDHelper.Create(const B: TBytes; AStartIndex: Cardinal; DataEndian: TEndian = CPUEndian): TGUID; overload; static;
  47. begin
  48. if ((System.Length(B)-AStartIndex)<16) then
  49. raise EArgumentException.CreateFmt('The length of a GUID array must be at least %d',[]);
  50. Result:=Create(B,AStartIndex,DataEndian=TEndian.Big);
  51. end;
  52. Class Function TGUIDHelper.Create(const S: string): TGUID; overload; static;
  53. begin
  54. Result:=StringToGUID(S);
  55. end;
  56. Class Function TGUIDHelper.Create(A: Integer; B: SmallInt; C: SmallInt; const D: TBytes): TGUID; overload; static;
  57. begin
  58. if (System.Length(D)<>8) then
  59. raise EArgumentException.CreateFmt('The length of a GUID array must be %d',[]);
  60. Result:=Create(Cardinal(A),Word(B),Word(C),D[0],D[1],D[2],D[3],D[4],D[5],D[6],D[7]);
  61. end;
  62. Class Function TGUIDHelper.Create(A: Integer; B: SmallInt; C: SmallInt; D, E, F, G, H, I, J, K: Byte): TGUID; overload; static;
  63. begin
  64. Result:=Create(Cardinal(A),Word(B),Word(C),D,E,F,G,H,I,J,K);
  65. end;
  66. Class Function TGUIDHelper.Create(A: Cardinal; B: Word; C: Word; D, E, F, G, H, I, J, K: Byte): TGUID; overload; static;
  67. begin
  68. Result.D1 := Cardinal(A);
  69. Result.D2 := Word(B);
  70. Result.D3 := Word(C);
  71. Result.D4[0] := D;
  72. Result.D4[1] := E;
  73. Result.D4[2] := F;
  74. Result.D4[3] := G;
  75. Result.D4[4] := H;
  76. Result.D4[5] := I;
  77. Result.D4[6] := J;
  78. Result.D4[7] := K;
  79. end;
  80. Class Function TGUIDHelper.NewGuid: TGUID; static;
  81. begin
  82. CreateGUID(Result)
  83. end;
  84. Function TGUIDHelper.ToByteArray(DataEndian: TEndian = CPUEndian): TBytes;
  85. begin
  86. SetLength(Result, 16);
  87. if DataEndian<>CPUEndian then
  88. begin
  89. PCardinal(@Result[0])^ := SwapEndian(D1);
  90. PWord(@Result[4])^ := SwapEndian(D2);
  91. PWord(@Result[6])^ := SwapEndian(D3);
  92. Move(D4, Result[8], 8);
  93. end
  94. else
  95. Move(D1, Result[0], SizeOf(Self));
  96. end;
  97. Function TGUIDHelper.ToString(SkipBrackets : Boolean = False): string;
  98. begin
  99. Result:=GuidToString(Self);
  100. If SkipBrackets then
  101. Result:=Copy(Result,2,Length(Result)-2);
  102. end;
  103. { ---------------------------------------------------------------------
  104. TStringHelper
  105. ---------------------------------------------------------------------}
  106. Function HaveChar(AChar : Char; const AList: array of Char) : Boolean;
  107. Var
  108. I : SizeInt;
  109. begin
  110. I:=0;
  111. Result:=False;
  112. While (Not Result) and (I<Length(AList)) do
  113. begin
  114. Result:=(AList[i]=AChar);
  115. Inc(I);
  116. end;
  117. end;
  118. function TStringHelper.GetChar(AIndex: SizeInt): Char;
  119. begin
  120. Result:=Self[AIndex+1];
  121. end;
  122. function TStringHelper.GetLength: SizeInt;
  123. begin
  124. Result:=System.Length(Self);
  125. end;
  126. class function TStringHelper.Compare(const A: string; const B: string): Integer;
  127. begin
  128. Result:=Compare(A,0,B,0,System.Length(B),[]);
  129. end;
  130. class function TStringHelper.Compare(const A: string; const B: string;
  131. IgnoreCase: Boolean): Integer; //deprecated 'Use same with TCompareOptions';
  132. begin
  133. if IgnoreCase then
  134. Result:=Compare(A,B,[coIgnoreCase])
  135. else
  136. Result:=Compare(A,B,[]);
  137. end;
  138. class function TStringHelper.Compare(const A: string; const B: string;
  139. Options: TCompareOptions): Integer;
  140. begin
  141. Result:=Compare(A,0,B,0,System.Length(B),Options);
  142. end;
  143. class function TStringHelper.Compare(const A: string; IndexA: SizeInt;
  144. const B: string; IndexB: SizeInt; ALen: SizeInt): Integer;
  145. begin
  146. Result:=Compare(A,IndexA,B,IndexB,ALen,[]);
  147. end;
  148. class function TStringHelper.Compare(const A: string; IndexA: SizeInt;
  149. const B: string; IndexB: SizeInt; ALen: SizeInt; IgnoreCase: Boolean
  150. ): Integer; //deprecated 'Use same with TCompareOptions';
  151. begin
  152. if IgnoreCase then
  153. Result:=Compare(A,IndexA,B,IndexB,ALen,[coIgnoreCase])
  154. else
  155. Result:=Compare(A,IndexA,B,IndexB,ALen,[])
  156. end;
  157. class function TStringHelper.Compare(const A: string; IndexA: SizeInt;
  158. const B: string; IndexB: SizeInt; ALen: SizeInt; Options: TCompareOptions
  159. ): Integer;
  160. Var
  161. L : SizeInt;
  162. begin
  163. L:=ALen;
  164. If (L>system.Length(A)-IndexA) then
  165. L:=system.Length(A)-IndexA;
  166. If (L>system.Length(B)-IndexB) then
  167. L:=system.Length(B)-IndexB;
  168. if (coIgnoreCase in Options) then
  169. begin
  170. Result:=strlicomp(PAnsiChar(@A[IndexA+1]),PAnsiChar(@B[IndexB+1]),L)
  171. end
  172. else
  173. Result:=strlcomp(PAnsiChar(@A[IndexA+1]),PAnsiChar(@B[IndexB+1]),L);
  174. end;
  175. class function TStringHelper.CompareOrdinal(const A: string; const B: string
  176. ): Integer;
  177. Var
  178. L : SizeInt;
  179. begin
  180. L:=System.Length(B);
  181. if L>System.Length(A) then
  182. L:=System.Length(A);
  183. Result:=CompareOrdinal(A,0,B,0,L);
  184. end;
  185. class function TStringHelper.CompareOrdinal(const A: string; IndexA: SizeInt;
  186. const B: string; IndexB: SizeInt; ALen: SizeInt): Integer;
  187. begin
  188. Result:=StrLComp(PAnsiChar(@A[IndexA+1]), PAnsiChar(@B[IndexB+1]), ALen);
  189. end;
  190. class function TStringHelper.CompareText(const A: string; const B: string
  191. ): Integer;
  192. begin
  193. Result:=Sysutils.CompareText(A,B);
  194. end;
  195. class function TStringHelper.Copy(const Str: string): string;
  196. begin
  197. Result:=Str;
  198. UniqueString(Result);
  199. end;
  200. class function TStringHelper.Create(AChar: Char; ACount: SizeInt): string;
  201. begin
  202. Result:=StringOfChar(AChar,ACount);
  203. end;
  204. class function TStringHelper.Create(const AValue: array of Char): string;
  205. begin
  206. Result:=Create(AValue,0,System.Length(AValue));
  207. end;
  208. class function TStringHelper.Create(const AValue: array of Char;
  209. StartIndex: SizeInt; ALen: SizeInt): string;
  210. begin
  211. SetLength(Result,ALen);
  212. if ALen>0 then
  213. Move(AValue[StartIndex],Result[1],ALen);
  214. end;
  215. class function TStringHelper.EndsText(const ASubText, AText: string): Boolean;
  216. begin
  217. Result:=(ASubText<>'') and (sysutils.CompareText(System.Copy(AText,System.Length(AText)-System.Length(ASubText)+1,System.Length(ASubText)),ASubText)=0);
  218. end;
  219. class function TStringHelper.Equals(const a: string; const b: string): Boolean;
  220. begin
  221. Result:=A=B;
  222. end;
  223. class function TStringHelper.Format(const AFormat: string;
  224. const args: array of const): string;
  225. begin
  226. Result:=Sysutils.Format(AFormat,Args);
  227. end;
  228. class function TStringHelper.IsNullOrEmpty(const AValue: string): Boolean;
  229. begin
  230. Result:=system.Length(AValue)=0;
  231. end;
  232. class function TStringHelper.IsNullOrWhiteSpace(const AValue: string): Boolean;
  233. const
  234. LWhiteSpace = [#0..' '];
  235. var
  236. I: SizeInt;
  237. begin
  238. for I:=1 to System.Length(AValue) do
  239. if not (AValue[I] in LWhiteSpace) then
  240. exit(False);
  241. Result:=True;
  242. end;
  243. class function TStringHelper.Join(const Separator: string;
  244. const Values: array of const): string;
  245. Var
  246. SValues : Array of string;
  247. I,L : SizeInt;
  248. S : String;
  249. P : ^TVarRec;
  250. begin
  251. L:=System.Length(Values);
  252. SetLength(SValues,L);
  253. Dec(L);
  254. for I:=0 to L do
  255. begin
  256. S:='';
  257. P:=@Values[I];
  258. Case P^.VType of
  259. vtInteger : S:=IntToStr(P^.VInteger);
  260. vtBoolean : S:=BoolToStr(P^.VBoolean, True);
  261. vtChar : S:=P^.VChar;
  262. vtPChar : S:= string(P^.VPChar);
  263. {$ifndef FPUNONE}
  264. vtExtended : S:=FloatToStr(P^.VExtended^);
  265. {$endif}
  266. vtObject : S:=TObject(P^.VObject).Classname;
  267. vtClass : S:=P^.VClass.Classname;
  268. vtCurrency : S:=CurrToStr(P^.VCurrency^);
  269. vtVariant : S:=(P^.VVariant^);
  270. vtInt64 : S:=IntToStr(PInt64(P^.VInt64)^);
  271. vtQword : S:=IntToStr(PQWord(P^.VQword)^);
  272. vtWideChar : S:=WideString(P^.VWideChar);
  273. vtPWideChar : S:=WideString(P^.VPWideChar);
  274. vtUnicodeString : S:=UnicodeString(P^.VUnicodeString);
  275. vtAnsiString : S:=Ansistring(P^.VAnsiString);
  276. else
  277. S:=Format('Unknown type: %d',[P^.VType]);
  278. end;
  279. SValues[I]:=S;
  280. end;
  281. Result:=Join(Separator,SValues);
  282. end;
  283. class function TStringHelper.Join(const Separator: string;
  284. const Values: array of string): string;
  285. begin
  286. Result:=Join(Separator,Values,0,System.Length(Values));
  287. end;
  288. class function TStringHelper.Join(const Separator: string;
  289. const Values: array of string; StartIndex: SizeInt; ACount: SizeInt): string;
  290. Var
  291. VLen,I,CountLim,NR,NSep,N : SizeInt;
  292. Rp: PChar;
  293. begin
  294. VLen:=System.Length(Values);
  295. If (ACount=0) then
  296. Exit('');
  297. CountLim:=VLen-StartIndex;
  298. if ACount>CountLim then
  299. ACount:=CountLim;
  300. If (ACount<0) or (StartIndex>VLen) or (StartIndex<0) then
  301. raise ERangeError.Create(SRangeError);
  302. if ACount=1 then
  303. exit(Values[StartIndex]);
  304. NSep:=System.Length(Separator);
  305. NR:=(ACount-1)*NSep;
  306. for I:=StartIndex to StartIndex+ACount-1 do
  307. NR:=NR+System.Length(Values[I]);
  308. SetLength(Result,NR);
  309. Rp:=@Result[1];
  310. for I:=StartIndex to StartIndex+ACount-1 do
  311. begin
  312. if I>StartIndex then
  313. begin
  314. Move(separator[1],Rp^,NSep*sizeof(Char));
  315. Rp:=Rp+NSep;
  316. end;
  317. N:=System.Length(Values[I]);
  318. Move(Values[I][1],Rp^,N*sizeof(Char));
  319. Rp:=Rp+N;
  320. end;
  321. end;
  322. class function TStringHelper.LowerCase(const S: string): string;
  323. begin
  324. Result:=sysutils.Lowercase(S);
  325. end;
  326. class function TStringHelper.Parse(const AValue: Boolean): string;
  327. begin
  328. Result:=BoolToStr(AValue);
  329. end;
  330. class function TStringHelper.Parse(const AValue: Extended): string;
  331. begin
  332. Result:=FloatToStr(AValue);
  333. end;
  334. class function TStringHelper.Parse(const AValue: Int64): string;
  335. begin
  336. Result:=IntToStr(AValue);
  337. end;
  338. class function TStringHelper.Parse(const AValue: Integer): string;
  339. begin
  340. Result:=IntToStr(AValue);
  341. end;
  342. class function TStringHelper.ToBoolean(const S: string): Boolean;
  343. begin
  344. Result:=StrToBool(S);
  345. end;
  346. class function TStringHelper.ToDouble(const S: string): Double;
  347. begin
  348. Result:=StrToFloat(S);
  349. end;
  350. class function TStringHelper.ToExtended(const S: string): Extended;
  351. begin
  352. Result:=StrToFloat(S);
  353. end;
  354. class function TStringHelper.ToInt64(const S: string): Int64;
  355. begin
  356. Result:=StrToInt64(S);
  357. end;
  358. class function TStringHelper.ToInteger(const S: string): Integer;
  359. begin
  360. Result:=StrToInt(S);
  361. end;
  362. class function TStringHelper.ToSingle(const S: string): Single;
  363. begin
  364. Result:=StrToFloat(S);
  365. end;
  366. class function TStringHelper.UpperCase(const S: string): string;
  367. begin
  368. Result:=sysutils.Uppercase(S);
  369. end;
  370. function TStringHelper.CompareTo(const B: string): Integer;
  371. begin
  372. // Order is important
  373. Result:=sysUtils.StrComp(PChar(Self),PChar(B));
  374. end;
  375. procedure TStringHelper.CopyTo(SourceIndex: SizeInt; var destination: array of Char; DestinationIndex: SizeInt; ACount: SizeInt);
  376. Var
  377. P1,P2 : PChar;
  378. begin
  379. // Writeln('((',DestinationIndex,'+',ACount,')<',System.Length(Destination),') : ', ((DestinationIndex+ACount)<System.Length(Destination)));
  380. if ((DestinationIndex+ACount)<=System.Length(Destination)) then
  381. begin
  382. // Writeln('AHA');
  383. P1:=@Self[SourceIndex+1];
  384. P2:=@Destination[DestinationIndex];
  385. Move(P1^,P2^,ACount*SizeOf(Char));
  386. end;
  387. end;
  388. function TStringHelper.Contains(const AValue: string; IgnoreCase: Boolean): Boolean;
  389. begin
  390. if IgnoreCase then
  391. Result:=Pos(LowerCase(AValue),LowerCase(Self))>0
  392. else
  393. Result:=Pos(AValue,Self)>0;
  394. end;
  395. function TStringHelper.CountChar(const C: Char): SizeInt;
  396. Var
  397. S : Char;
  398. begin
  399. Result:=0;
  400. For S in Self do
  401. if (S=C) then
  402. Inc(Result);
  403. end;
  404. function TStringHelper.DeQuotedString: string;
  405. begin
  406. Result:=DeQuotedString('''');
  407. end;
  408. function TStringHelper.DeQuotedString(const AQuoteChar: Char): string;
  409. var
  410. L,I : SizeInt;
  411. Res : Array of Char;
  412. PS,PD : PChar;
  413. IsQuote : Boolean;
  414. begin
  415. L:=System.Length(Self);
  416. if (L<2) or Not ((Self[1]=AQuoteChar) and (Self[L]=AQuoteChar)) then
  417. Exit(Self);
  418. SetLength(Res,L);
  419. IsQuote:=False;
  420. PS:=@Self[2];
  421. PD:=@Res[0];
  422. For I:=2 to L-1 do
  423. begin
  424. if (PS^=AQuoteChar) then
  425. begin
  426. IsQuote:=Not IsQuote;
  427. if Not IsQuote then
  428. begin
  429. PD^:=PS^;
  430. Inc(PD);
  431. end;
  432. end
  433. else
  434. begin
  435. if IsQuote then
  436. IsQuote:=false;
  437. PD^:=PS^;
  438. Inc(PD);
  439. end;
  440. Inc(PS);
  441. end;
  442. SetString(Result,@Res[0],PD-@Res[0]);
  443. end;
  444. function TStringHelper.EndsWith(const AValue: string): Boolean;
  445. begin
  446. Result:=EndsWith(AValue,False);
  447. end;
  448. function TStringHelper.EndsWith(const AValue: string; IgnoreCase: Boolean): Boolean;
  449. Var
  450. L,NS : SizeInt;
  451. begin
  452. L:=system.Length(AVAlue);
  453. NS:=System.Length(Self);
  454. Result:=L<=NS;
  455. if Result then
  456. if IgnoreCase then
  457. Result:=SameText(System.Copy(Self,NS-L+1,L),AValue)
  458. else
  459. Result:=CompareChar(PChar(Pointer(Self))[NS-L],PChar(Pointer(AValue))^,L)=0;
  460. end;
  461. function TStringHelper.Equals(const AValue: string; IgnoreCase: Boolean = False): Boolean;
  462. begin
  463. if IgnoreCase then
  464. Result:=SameText(Self,aValue)
  465. else
  466. Result:=(Self=AValue);
  467. end;
  468. function TStringHelper.Format(const args: array of const): string;
  469. begin
  470. Result:=Format(Self,Args);
  471. end;
  472. function TStringHelper.GetHashCode: Integer;
  473. // Taken from contnrs, fphash
  474. var
  475. P,pmax : PChar;
  476. begin
  477. {$push}
  478. {$Q-}
  479. Result:=0;
  480. P:=Pchar(Self);
  481. pmax:=p+length;
  482. while (p<pmax) do
  483. begin
  484. Result:=LongWord(LongInt(Result shl 5) - LongInt(Result)) xor LongWord(P^);
  485. Inc(p);
  486. end;
  487. {$pop}
  488. end;
  489. function TStringHelper.IndexOf(AValue: Char): SizeInt;
  490. begin
  491. Result:=IndexOf(AValue,0,Length);
  492. end;
  493. function TStringHelper.IndexOf(const AValue: string): SizeInt;
  494. begin
  495. Result:=IndexOf(AValue,0,Length);
  496. end;
  497. function TStringHelper.IndexOf(AValue: Char; StartIndex: SizeInt): SizeInt;
  498. begin
  499. Result:=IndexOf(AValue,StartIndex,Length);
  500. end;
  501. function TStringHelper.IndexOf(const AValue: string; StartIndex: SizeInt
  502. ): SizeInt;
  503. begin
  504. Result:=IndexOf(AValue,StartIndex,Length);
  505. end;
  506. function TStringHelper.IndexOf(AValue: Char; StartIndex: SizeInt;
  507. ACount: SizeInt): SizeInt;
  508. Var
  509. CountLim : SizeInt;
  510. begin
  511. if StartIndex<0 then
  512. StartIndex:=0;
  513. CountLim:=System.Length(Self)-StartIndex;
  514. if ACount>CountLim then
  515. ACount:=CountLim;
  516. if ACount<=0 then
  517. Exit(-1);
  518. // pointer casts are to access self as 0 based index!
  519. Result:=IndexChar(PChar(Pointer(self))[StartIndex],ACount,AValue);
  520. if Result>=0 then
  521. Result:=Result+StartIndex;
  522. end;
  523. function TStringHelper.IndexOf(const AValue: string; StartIndex: SizeInt;
  524. ACount: SizeInt): SizeInt;
  525. Var
  526. CountLim,NV,Ofs : SizeInt;
  527. SP,SE : PChar;
  528. begin
  529. if StartIndex<0 then
  530. StartIndex:=0;
  531. CountLim:=System.Length(Self)-StartIndex;
  532. if ACount>CountLim then
  533. ACount:=CountLim;
  534. NV:=System.Length(AValue);
  535. if (NV>0) and (ACount>=NV) then
  536. begin
  537. SP:=PChar(Pointer(Self))+StartIndex;
  538. SE:=SP+ACount-NV+1;
  539. repeat
  540. Ofs:=IndexChar(SP^,SE-SP,PChar(Pointer(AValue))[0]);
  541. if Ofs<0 then
  542. Break;
  543. SP:=SP+Ofs+1;
  544. if CompareChar(SP^,PChar(Pointer(AValue))[1],NV-1)=0 then
  545. Exit(SP-PChar(Pointer(Self))-1);
  546. until false;
  547. end;
  548. Result:=-1;
  549. end;
  550. function TStringHelper.IndexOfUnQuoted(const AValue: string; StartQuote,
  551. EndQuote: Char; StartIndex: SizeInt = 0): SizeInt;
  552. Var
  553. LV : SizeInt;
  554. Function MatchAt(I : SizeInt) : Boolean ; Inline;
  555. Var
  556. J : SizeInt;
  557. begin
  558. J:=1;
  559. Repeat
  560. Result:=(Self[I+J-1]=AValue[j]);
  561. Inc(J);
  562. Until (Not Result) or (J>LV);
  563. end;
  564. Var
  565. I,L,Q: SizeInt;
  566. begin
  567. Result:=-1;
  568. LV:=system.Length(AValue);
  569. L:=Length-LV+1;
  570. if L<0 then
  571. L:=0;
  572. I:=StartIndex+1;
  573. Q:=0;
  574. if StartQuote=EndQuote then
  575. begin
  576. While (Result=-1) and (I<=L) do
  577. begin
  578. if (Self[I]=StartQuote) then
  579. Q:=1-Q;
  580. if (Q=0) and MatchAt(i) then
  581. Result:=I-1;
  582. Inc(I);
  583. end;
  584. end
  585. else
  586. begin
  587. While (Result=-1) and (I<=L) do
  588. begin
  589. if Self[I]=StartQuote then
  590. Inc(Q)
  591. else if (Self[I]=EndQuote) and (Q>0) then
  592. Dec(Q);
  593. if (Q=0) and MatchAt(i) then
  594. Result:=I-1;
  595. Inc(I);
  596. end;
  597. end;
  598. end;
  599. function TStringHelper.IndexOfAny(const AnyOf: array of Char): SizeInt;
  600. begin
  601. Result:=IndexOfAny(AnyOf,0,Length);
  602. end;
  603. function TStringHelper.IndexOfAny(const AnyOf: array of Char;
  604. StartIndex: SizeInt): SizeInt;
  605. begin
  606. Result:=IndexOfAny(AnyOf,StartIndex,Length);
  607. end;
  608. function TStringHelper.IndexOfAny(const AnyOf: array of Char;
  609. StartIndex: SizeInt; ACount: SizeInt): SizeInt;
  610. Var
  611. i,L : SizeInt;
  612. begin
  613. I:=StartIndex+1;
  614. L:=I+ACount-1;
  615. If L>Length then
  616. L:=Length;
  617. Result:=-1;
  618. While (Result=-1) and (I<=L) do
  619. begin
  620. if HaveChar(Self[i],AnyOf) then
  621. Result:=I-1;
  622. Inc(I);
  623. end;
  624. end;
  625. function TStringHelper.IndexOfAny(const AnyOf: array of String): SizeInt;
  626. begin
  627. Result:=IndexOfAny(AnyOf,0,Length);
  628. end;
  629. function TStringHelper.IndexOfAny(const AnyOf: array of String;
  630. StartIndex: SizeInt): SizeInt;
  631. begin
  632. Result:=IndexOfAny(AnyOf,StartIndex,Length-StartIndex);
  633. end;
  634. function TStringHelper.IndexOfAny(const AnyOf: array of String;
  635. StartIndex: SizeInt; ACount: SizeInt): SizeInt;
  636. Var
  637. M : SizeInt;
  638. begin
  639. Result:=IndexOfAny(AnyOf,StartIndex,ACount,M);
  640. end;
  641. function TStringHelper.IndexOfAny(const AnyOf: array of String;
  642. StartIndex: SizeInt; ACount: SizeInt; out AMatch: SizeInt): SizeInt;
  643. Var
  644. L,I : SizeInt;
  645. begin
  646. Result:=-1;
  647. For I:=0 to System.Length(AnyOf)-1 do
  648. begin
  649. L:=IndexOf(AnyOf[i],StartIndex,ACount);
  650. If (L>=0) and ((Result=-1) or (L<Result)) then
  651. begin
  652. Result:=L;
  653. AMatch:=I;
  654. end;
  655. end;
  656. end;
  657. function TStringHelper.IndexOfAnyUnquoted(const AnyOf: array of Char;
  658. StartQuote, EndQuote: Char): SizeInt;
  659. begin
  660. Result:=IndexOfAnyUnquoted(AnyOf,StartQuote,EndQuote,0,Length);
  661. end;
  662. function TStringHelper.IndexOfAnyUnquoted(const AnyOf: array of Char;
  663. StartQuote, EndQuote: Char; StartIndex: SizeInt): SizeInt;
  664. begin
  665. Result:=IndexOfAnyUnquoted(AnyOf,StartQuote,EndQuote,StartIndex,Length);
  666. end;
  667. function TStringHelper.IndexOfAnyUnquoted(const AnyOf: array of Char;
  668. StartQuote, EndQuote: Char; StartIndex: SizeInt; ACount: SizeInt): SizeInt;
  669. Var
  670. I,L : SizeInt;
  671. Q : SizeInt;
  672. begin
  673. Result:=-1;
  674. L:=StartIndex+ACount-1;
  675. if L>Length then
  676. L:=Length;
  677. I:=StartIndex+1;
  678. Q:=0;
  679. if StartQuote=EndQuote then
  680. begin
  681. While (Result=-1) and (I<=L) do
  682. begin
  683. if (Self[I]=StartQuote) then
  684. Q:=1-Q;
  685. if (Q=0) and HaveChar(Self[i],AnyOf) then
  686. Result:=I-1;
  687. Inc(I);
  688. end;
  689. end
  690. else
  691. begin
  692. While (Result=-1) and (I<=L) do
  693. begin
  694. if Self[I]=StartQuote then
  695. Inc(Q)
  696. else if (Self[I]=EndQuote) and (Q>0) then
  697. Dec(Q);
  698. if (Q=0) and HaveChar(Self[i],AnyOf) then
  699. Result:=I-1;
  700. Inc(I);
  701. end;
  702. end;
  703. end;
  704. function TStringHelper.IndexOfAnyUnquoted(const AnyOf: array of string;
  705. StartQuote, EndQuote: Char; StartIndex: SizeInt; out Matched: SizeInt
  706. ): SizeInt;
  707. Var
  708. L,I : SizeInt;
  709. begin
  710. Result:=-1;
  711. For I:=0 to System.Length(AnyOf)-1 do
  712. begin
  713. L:=IndexOfUnquoted(AnyOf[i],StartQuote,EndQuote,StartIndex);
  714. If (L>=0) and ((Result=-1) or (L<Result)) then
  715. begin
  716. Result:=L;
  717. Matched:=I;
  718. end;
  719. end;
  720. end;
  721. function TStringHelper.Insert(StartIndex: SizeInt; const AValue: string
  722. ): string;
  723. begin
  724. system.Insert(AValue,Self,StartIndex+1);
  725. Result:=Self;
  726. end;
  727. function TStringHelper.IsDelimiter(const Delimiters: string; Index: SizeInt
  728. ): Boolean;
  729. begin
  730. Result:=sysutils.IsDelimiter(Delimiters,Self,Index+1);
  731. end;
  732. function TStringHelper.IsEmpty: Boolean;
  733. begin
  734. Result:=(Length=0)
  735. end;
  736. function TStringHelper.LastDelimiter(const Delims: string): SizeInt;
  737. begin
  738. Result:=sysutils.LastDelimiter(Delims,Self)-1;
  739. end;
  740. function TStringHelper.LastIndexOf(AValue: Char): SizeInt;
  741. begin
  742. Result:=LastIndexOf(AValue,Length-1,Length);
  743. end;
  744. function TStringHelper.LastIndexOf(const AValue: string): SizeInt;
  745. begin
  746. Result:=LastIndexOf(AValue,Length-1,Length);
  747. end;
  748. function TStringHelper.LastIndexOf(AValue: Char; AStartIndex: SizeInt): SizeInt;
  749. begin
  750. Result:=LastIndexOf(AValue,AStartIndex,Length);
  751. end;
  752. function TStringHelper.LastIndexOf(const AValue: string; AStartIndex: SizeInt
  753. ): SizeInt;
  754. begin
  755. Result:=LastIndexOf(AValue,AStartIndex,Length);
  756. end;
  757. function TStringHelper.LastIndexOf(AValue: Char; AStartIndex: SizeInt;
  758. ACount: SizeInt): SizeInt;
  759. Var
  760. Min : SizeInt;
  761. begin
  762. Result:=AStartIndex+1;
  763. Min:=Result-ACount+1;
  764. If Min<1 then
  765. Min:=1;
  766. While (Result>=Min) and (Self[Result]<>AValue) do
  767. Dec(Result);
  768. if Result<Min then
  769. Result:=-1
  770. else
  771. Result:=Result-1;
  772. end;
  773. function TStringHelper.LastIndexOf(const AValue: string; AStartIndex: SizeInt; ACount: SizeInt): SizeInt;
  774. var
  775. I,L,LS,M : SizeInt;
  776. S : String;
  777. P : PChar;
  778. begin
  779. Result:=-1;
  780. LS:=system.Length(Self);
  781. L:=system.Length(AValue);
  782. if (L=0) or (L>LS) then
  783. Exit;
  784. P:=PChar(AValue);
  785. S:=Self;
  786. I:=AStartIndex+1; // 1 based
  787. if (I>LS) then
  788. I:=LS;
  789. I:=I-L+1;
  790. M:=AStartIndex-ACount+2; // 1 based
  791. if M<1 then
  792. M:=1;
  793. while (Result=-1) and (I>=M) do
  794. begin
  795. if (0=StrLComp(PChar(@S[I]),P,L)) then
  796. Result:=I-1;
  797. Dec(I);
  798. end;
  799. end;
  800. function TStringHelper.LastIndexOfAny(const AnyOf: array of Char): SizeInt;
  801. begin
  802. Result:=LastIndexOfAny(AnyOf,Length-1,Length);
  803. end;
  804. function TStringHelper.LastIndexOfAny(const AnyOf: array of Char;
  805. AStartIndex: SizeInt): SizeInt;
  806. begin
  807. Result:=LastIndexOfAny(AnyOf,AStartIndex,Length);
  808. end;
  809. function TStringHelper.LastIndexOfAny(const AnyOf: array of Char;
  810. AStartIndex: SizeInt; ACount: SizeInt): SizeInt;
  811. Var
  812. Min : SizeInt;
  813. begin
  814. Result:=AStartIndex+1;
  815. Min:=Result-ACount+1;
  816. If Min<1 then
  817. Min:=1;
  818. While (Result>=Min) and Not HaveChar(Self[Result],AnyOf) do
  819. Dec(Result);
  820. if Result<Min then
  821. Result:=-1
  822. else
  823. Result:=Result-1;
  824. end;
  825. function TStringHelper.PadLeft(ATotalWidth: SizeInt): string;
  826. begin
  827. Result:=PadLeft(ATotalWidth,' ');
  828. end;
  829. function TStringHelper.PadLeft(ATotalWidth: SizeInt; PaddingChar: Char): string;
  830. Var
  831. L : SizeInt;
  832. begin
  833. Result:=Self;
  834. L:=ATotalWidth-Length;
  835. If L>0 then
  836. Result:=StringOfChar(PaddingChar,L)+Result;
  837. end;
  838. function TStringHelper.PadRight(ATotalWidth: SizeInt): string;
  839. begin
  840. Result:=PadRight(ATotalWidth,' ');
  841. end;
  842. function TStringHelper.PadRight(ATotalWidth: SizeInt; PaddingChar: Char
  843. ): string;
  844. Var
  845. L : SizeInt;
  846. begin
  847. Result:=Self;
  848. L:=ATotalWidth-Length;
  849. If L>0 then
  850. Result:=Result+StringOfChar(PaddingChar,L);
  851. end;
  852. function TStringHelper.QuotedString: string;
  853. begin
  854. Result:=QuotedStr(Self);
  855. end;
  856. function TStringHelper.QuotedString(const AQuoteChar: Char): string;
  857. begin
  858. Result:=AnsiQuotedStr(Self,AQuoteChar);
  859. end;
  860. function TStringHelper.Remove(StartIndex: SizeInt): string;
  861. begin
  862. Result:=Remove(StartIndex,Self.Length-StartIndex);
  863. end;
  864. function TStringHelper.Remove(StartIndex: SizeInt; ACount: SizeInt): string;
  865. begin
  866. Result:=Self;
  867. System.Delete(Result,StartIndex+1,ACount);
  868. end;
  869. function TStringHelper.Replace(OldChar: Char; NewChar: Char): string;
  870. begin
  871. Result:=Replace(OldChar,NewChar,[rfReplaceAll]);
  872. end;
  873. function TStringHelper.Replace(OldChar: Char; NewChar: Char;
  874. ReplaceFlags: TReplaceFlags): string;
  875. var
  876. Sp,Se,Rp : PChar;
  877. Ofs : SizeInt;
  878. begin
  879. if rfIgnoreCase in ReplaceFlags then
  880. exit(StringReplace(Self,OldChar,NewChar,ReplaceFlags));
  881. Sp:=PChar(Pointer(Self));
  882. Se:=Sp+System.Length(Self);
  883. Ofs:=IndexChar(Sp^,Se-Sp,OldChar);
  884. if Ofs<0 then
  885. exit(Self);
  886. SetLength(Result,Se-Sp);
  887. Rp:=PChar(Pointer(Result));
  888. repeat
  889. Move(Sp^,Rp^,Ofs*sizeof(Char));
  890. Sp:=Sp+Ofs+1;
  891. Rp[Ofs]:=NewChar;
  892. Rp:=Rp+Ofs+1;
  893. if not (rfReplaceAll in ReplaceFlags) then
  894. break;
  895. { This loop can be removed entirely, but greatly speeds up replacing streaks of characters. }
  896. while (Sp<Se) and (Sp^=OldChar) do
  897. begin
  898. Rp^:=NewChar;
  899. Sp:=Sp+1;
  900. Rp:=Rp+1;
  901. end;
  902. Ofs:=IndexChar(Sp^,Se-Sp,OldChar);
  903. until Ofs<0;
  904. Move(Sp^,Rp^,(Se-Sp)*sizeof(Char));
  905. end;
  906. function TStringHelper.Replace(const OldValue: string; const NewValue: string
  907. ): string;
  908. begin
  909. Result:=Replace(OldValue,NewValue,[rfReplaceAll]);
  910. end;
  911. function TStringHelper.Replace(const OldValue: string; const NewValue: string;
  912. ReplaceFlags: TReplaceFlags): string;
  913. begin
  914. Result:=StringReplace(Self,OldValue,NewValue,ReplaceFlags);
  915. end;
  916. function TStringHelper.Split(const Separators: array of Char): TStringArray;
  917. begin
  918. Result:=Split(Separators,#0,#0,Length+1,TStringSplitOptions.None);
  919. end;
  920. function TStringHelper.Split(const Separators: array of Char; ACount: SizeInt
  921. ): TStringArray;
  922. begin
  923. Result:=Split(Separators,#0,#0,ACount,TStringSplitOptions.None);
  924. end;
  925. function TStringHelper.Split(const Separators: array of Char;
  926. Options: TStringSplitOptions): TStringArray;
  927. begin
  928. Result:=Split(Separators,Length+1,Options);
  929. end;
  930. function TStringHelper.Split(const Separators: array of Char; ACount: SizeInt;
  931. Options: TStringSplitOptions): TStringArray;
  932. begin
  933. Result:=Split(Separators,#0,#0,ACount,Options);
  934. end;
  935. function TStringHelper.Split(const Separators: array of string): TStringArray;
  936. begin
  937. Result:=Split(Separators,Length+1);
  938. end;
  939. function TStringHelper.Split(const Separators: array of string; ACount: SizeInt
  940. ): TStringArray;
  941. begin
  942. Result:=Split(Separators,ACount,TStringSplitOptions.None);
  943. end;
  944. function TStringHelper.Split(const Separators: array of string;
  945. Options: TStringSplitOptions): TStringArray;
  946. begin
  947. Result:=Split(Separators,Length+1,Options);
  948. end;
  949. function TStringHelper.Split(const Separators: array of string;
  950. ACount: SizeInt; Options: TStringSplitOptions): TStringArray;
  951. begin
  952. Result:=Split(Separators,#0,#0,ACount,Options);
  953. end;
  954. function TStringHelper.Split(const Separators: array of Char; AQuote: Char
  955. ): TStringArray;
  956. begin
  957. Result:=Split(Separators,AQuote,AQuote);
  958. end;
  959. function TStringHelper.Split(const Separators: array of Char; AQuoteStart,
  960. AQuoteEnd: Char): TStringArray;
  961. begin
  962. Result:=Split(Separators,AQuoteStart,AQuoteEnd,TStringSplitOptions.None);
  963. end;
  964. function TStringHelper.Split(const Separators: array of Char; AQuoteStart,
  965. AQuoteEnd: Char; Options: TStringSplitOptions): TStringArray;
  966. begin
  967. Result:=Split(Separators,AQuoteStart,AQuoteEnd,Length+1,Options);
  968. end;
  969. function TStringHelper.Split(const Separators: array of Char; AQuoteStart,
  970. AQuoteEnd: Char; ACount: SizeInt): TStringArray;
  971. begin
  972. Result:=Split(Separators,AQuoteStart,AQuoteEnd,ACount,TStringSplitOptions.None);
  973. end;
  974. function TStringHelper.Split(const Separators: array of Char; AQuoteStart,
  975. AQuoteEnd: Char; ACount: SizeInt; Options: TStringSplitOptions): TStringArray;
  976. Function NextSep(StartIndex : SizeInt) : SizeInt;
  977. begin
  978. if (AQuoteStart<>#0) then
  979. Result:=Self.IndexOfAnyUnQuoted(Separators,AQuoteStart,AQuoteEnd,StartIndex)
  980. else
  981. Result:=Self.IndexOfAny(Separators,StartIndex);
  982. end;
  983. Procedure MaybeGrow(Curlen : SizeInt);
  984. begin
  985. if System.Length(Result)<=CurLen then
  986. SetLength(Result,System.Length(Result)+4+SizeInt(SizeUint(System.Length(Result)) div 4));
  987. end;
  988. Var
  989. Sep,LastSep,Len : SizeInt;
  990. begin
  991. Result:=nil;
  992. Len:=0;
  993. LastSep:=0;
  994. While ((ACount=0) or (Len<ACount)) and (LastSep<=System.Length(Self)) do
  995. begin
  996. Sep:=NextSep(LastSep);
  997. if Sep<0 then
  998. Sep:=System.Length(Self);
  999. // Writeln('Examining >',T,'< at pos ',LastSep,', till pos ',Sep);
  1000. If (Sep>LastSep) or (not (TStringSplitOptions.ExcludeEmpty=Options)) then
  1001. begin
  1002. MaybeGrow(Len);
  1003. Result[Len]:=SubString(LastSep,Sep-LastSep);
  1004. Inc(Len);
  1005. end;
  1006. LastSep:=Sep+1;
  1007. end;
  1008. if (TStringSplitOptions.ExcludeLastEmpty=Options) then
  1009. if (Len > 0) and (Result[Len-1] = '') then
  1010. dec(Len);
  1011. SetLength(Result,Len);
  1012. end;
  1013. function TStringHelper.Split(const Separators: array of string; AQuote: Char
  1014. ): TStringArray;
  1015. begin
  1016. Result:=SPlit(Separators,AQuote,AQuote);
  1017. end;
  1018. function TStringHelper.Split(const Separators: array of string; AQuoteStart,
  1019. AQuoteEnd: Char): TStringArray;
  1020. begin
  1021. Result:=SPlit(Separators,AQuoteStart,AQuoteEnd,Length+1,TStringSplitOptions.None);
  1022. end;
  1023. function TStringHelper.Split(const Separators: array of string; AQuoteStart,
  1024. AQuoteEnd: Char; Options: TStringSplitOptions): TStringArray;
  1025. begin
  1026. Result:=SPlit(Separators,AQuoteStart,AQuoteEnd,Length+1,Options);
  1027. end;
  1028. function TStringHelper.Split(const Separators: array of string; AQuoteStart,
  1029. AQuoteEnd: Char; ACount: SizeInt): TStringArray;
  1030. begin
  1031. Result:=SPlit(Separators,AQuoteStart,AQuoteEnd,ACount,TStringSplitOptions.None);
  1032. end;
  1033. function TStringHelper.Split(const Separators: array of string; AQuoteStart,
  1034. AQuoteEnd: Char; ACount: SizeInt; Options: TStringSplitOptions): TStringArray;
  1035. Const
  1036. BlockSize = 10;
  1037. Function NextSep(StartIndex : SizeInt; out Match : SizeInt) : SizeInt;
  1038. begin
  1039. if (AQuoteStart<>#0) then
  1040. Result:=Self.IndexOfAnyUnQuoted(Separators,AQuoteStart,AQuoteEnd,StartIndex,Match)
  1041. else
  1042. Result:=Self.IndexOfAny(Separators,StartIndex,Length,Match);
  1043. if Result<>-1 then
  1044. end;
  1045. Procedure MaybeGrow(Curlen : SizeInt);
  1046. begin
  1047. if System.Length(Result)<=CurLen then
  1048. SetLength(Result,System.Length(Result)+BlockSize);
  1049. end;
  1050. Var
  1051. Sep,LastSep,Len,Match : SizeInt;
  1052. T : String;
  1053. begin
  1054. SetLength(Result,BlockSize);
  1055. Len:=0;
  1056. LastSep:=0;
  1057. Sep:=NextSep(0,Match);
  1058. While (Sep<>-1) and ((ACount=0) or (Len<ACount)) do
  1059. begin
  1060. T:=SubString(LastSep,Sep-LastSep);
  1061. If (T<>'') or (not (TStringSplitOptions.ExcludeEmpty=Options)) then
  1062. begin
  1063. MaybeGrow(Len);
  1064. Result[Len]:=T;
  1065. Inc(Len);
  1066. end;
  1067. LastSep:=Sep+System.Length(Separators[Match]);
  1068. Sep:=NextSep(LastSep,Match);
  1069. end;
  1070. if (LastSep<=Length) and ((ACount=0) or (Len<ACount)) then
  1071. begin
  1072. T:=SubString(LastSep);
  1073. // Writeln('Examining >',T,'< at pos,',LastSep,' till pos ',Sep);
  1074. If (T<>'') or (not (TStringSplitOptions.ExcludeEmpty=Options)) then
  1075. begin
  1076. MaybeGrow(Len);
  1077. Result[Len]:=T;
  1078. Inc(Len);
  1079. end;
  1080. end;
  1081. If (TStringSplitOptions.ExcludeLastEmpty=Options) then
  1082. if (Len > 0) and (Result[Len-1] = '') then
  1083. dec(Len);
  1084. SetLength(Result,Len);
  1085. end;
  1086. function TStringHelper.StartsWith(const AValue: string): Boolean;
  1087. begin
  1088. Result:=StartsWith(AValue,False);
  1089. end;
  1090. function TStringHelper.StartsWith(const AValue: string; IgnoreCase: Boolean
  1091. ): Boolean;
  1092. Var
  1093. L : SizeInt;
  1094. begin
  1095. L:=System.Length(AValue);
  1096. Result:=L<=System.Length(Self);
  1097. if Result then
  1098. if IgnoreCase then
  1099. Result:=SameText(System.Copy(Self,1,L),AValue)
  1100. else
  1101. Result:=CompareChar(PChar(Pointer(Self))^,PChar(Pointer(AValue))^,L)=0;
  1102. end;
  1103. function TStringHelper.Substring(AStartIndex: SizeInt): string;
  1104. begin
  1105. Result:=Self.SubString(AStartIndex,Self.Length-AStartIndex);
  1106. end;
  1107. function TStringHelper.Substring(AStartIndex: SizeInt; ALen: SizeInt): string;
  1108. begin
  1109. Result:=system.Copy(Self,AStartIndex+1,ALen);
  1110. end;
  1111. function TStringHelper.ToBoolean: Boolean;
  1112. begin
  1113. Result:=StrToBool(Self);
  1114. end;
  1115. function TStringHelper.ToInteger: Integer;
  1116. begin
  1117. Result:=StrToInt(Self);
  1118. end;
  1119. function TStringHelper.ToInt64: Int64;
  1120. begin
  1121. Result:=StrToInt64(Self);
  1122. end;
  1123. function TStringHelper.ToSingle: Single;
  1124. begin
  1125. Result:=StrToFLoat(Self);
  1126. end;
  1127. function TStringHelper.ToDouble: Double;
  1128. begin
  1129. Result:=StrToFLoat(Self);
  1130. end;
  1131. function TStringHelper.ToExtended: Extended;
  1132. begin
  1133. Result:=StrToFLoat(Self);
  1134. end;
  1135. function TStringHelper.ToCharArray: TCharArray;
  1136. begin
  1137. Result:=ToCharArray(0,Self.Length);
  1138. end;
  1139. function TStringHelper.ToCharArray(AStartIndex: SizeInt; ALen: SizeInt
  1140. ): TCharArray;
  1141. Var
  1142. I : SizeInt;
  1143. begin
  1144. SetLength(Result,ALen);
  1145. For I:=0 to ALen-1 do
  1146. Result[I]:=Self[AStartIndex+I+1];
  1147. end;
  1148. function TStringHelper.ToLower: string;
  1149. begin
  1150. Result:=LowerCase(Self);
  1151. end;
  1152. function TStringHelper.ToLowerInvariant: string;
  1153. begin
  1154. Result:=LowerCase(Self);
  1155. end;
  1156. function TStringHelper.ToUpper: string;
  1157. begin
  1158. Result:=UpperCase(Self);
  1159. end;
  1160. function TStringHelper.ToUpperInvariant: string;
  1161. begin
  1162. Result:=UpperCase(Self);
  1163. end;
  1164. function TStringHelper.Trim: string;
  1165. begin
  1166. Result:=SysUtils.Trim(Self);
  1167. end;
  1168. function TStringHelper.TrimLeft: string;
  1169. begin
  1170. Result:=SysUtils.TrimLeft(Self);
  1171. end;
  1172. function TStringHelper.TrimRight: string;
  1173. begin
  1174. Result:=SysUtils.TrimRight(Self);
  1175. end;
  1176. function TStringHelper.Trim(const ATrimChars: array of Char): string;
  1177. begin
  1178. Result:=Self.TrimLeft(ATrimChars).TrimRight(ATrimChars);
  1179. end;
  1180. function TStringHelper.TrimLeft(const ATrimChars: array of Char): string;
  1181. Var
  1182. I,Len : SizeInt;
  1183. begin
  1184. I:=1;
  1185. Len:=Self.Length;
  1186. While (I<=Len) and HaveChar(Self[i],ATrimChars) do Inc(I);
  1187. if I=1 then
  1188. Result:=Self
  1189. else if I>Len then
  1190. Result:=''
  1191. else
  1192. Result:=system.Copy(Self,I,Len-I+1);
  1193. end;
  1194. function TStringHelper.TrimRight(const ATrimChars: array of Char): string;
  1195. Var
  1196. I,Len : SizeInt;
  1197. begin
  1198. Len:=Self.Length;
  1199. I:=Len;
  1200. While (I>=1) and HaveChar(Self[i],ATrimChars) do Dec(I);
  1201. if I<1 then
  1202. Result:=''
  1203. else if I=Len then
  1204. Result:=Self
  1205. else
  1206. Result:=system.Copy(Self,1,I);
  1207. end;
  1208. function TStringHelper.TrimEnd(const ATrimChars: array of Char): string;
  1209. begin
  1210. Result:=TrimRight(ATrimChars);
  1211. end;
  1212. function TStringHelper.TrimStart(const ATrimChars: array of Char): string;
  1213. begin
  1214. Result:=TrimLeft(ATrimChars);
  1215. end;
  1216. { ---------------------------------------------------------------------
  1217. TCurrencyHelper
  1218. ---------------------------------------------------------------------}
  1219. function TCurrencyHelper.GetMaxValue: Currency;
  1220. begin
  1221. Result:=MaxCurrency;
  1222. end;
  1223. function TCurrencyHelper.GetMinValue: Currency;
  1224. begin
  1225. Result:=MinCurrency;
  1226. end;
  1227. function TCurrencyHelper.Ceil: Int64;
  1228. begin
  1229. {$warning TCurrencyHelper.Ceil unimplemented!}
  1230. end;
  1231. function TCurrencyHelper.Floor: Int64;
  1232. begin
  1233. {$warning TCurrencyHelper.Floor unimplemented!}
  1234. end;
  1235. function TCurrencyHelper.Frac: Currency;
  1236. begin
  1237. Result:=System.Frac(Self);
  1238. end;
  1239. class function TCurrencyHelper.Parse(const S: string; const AFormatSettings: TFormatSettings): Currency;
  1240. begin
  1241. Result:=StrToCurr(S, AFormatSettings);
  1242. end;
  1243. class function TCurrencyHelper.Parse(const S: string): Currency;
  1244. begin
  1245. Result:=StrToCurr(S);
  1246. end;
  1247. class function TCurrencyHelper.Size: Integer;
  1248. begin
  1249. Result:=SizeOf(Currency);
  1250. end;
  1251. function TCurrencyHelper.ToString(const AFormatSettings: TFormatSettings): string;
  1252. begin
  1253. Result:=CurrToStr(Self, AFormatSettings);
  1254. end;
  1255. function TCurrencyHelper.ToString: string;
  1256. begin
  1257. Result:=CurrToStr(Self);
  1258. end;
  1259. class function TCurrencyHelper.ToString(const Value: Currency; const AFormatSettings: TFormatSettings): string;
  1260. begin
  1261. Result:=CurrToStr(Value, AFormatSettings);
  1262. end;
  1263. class function TCurrencyHelper.ToString(const Value: Currency): string;
  1264. begin
  1265. Result:=CurrToStr(Value);
  1266. end;
  1267. function TCurrencyHelper.Trunc: Int64;
  1268. begin
  1269. Result:=System.Trunc(Self);
  1270. end;
  1271. class function TCurrencyHelper.TryParse(const S: string; out Value: Currency; const AFormatSettings: TFormatSettings): Boolean;
  1272. begin
  1273. Result:=True;
  1274. try
  1275. Value:=StrToCurr(S, AFormatSettings);
  1276. except
  1277. on E: Exception do
  1278. Result:=False;
  1279. end;
  1280. end;
  1281. class function TCurrencyHelper.TryParse(const S: string; out Value: Currency): Boolean;
  1282. begin
  1283. Result:=True;
  1284. try
  1285. Value:=StrToCurr(S);
  1286. except
  1287. on E: Exception do
  1288. Result:=False;
  1289. end;
  1290. end;
  1291. { ---------------------------------------------------------------------
  1292. TSingleHelper
  1293. ---------------------------------------------------------------------}
  1294. {$MACRO ON}
  1295. {$IFDEF FPC_HAS_TYPE_SINGLE}
  1296. {$define TFLOATHELPER:=TSingleHelper}
  1297. {$define FLOATTYPE:=Single}
  1298. {$define TFloatRec:=TSingleRec}
  1299. {$i syshelpf.inc}
  1300. {$UNDEF TFloatRec}
  1301. {$ENDIF FPC_HAS_TYPE_SINGLE}
  1302. { ---------------------------------------------------------------------
  1303. TDoubleHelper
  1304. ---------------------------------------------------------------------}
  1305. {$IFDEF FPC_HAS_TYPE_DOUBLE}
  1306. {$define TFLOATHELPER:=TDoubleHelper}
  1307. {$define FLOATTYPE:=Double}
  1308. {$define TFloatRec:=TDoubleRec}
  1309. {$i syshelpf.inc}
  1310. {$UNDEF TFloatRec}
  1311. {$ENDIF FPC_HAS_TYPE_DOUBLE}
  1312. { ---------------------------------------------------------------------
  1313. TExtendedHelper
  1314. ---------------------------------------------------------------------}
  1315. {$ifdef FPC_HAS_TYPE_EXTENDED}
  1316. {$define TFLOATHELPER:=TExtendedHelper}
  1317. {$define FLOATTYPE:=Extended}
  1318. {$define TFloatRec:=TExtended80Rec}
  1319. {$i syshelpf.inc}
  1320. {$UNDEF TFloatRec}
  1321. {$ENDIF FPC_HAS_TYPE_EXTENDED}
  1322. { ---------------------------------------------------------------------
  1323. TByteHelper
  1324. ---------------------------------------------------------------------}
  1325. {$define TORDINALHELPER:=TByteHelper}
  1326. {$define TORDINALTYPE:=Byte}
  1327. {$define TORDINALBITINDEX:=TByteBitIndex}
  1328. {$define TORDINALNIBBLEINDEX:=TByteNibbleIndex}
  1329. {$define TORDINALOVERLAY:=TByteOverlay}
  1330. {$define TORDINALTYPESIZE1}
  1331. {$i syshelpo.inc}
  1332. {$undef TORDINALTYPESIZE1}
  1333. { ---------------------------------------------------------------------
  1334. TShortintHelper
  1335. ---------------------------------------------------------------------}
  1336. {$define TORDINALHELPER:=TShortIntHelper}
  1337. {$define TORDINALTYPE:=ShortInt}
  1338. {$define TORDINALBITINDEX:=TShortIntBitIndex}
  1339. {$define TORDINALNIBBLEINDEX:=TShortIntNibbleIndex}
  1340. {$define TORDINALOVERLAY:=TShortIntOverlay}
  1341. {$define TORDINALTYPESIZE1}
  1342. {$i syshelpo.inc}
  1343. {$undef TORDINALTYPESIZE1}
  1344. { ---------------------------------------------------------------------
  1345. TSmallintHelper
  1346. ---------------------------------------------------------------------}
  1347. {$define TORDINALHELPER:=TSmallIntHelper}
  1348. {$define TORDINALTYPE:=SmallInt}
  1349. {$define TORDINALBITINDEX:=TSmallIntBitIndex}
  1350. {$define TORDINALNIBBLEINDEX:=TSmallIntNibbleIndex}
  1351. {$define TORDINALBYTEINDEX:=TWordByteIndex}
  1352. {$define TORDINALOVERLAY:=TWordOverlay}
  1353. {$define TORDINALTYPESIZE2}
  1354. {$i syshelpo.inc}
  1355. {$undef TORDINALTYPESIZE2}
  1356. { ---------------------------------------------------------------------
  1357. TWordHelper
  1358. ---------------------------------------------------------------------}
  1359. {$define TORDINALHELPER:=TWordHelper}
  1360. {$define TORDINALTYPE:=Word}
  1361. {$define TORDINALBITINDEX:=TWordBitIndex}
  1362. {$define TORDINALNIBBLEINDEX:=TWordNibbleIndex}
  1363. {$define TORDINALBYTEINDEX:=TWordByteIndex}
  1364. {$define TORDINALOVERLAY:=TWordOverlay}
  1365. {$define TORDINALTYPESIZE2}
  1366. {$i syshelpo.inc}
  1367. {$undef TORDINALTYPESIZE2}
  1368. { ---------------------------------------------------------------------
  1369. TCardinalHelper
  1370. ---------------------------------------------------------------------}
  1371. {$define TORDINALHELPER:=TCardinalHelper}
  1372. {$define TORDINALTYPE:=Cardinal}
  1373. {$define TORDINALBITINDEX:=TCardinalBitIndex}
  1374. {$define TORDINALNIBBLEINDEX:=TCardinalNibbleIndex}
  1375. {$define TORDINALBYTEINDEX:=TCardinalByteIndex}
  1376. {$define TORDINALWORDINDEX:=TCardinalWordIndex}
  1377. {$define TORDINALOVERLAY:=TDwordOverlay}
  1378. {$define TORDINALTYPESIZE4}
  1379. {$i syshelpo.inc}
  1380. {$undef TORDINALTYPESIZE4}
  1381. { ---------------------------------------------------------------------
  1382. TIntegerHelper
  1383. ---------------------------------------------------------------------}
  1384. {$define TORDINALHELPER:=TIntegerHelper}
  1385. {$define TORDINALTYPE:=Integer}
  1386. {$define TORDINALBITINDEX:=TIntegerBitIndex}
  1387. {$define TORDINALNIBBLEINDEX:=TIntegerNibbleIndex}
  1388. {$define TORDINALBYTEINDEX:=TIntegerByteIndex}
  1389. {$define TORDINALWORDINDEX:=TIntegerWordIndex}
  1390. {$if sizeof(Integer)=2}
  1391. {$define TORDINALOVERLAY:=TWordOverlay}
  1392. {$define TORDINALTYPESIZE2}
  1393. {$elseif sizeof(Integer)=4}
  1394. {$define TORDINALOVERLAY:=TDwordOverlay}
  1395. {$define TORDINALTYPESIZE4}
  1396. {$else}
  1397. {$fatal Unsupported Integer type size}
  1398. {$endif}
  1399. {$i syshelpo.inc}
  1400. {$undef TORDINALTYPESIZE2}
  1401. {$undef TORDINALTYPESIZE4}
  1402. { ---------------------------------------------------------------------
  1403. TLongIntHelper
  1404. ---------------------------------------------------------------------}
  1405. {$define TORDINALHELPER:=TLongIntHelper}
  1406. {$define TORDINALTYPE:=LongInt}
  1407. {$define TORDINALBITINDEX:=TLongIntBitIndex}
  1408. {$define TORDINALNIBBLEINDEX:=TLongIntNibbleIndex}
  1409. {$define TORDINALBYTEINDEX:=TLongIntByteIndex}
  1410. {$define TORDINALWORDINDEX:=TLongIntWordIndex}
  1411. {$define TORDINALOVERLAY:=TDwordOverlay}
  1412. {$define TORDINALTYPESIZE4}
  1413. {$i syshelpo.inc}
  1414. {$undef TORDINALTYPESIZE4}
  1415. { ---------------------------------------------------------------------
  1416. TInt64Helper
  1417. ---------------------------------------------------------------------}
  1418. {$define TORDINALHELPER:=TInt64Helper}
  1419. {$define TORDINALTYPE:=Int64}
  1420. {$define TORDINALBITINDEX:=TInt64BitIndex}
  1421. {$define TORDINALNIBBLEINDEX:=TInt64NibbleIndex}
  1422. {$define TORDINALBYTEINDEX:=TInt64ByteIndex}
  1423. {$define TORDINALWORDINDEX:=TInt64WordIndex}
  1424. {$define TORDINALDWORDINDEX:=TInt64DWordIndex}
  1425. {$define TORDINALOVERLAY:=TQwordOverlay}
  1426. {$define TORDINALTYPESIZE8}
  1427. {$i syshelpo.inc}
  1428. {$undef TORDINALTYPESIZE8}
  1429. { ---------------------------------------------------------------------
  1430. TQWordHelper
  1431. ---------------------------------------------------------------------}
  1432. {$define TORDINALHELPER:=TQWordHelper}
  1433. {$define TORDINALTYPE:=QWord}
  1434. {$define TORDINALBITINDEX:=TQwordBitIndex}
  1435. {$define TORDINALNIBBLEINDEX:=TQwordNibbleIndex}
  1436. {$define TORDINALBYTEINDEX:=TQwordByteIndex}
  1437. {$define TORDINALWORDINDEX:=TQWordWordIndex}
  1438. {$define TORDINALDWORDINDEX:=TQWordDWordIndex}
  1439. {$define TORDINALOVERLAY:=TQwordOverlay}
  1440. {$define TORDINALTYPESIZE8}
  1441. {$i syshelpo.inc}
  1442. {$undef TORDINALTYPESIZE8}
  1443. { ---------------------------------------------------------------------
  1444. TNativeIntHelper
  1445. ---------------------------------------------------------------------}
  1446. {$define TORDINALHELPER:=TNativeIntHelper}
  1447. {$define TORDINALTYPE:=NativeInt}
  1448. {$define TORDINALBITINDEX:=TNativeIntBitIndex}
  1449. {$if sizeof(NativeInt)=2}
  1450. {$define TORDINALNIBBLEINDEX:=TSmallIntNibbleIndex}
  1451. {$define TORDINALBYTEINDEX:=TSmallIntByteIndex}
  1452. {$define TORDINALOVERLAY:=TSmallIntOverlay}
  1453. {$define TORDINALTYPESIZE2}
  1454. {$elseif sizeof(NativeInt)=4}
  1455. {$define TORDINALNIBBLEINDEX:=TLongIntNibbleIndex}
  1456. {$define TORDINALBYTEINDEX:=TLongIntByteIndex}
  1457. {$define TORDINALWORDINDEX:=TLongIntWordIndex}
  1458. {$define TORDINALOVERLAY:=TLongIntOverlay}
  1459. {$define TORDINALTYPESIZE4}
  1460. {$elseif sizeof(NativeInt)=8}
  1461. {$define TORDINALNIBBLEINDEX:=TInt64NibbleIndex}
  1462. {$define TORDINALBYTEINDEX:=TInt64ByteIndex}
  1463. {$define TORDINALWORDINDEX:=TInt64WordIndex}
  1464. {$define TORDINALDWORDINDEX:=TInt64DWordIndex}
  1465. {$define TORDINALOVERLAY:=TInt64Overlay}
  1466. {$define TORDINALTYPESIZE8}
  1467. {$else}
  1468. {$fatal Unsupported NativeInt type size}
  1469. {$endif}
  1470. {$i syshelpo.inc}
  1471. {$undef TORDINALTYPESIZE2}
  1472. {$undef TORDINALTYPESIZE4}
  1473. {$undef TORDINALTYPESIZE8}
  1474. { ---------------------------------------------------------------------
  1475. TNativeUIntHelper
  1476. ---------------------------------------------------------------------}
  1477. {$define TORDINALHELPER:=TNativeUIntHelper}
  1478. {$define TORDINALTYPE:=NativeUInt}
  1479. {$define TORDINALBITINDEX:=TNativeUIntBitIndex}
  1480. {$if sizeof(NativeUInt)=2}
  1481. {$define TORDINALNIBBLEINDEX:=TWordNibbleIndex}
  1482. {$define TORDINALBYTEINDEX:=TWordByteIndex}
  1483. {$define TORDINALOVERLAY:=TWordOverlay}
  1484. {$define TORDINALTYPESIZE2}
  1485. {$elseif sizeof(NativeUInt)=4}
  1486. {$define TORDINALNIBBLEINDEX:=TDwordNibbleIndex}
  1487. {$define TORDINALBYTEINDEX:=TDwordByteIndex}
  1488. {$define TORDINALWORDINDEX:=TDwordWordIndex}
  1489. {$define TORDINALOVERLAY:=TDwordOverlay}
  1490. {$define TORDINALTYPESIZE4}
  1491. {$elseif sizeof(NativeUInt)=8}
  1492. {$define TORDINALNIBBLEINDEX:=TQwordNibbleIndex}
  1493. {$define TORDINALBYTEINDEX:=TQwordByteIndex}
  1494. {$define TORDINALWORDINDEX:=TQwordWordIndex}
  1495. {$define TORDINALDWORDINDEX:=TQwordDWordIndex}
  1496. {$define TORDINALOVERLAY:=TQwordOverlay}
  1497. {$define TORDINALTYPESIZE8}
  1498. {$else}
  1499. {$fatal Unsupported NativeUInt type size}
  1500. {$endif}
  1501. {$i syshelpo.inc}
  1502. {$undef TORDINALTYPESIZE2}
  1503. {$undef TORDINALTYPESIZE4}
  1504. {$undef TORDINALTYPESIZE8}
  1505. { ---------------------------------------------------------------------
  1506. TBooleanHelper
  1507. ---------------------------------------------------------------------}
  1508. {$define TBOOLHELPER:=TBooleanHelper}
  1509. {$define TBOOLTYPE:=Boolean}
  1510. {$i syshelpb.inc}
  1511. { ---------------------------------------------------------------------
  1512. TBoolean8Helper
  1513. ---------------------------------------------------------------------}
  1514. {$define TBOOLHELPER:=TBoolean8Helper}
  1515. {$define TBOOLTYPE:=Boolean8}
  1516. {$i syshelpb.inc}
  1517. { ---------------------------------------------------------------------
  1518. TBoolean16Helper
  1519. ---------------------------------------------------------------------}
  1520. {$define TBOOLHELPER:=TBoolean16Helper}
  1521. {$define TBOOLTYPE:=Boolean16}
  1522. {$i syshelpb.inc}
  1523. { ---------------------------------------------------------------------
  1524. TBoolean32Helper
  1525. ---------------------------------------------------------------------}
  1526. {$define TBOOLHELPER:=TBoolean32Helper}
  1527. {$define TBOOLTYPE:=Boolean32}
  1528. {$i syshelpb.inc}
  1529. { ---------------------------------------------------------------------
  1530. TBoolean64Helper
  1531. ---------------------------------------------------------------------}
  1532. {$define TBOOLHELPER:=TBoolean64Helper}
  1533. {$define TBOOLTYPE:=Boolean64}
  1534. {$i syshelpb.inc}
  1535. { ---------------------------------------------------------------------
  1536. TByteBoolHelper
  1537. ---------------------------------------------------------------------}
  1538. {$define TBOOLHELPER:=TByteBoolHelper}
  1539. {$define TBOOLTYPE:=ByteBool}
  1540. {$i syshelpb.inc}
  1541. { ---------------------------------------------------------------------
  1542. TWordBoolHelper
  1543. ---------------------------------------------------------------------}
  1544. {$define TBOOLHELPER:=TWordBoolHelper}
  1545. {$define TBOOLTYPE:=WordBool}
  1546. {$i syshelpb.inc}
  1547. { ---------------------------------------------------------------------
  1548. TLongBoolHelper
  1549. ---------------------------------------------------------------------}
  1550. {$define TBOOLHELPER:=TLongBoolHelper}
  1551. {$define TBOOLTYPE:=LongBool}
  1552. {$i syshelpb.inc}
  1553. { ---------------------------------------------------------------------
  1554. TQWordBoolHelper
  1555. ---------------------------------------------------------------------}
  1556. {$define TBOOLHELPER:=TQWordBoolHelper}
  1557. {$define TBOOLTYPE:=QWordBool}
  1558. {$i syshelpb.inc}