syshelp.inc 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618
  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 : Integer;
  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: Integer): Char;
  119. begin
  120. Result:=Self[AIndex+1];
  121. end;
  122. function TStringHelper.GetLength: Integer;
  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: Integer;
  144. const B: string; IndexB: Integer; ALen: Integer): Integer;
  145. begin
  146. Result:=Compare(A,IndexA,B,IndexB,ALen,[]);
  147. end;
  148. class function TStringHelper.Compare(const A: string; IndexA: Integer;
  149. const B: string; IndexB: Integer; ALen: Integer; 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: Integer;
  158. const B: string; IndexB: Integer; ALen: Integer; Options: TCompareOptions
  159. ): Integer;
  160. Var
  161. l : Integer;
  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 : Integer;
  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: Integer;
  186. const B: string; IndexB: Integer; ALen: Integer): 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: Integer): 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: Integer; ALen: Integer): 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. begin
  234. Result:=system.Length(SysUtils.Trim(AValue))=0;
  235. end;
  236. class function TStringHelper.Join(const Separator: string;
  237. const Values: array of const): string;
  238. Var
  239. SValues : Array of string;
  240. I,L : Integer;
  241. S : String;
  242. P : ^TVarRec;
  243. begin
  244. L:=System.Length(Values);
  245. SetLength(SValues,L);
  246. Dec(L);
  247. for I:=0 to L do
  248. begin
  249. S:='';
  250. P:=@Values[I];
  251. Case P^.VType of
  252. vtInteger : S:=IntToStr(P^.VInteger);
  253. vtBoolean : S:=BoolToStr(P^.VBoolean, True);
  254. vtChar : S:=P^.VChar;
  255. vtPChar : S:= string(P^.VPChar);
  256. {$ifndef FPUNONE}
  257. vtExtended : S:=FloatToStr(P^.VExtended^);
  258. {$endif}
  259. vtObject : S:=TObject(P^.VObject).Classname;
  260. vtClass : S:=P^.VClass.Classname;
  261. vtCurrency : S:=CurrToStr(P^.VCurrency^);
  262. vtVariant : S:=(P^.VVariant^);
  263. vtInt64 : S:=IntToStr(PInt64(P^.VInt64)^);
  264. vtQword : S:=IntToStr(PQWord(P^.VQword)^);
  265. vtWideChar : S:=WideString(P^.VWideChar);
  266. vtPWideChar : S:=WideString(P^.VPWideChar);
  267. vtUnicodeString : S:=UnicodeString(P^.VUnicodeString);
  268. vtAnsiString : S:=Ansistring(P^.VAnsiString);
  269. else
  270. S:=Format('Unknown type: %d',[P^.VType]);
  271. end;
  272. SValues[I]:=S;
  273. end;
  274. Result:=Join(Separator,SValues);
  275. end;
  276. class function TStringHelper.Join(const Separator: string;
  277. const Values: array of string): string;
  278. begin
  279. Result:=Join(Separator,Values,0,System.Length(Values));
  280. end;
  281. class function TStringHelper.Join(const Separator: string;
  282. const Values: array of string; StartIndex: Integer; ACount: Integer): string;
  283. Var
  284. I,L,VLen : integer;
  285. begin
  286. VLen:=High(Values);
  287. If (ACount<0) or ((StartIndex>0) and (StartIndex>VLen)) then
  288. raise ERangeError.Create(SRangeError);
  289. If (ACount=0) or (VLen<0) then
  290. Result:=''
  291. else
  292. begin
  293. L:=StartIndex+ACount-1;
  294. if L>Vlen then
  295. L:=VLen;
  296. Result:=Values[StartIndex];
  297. For I:=StartIndex+1 to L do
  298. Result:=Result+Separator+Values[I];
  299. end;
  300. end;
  301. class function TStringHelper.LowerCase(const S: string): string;
  302. begin
  303. Result:=sysutils.Lowercase(S);
  304. end;
  305. class function TStringHelper.Parse(const AValue: Boolean): string;
  306. begin
  307. Result:=BoolToStr(AValue);
  308. end;
  309. class function TStringHelper.Parse(const AValue: Extended): string;
  310. begin
  311. Result:=FloatToStr(AValue);
  312. end;
  313. class function TStringHelper.Parse(const AValue: Int64): string;
  314. begin
  315. Result:=IntToStr(AValue);
  316. end;
  317. class function TStringHelper.Parse(const AValue: Integer): string;
  318. begin
  319. Result:=IntToStr(AValue);
  320. end;
  321. class function TStringHelper.ToBoolean(const S: string): Boolean;
  322. begin
  323. Result:=StrToBool(S);
  324. end;
  325. class function TStringHelper.ToDouble(const S: string): Double;
  326. begin
  327. Result:=StrToFloat(S);
  328. end;
  329. class function TStringHelper.ToExtended(const S: string): Extended;
  330. begin
  331. Result:=StrToFloat(S);
  332. end;
  333. class function TStringHelper.ToInt64(const S: string): Int64;
  334. begin
  335. Result:=StrToInt64(S);
  336. end;
  337. class function TStringHelper.ToInteger(const S: string): Integer;
  338. begin
  339. Result:=StrToInt(S);
  340. end;
  341. class function TStringHelper.ToSingle(const S: string): Single;
  342. begin
  343. Result:=StrToFloat(S);
  344. end;
  345. class function TStringHelper.UpperCase(const S: string): string;
  346. begin
  347. Result:=sysutils.Uppercase(S);
  348. end;
  349. function TStringHelper.CompareTo(const B: string): Integer;
  350. begin
  351. // Order is important
  352. Result:=sysUtils.StrComp(PChar(Self),PChar(B));
  353. end;
  354. procedure TStringHelper.CopyTo(SourceIndex: Integer; var destination: array of Char; DestinationIndex: Integer; ACount: Integer);
  355. Var
  356. P1,P2 : PChar;
  357. begin
  358. // Writeln('((',DestinationIndex,'+',ACount,')<',System.Length(Destination),') : ', ((DestinationIndex+ACount)<System.Length(Destination)));
  359. if ((DestinationIndex+ACount)<=System.Length(Destination)) then
  360. begin
  361. // Writeln('AHA');
  362. P1:=@Self[SourceIndex+1];
  363. P2:=@Destination[DestinationIndex];
  364. Move(P1^,P2^,ACount*SizeOf(Char));
  365. end;
  366. end;
  367. function TStringHelper.Contains(const AValue: string): Boolean;
  368. begin
  369. Result:=Pos(AValue,Self)>0;
  370. end;
  371. function TStringHelper.CountChar(const C: Char): Integer;
  372. Var
  373. S : Char;
  374. begin
  375. Result:=0;
  376. For S in Self do
  377. if (S=C) then
  378. Inc(Result);
  379. end;
  380. function TStringHelper.DeQuotedString: string;
  381. begin
  382. Result:=DeQuotedString('''');
  383. end;
  384. function TStringHelper.DeQuotedString(const AQuoteChar: Char): string;
  385. var
  386. L,I : Integer;
  387. Res : Array of Char;
  388. PS,PD : PChar;
  389. IsQuote : Boolean;
  390. begin
  391. L:=System.Length(Self);
  392. if (L<2) or Not ((Self[1]=AQuoteChar) and (Self[L]=AQuoteChar)) then
  393. Exit(Self);
  394. SetLength(Res,L);
  395. IsQuote:=False;
  396. PS:=@Self[2];
  397. PD:=@Res[0];
  398. For I:=2 to L-1 do
  399. begin
  400. if (PS^=AQuoteChar) then
  401. begin
  402. IsQuote:=Not IsQuote;
  403. if Not IsQuote then
  404. begin
  405. PD^:=PS^;
  406. Inc(PD);
  407. end;
  408. end
  409. else
  410. begin
  411. if IsQuote then
  412. IsQuote:=false;
  413. PD^:=PS^;
  414. Inc(PD);
  415. end;
  416. Inc(PS);
  417. end;
  418. SetString(Result,@Res[0],PD-@Res[0]);
  419. end;
  420. function TStringHelper.EndsWith(const AValue: string): Boolean;
  421. begin
  422. Result:=EndsWith(AValue,False);
  423. end;
  424. function TStringHelper.EndsWith(const AValue: string; IgnoreCase: Boolean): Boolean;
  425. Var
  426. L : integer;
  427. S : String;
  428. begin
  429. L:=system.Length(AVAlue);
  430. Result:=L>0;
  431. if Result then
  432. begin
  433. S:=system.Copy(Self,Length-L+1,L);
  434. Result:=system.Length(S)=L;
  435. if Result then
  436. if IgnoreCase then
  437. Result:=CompareText(S,AValue)=0
  438. else
  439. Result:=S=AValue;
  440. end;
  441. end;
  442. function TStringHelper.Equals(const AValue: string): Boolean;
  443. begin
  444. Result:=(Self=AValue);
  445. end;
  446. function TStringHelper.Format(const args: array of const): string;
  447. begin
  448. Result:=Format(Self,Args);
  449. end;
  450. function TStringHelper.GetHashCode: Integer;
  451. // Taken from contnrs, fphash
  452. var
  453. P,pmax : PChar;
  454. begin
  455. {$push}
  456. {$Q-}
  457. Result:=0;
  458. P:=Pchar(Self);
  459. pmax:=p+length;
  460. while (p<pmax) do
  461. begin
  462. Result:=LongWord(LongInt(Result shl 5) - LongInt(Result)) xor LongWord(P^);
  463. Inc(p);
  464. end;
  465. {$pop}
  466. end;
  467. function TStringHelper.IndexOf(AValue: Char): Integer;
  468. begin
  469. Result:=IndexOf(AValue,0,Length);
  470. end;
  471. function TStringHelper.IndexOf(const AValue: string): Integer;
  472. begin
  473. Result:=IndexOf(AValue,0,Length);
  474. end;
  475. function TStringHelper.IndexOf(AValue: Char; StartIndex: Integer): Integer;
  476. begin
  477. Result:=IndexOf(AValue,StartIndex,Length);
  478. end;
  479. function TStringHelper.IndexOf(const AValue: string; StartIndex: Integer
  480. ): Integer;
  481. begin
  482. Result:=IndexOf(AValue,StartIndex,Length);
  483. end;
  484. function TStringHelper.IndexOf(AValue: Char; StartIndex: Integer;
  485. ACount: Integer): Integer;
  486. Var
  487. S : String;
  488. begin
  489. S:=System.Copy(Self,StartIndex+1,ACount);
  490. Result:=Pos(AValue,S)-1;
  491. if Result<>-1 then
  492. Result:=Result+StartIndex;
  493. end;
  494. function TStringHelper.IndexOf(const AValue: string; StartIndex: Integer;
  495. ACount: Integer): Integer;
  496. Var
  497. S : String;
  498. begin
  499. S:=System.Copy(Self,StartIndex+1,ACount);
  500. Result:=Pos(AValue,S)-1;
  501. if Result<>-1 then
  502. Result:=Result+StartIndex;
  503. end;
  504. function TStringHelper.IndexOfUnQuoted(const AValue: string; StartQuote,
  505. EndQuote: Char; StartIndex: Integer = 0): Integer;
  506. Var
  507. LV : Integer;
  508. Function MatchAt(I : Integer) : Boolean ; Inline;
  509. Var
  510. J : integer;
  511. begin
  512. J:=1;
  513. Repeat
  514. Result:=(Self[I+J-1]=AValue[j]);
  515. Inc(J);
  516. Until (Not Result) or (J>LV);
  517. end;
  518. Var
  519. I,L: Integer;
  520. Q : Integer;
  521. begin
  522. Result:=-1;
  523. LV:=system.Length(AValue);
  524. L:=Length-LV+1;
  525. if L<0 then
  526. L:=0;
  527. I:=StartIndex+1;
  528. Q:=0;
  529. if StartQuote=EndQuote then
  530. begin
  531. While (Result=-1) and (I<=L) do
  532. begin
  533. if (Self[I]=StartQuote) then
  534. Q:=1-Q;
  535. if (Q=0) and MatchAt(i) then
  536. Result:=I-1;
  537. Inc(I);
  538. end;
  539. end
  540. else
  541. begin
  542. While (Result=-1) and (I<=L) do
  543. begin
  544. if Self[I]=StartQuote then
  545. Inc(Q)
  546. else if (Self[I]=EndQuote) and (Q>0) then
  547. Dec(Q);
  548. if (Q=0) and MatchAt(i) then
  549. Result:=I-1;
  550. Inc(I);
  551. end;
  552. end;
  553. end;
  554. function TStringHelper.IndexOfAny(const AnyOf: array of Char): Integer;
  555. begin
  556. Result:=IndexOfAny(AnyOf,0,Length);
  557. end;
  558. function TStringHelper.IndexOfAny(const AnyOf: array of Char;
  559. StartIndex: Integer): Integer;
  560. begin
  561. Result:=IndexOfAny(AnyOf,StartIndex,Length);
  562. end;
  563. function TStringHelper.IndexOfAny(const AnyOf: array of Char;
  564. StartIndex: Integer; ACount: Integer): Integer;
  565. Var
  566. i,L : Integer;
  567. begin
  568. I:=StartIndex+1;
  569. L:=I+ACount-1;
  570. If L>Length then
  571. L:=Length;
  572. Result:=-1;
  573. While (Result=-1) and (I<=L) do
  574. begin
  575. if HaveChar(Self[i],AnyOf) then
  576. Result:=I-1;
  577. Inc(I);
  578. end;
  579. end;
  580. function TStringHelper.IndexOfAny(const AnyOf: array of String): Integer;
  581. begin
  582. Result:=IndexOfAny(AnyOf,0,Length);
  583. end;
  584. function TStringHelper.IndexOfAny(const AnyOf: array of String;
  585. StartIndex: Integer): Integer;
  586. begin
  587. Result:=IndexOfAny(AnyOf,StartIndex,Length-StartIndex);
  588. end;
  589. function TStringHelper.IndexOfAny(const AnyOf: array of String;
  590. StartIndex: Integer; ACount: Integer): Integer;
  591. Var
  592. M : Integer;
  593. begin
  594. Result:=IndexOfAny(AnyOf,StartIndex,ACount,M);
  595. end;
  596. function TStringHelper.IndexOfAny(const AnyOf: array of String;
  597. StartIndex: Integer; ACount: Integer; out AMatch: Integer): Integer;
  598. Var
  599. L,I : Integer;
  600. begin
  601. Result:=-1;
  602. For I:=0 to System.Length(AnyOf)-1 do
  603. begin
  604. L:=IndexOf(AnyOf[i],StartIndex,ACount);
  605. If (L>=0) and ((Result=-1) or (L<Result)) then
  606. begin
  607. Result:=L;
  608. AMatch:=I;
  609. end;
  610. end;
  611. end;
  612. function TStringHelper.IndexOfAnyUnquoted(const AnyOf: array of Char;
  613. StartQuote, EndQuote: Char): Integer;
  614. begin
  615. Result:=IndexOfAnyUnquoted(AnyOf,StartQuote,EndQuote,0,Length);
  616. end;
  617. function TStringHelper.IndexOfAnyUnquoted(const AnyOf: array of Char;
  618. StartQuote, EndQuote: Char; StartIndex: Integer): Integer;
  619. begin
  620. Result:=IndexOfAnyUnquoted(AnyOf,StartQuote,EndQuote,StartIndex,Length);
  621. end;
  622. function TStringHelper.IndexOfAnyUnquoted(const AnyOf: array of Char;
  623. StartQuote, EndQuote: Char; StartIndex: Integer; ACount: Integer): Integer;
  624. Var
  625. I,L : Integer;
  626. Q : Integer;
  627. begin
  628. Result:=-1;
  629. L:=StartIndex+ACount-1;
  630. if L>Length then
  631. L:=Length;
  632. I:=StartIndex+1;
  633. Q:=0;
  634. if StartQuote=EndQuote then
  635. begin
  636. While (Result=-1) and (I<=L) do
  637. begin
  638. if (Self[I]=StartQuote) then
  639. Q:=1-Q;
  640. if (Q=0) and HaveChar(Self[i],AnyOf) then
  641. Result:=I-1;
  642. Inc(I);
  643. end;
  644. end
  645. else
  646. begin
  647. While (Result=-1) and (I<=L) do
  648. begin
  649. if Self[I]=StartQuote then
  650. Inc(Q)
  651. else if (Self[I]=EndQuote) and (Q>0) then
  652. Dec(Q);
  653. if (Q=0) and HaveChar(Self[i],AnyOf) then
  654. Result:=I-1;
  655. Inc(I);
  656. end;
  657. end;
  658. end;
  659. function TStringHelper.IndexOfAnyUnquoted(const AnyOf: array of string;
  660. StartQuote, EndQuote: Char; StartIndex: Integer; out Matched: Integer
  661. ): Integer;
  662. Var
  663. L,I : Integer;
  664. begin
  665. Result:=-1;
  666. For I:=0 to System.Length(AnyOf)-1 do
  667. begin
  668. L:=IndexOfUnquoted(AnyOf[i],StartQuote,EndQuote,StartIndex);
  669. If (L>=0) and ((Result=-1) or (L<Result)) then
  670. begin
  671. Result:=L;
  672. Matched:=I;
  673. end;
  674. end;
  675. end;
  676. function TStringHelper.Insert(StartIndex: Integer; const AValue: string
  677. ): string;
  678. begin
  679. system.Insert(AValue,Self,StartIndex+1);
  680. Result:=Self;
  681. end;
  682. function TStringHelper.IsDelimiter(const Delimiters: string; Index: Integer
  683. ): Boolean;
  684. begin
  685. Result:=sysutils.IsDelimiter(Delimiters,Self,Index+1);
  686. end;
  687. function TStringHelper.IsEmpty: Boolean;
  688. begin
  689. Result:=(Length=0)
  690. end;
  691. function TStringHelper.LastDelimiter(const Delims: string): Integer;
  692. begin
  693. Result:=sysutils.LastDelimiter(Delims,Self)-1;
  694. end;
  695. function TStringHelper.LastIndexOf(AValue: Char): Integer;
  696. begin
  697. Result:=LastIndexOf(AValue,Length-1,Length);
  698. end;
  699. function TStringHelper.LastIndexOf(const AValue: string): Integer;
  700. begin
  701. Result:=LastIndexOf(AValue,Length-1,Length);
  702. end;
  703. function TStringHelper.LastIndexOf(AValue: Char; AStartIndex: Integer): Integer;
  704. begin
  705. Result:=LastIndexOf(AValue,AStartIndex,Length);
  706. end;
  707. function TStringHelper.LastIndexOf(const AValue: string; AStartIndex: Integer
  708. ): Integer;
  709. begin
  710. Result:=LastIndexOf(AValue,AStartIndex,Length);
  711. end;
  712. function TStringHelper.LastIndexOf(AValue: Char; AStartIndex: Integer;
  713. ACount: Integer): Integer;
  714. Var
  715. Min : Integer;
  716. begin
  717. Result:=AStartIndex+1;
  718. Min:=Result-ACount+1;
  719. If Min<1 then
  720. Min:=1;
  721. While (Result>=Min) and (Self[Result]<>AValue) do
  722. Dec(Result);
  723. if Result<Min then
  724. Result:=-1
  725. else
  726. Result:=Result-1;
  727. end;
  728. function TStringHelper.LastIndexOf(const AValue: string; AStartIndex: Integer;
  729. ACount: Integer): Integer;
  730. begin
  731. Result:=LastIndexOf(AValue,AStartIndex,AStartIndex+1);
  732. end;
  733. function TStringHelper.LastIndexOfAny(const AnyOf: array of Char): Integer;
  734. begin
  735. Result:=LastIndexOfAny(AnyOf,Length-1,Length);
  736. end;
  737. function TStringHelper.LastIndexOfAny(const AnyOf: array of Char;
  738. AStartIndex: Integer): Integer;
  739. begin
  740. Result:=LastIndexOfAny(AnyOf,AStartIndex,Length);
  741. end;
  742. function TStringHelper.LastIndexOfAny(const AnyOf: array of Char;
  743. AStartIndex: Integer; ACount: Integer): Integer;
  744. Var
  745. Min : Integer;
  746. begin
  747. Result:=AStartIndex+1;
  748. Min:=Result-ACount+1;
  749. If Min<1 then
  750. Min:=1;
  751. While (Result>=Min) and Not HaveChar(Self[Result],AnyOf) do
  752. Dec(Result);
  753. if Result<Min then
  754. Result:=-1
  755. else
  756. Result:=Result-1;
  757. end;
  758. function TStringHelper.PadLeft(ATotalWidth: Integer): string;
  759. begin
  760. Result:=PadLeft(ATotalWidth,' ');
  761. end;
  762. function TStringHelper.PadLeft(ATotalWidth: Integer; PaddingChar: Char): string;
  763. Var
  764. L : Integer;
  765. begin
  766. Result:=Self;
  767. L:=ATotalWidth-Length;
  768. If L>0 then
  769. Result:=StringOfChar(PaddingChar,L)+Result;
  770. end;
  771. function TStringHelper.PadRight(ATotalWidth: Integer): string;
  772. begin
  773. Result:=PadRight(ATotalWidth,' ');
  774. end;
  775. function TStringHelper.PadRight(ATotalWidth: Integer; PaddingChar: Char
  776. ): string;
  777. Var
  778. L : Integer;
  779. begin
  780. Result:=Self;
  781. L:=ATotalWidth-Length;
  782. If L>0 then
  783. Result:=Result+StringOfChar(PaddingChar,L);
  784. end;
  785. function TStringHelper.QuotedString: string;
  786. begin
  787. Result:=QuotedStr(Self);
  788. end;
  789. function TStringHelper.QuotedString(const AQuoteChar: Char): string;
  790. begin
  791. Result:=AnsiQuotedStr(Self,AQuoteChar);
  792. end;
  793. function TStringHelper.Remove(StartIndex: Integer): string;
  794. begin
  795. Result:=Remove(StartIndex,Self.Length-StartIndex);
  796. end;
  797. function TStringHelper.Remove(StartIndex: Integer; ACount: Integer): string;
  798. begin
  799. Result:=Self;
  800. System.Delete(Result,StartIndex+1,ACount);
  801. end;
  802. function TStringHelper.Replace(OldChar: Char; NewChar: Char): string;
  803. begin
  804. Result:=Replace(OldChar,NewChar,[rfReplaceAll]);
  805. end;
  806. function TStringHelper.Replace(OldChar: Char; NewChar: Char;
  807. ReplaceFlags: TReplaceFlags): string;
  808. begin
  809. Result:=StringReplace(Self,OldChar,NewChar,ReplaceFlags);
  810. end;
  811. function TStringHelper.Replace(const OldValue: string; const NewValue: string
  812. ): string;
  813. begin
  814. Result:=Replace(OldValue,NewValue,[rfReplaceAll]);
  815. end;
  816. function TStringHelper.Replace(const OldValue: string; const NewValue: string;
  817. ReplaceFlags: TReplaceFlags): string;
  818. begin
  819. Result:=StringReplace(Self,OldValue,NewValue,ReplaceFlags);
  820. end;
  821. function TStringHelper.Split(const Separators: array of Char): TStringArray;
  822. begin
  823. Result:=SPlit(Separators,#0,#0,Length,TStringSplitOptions([]));
  824. end;
  825. function TStringHelper.Split(const Separators: array of Char; ACount: Integer
  826. ): TStringArray;
  827. begin
  828. Result:=SPlit(Separators,#0,#0,ACount,TStringSplitOptions([]));
  829. end;
  830. function TStringHelper.Split(const Separators: array of Char;
  831. Options: TStringSplitOptions): TStringArray;
  832. begin
  833. Result:=SPlit(Separators,Length,Options);
  834. end;
  835. function TStringHelper.Split(const Separators: array of Char; ACount: Integer;
  836. Options: TStringSplitOptions): TStringArray;
  837. begin
  838. Result:=SPlit(Separators,#0,#0,ACount,Options);
  839. end;
  840. function TStringHelper.Split(const Separators: array of string): TStringArray;
  841. begin
  842. Result:=Split(Separators,Length);
  843. end;
  844. function TStringHelper.Split(const Separators: array of string; ACount: Integer
  845. ): TStringArray;
  846. begin
  847. Result:=Split(Separators,ACount,TStringSplitOptions([]));
  848. end;
  849. function TStringHelper.Split(const Separators: array of string;
  850. Options: TStringSplitOptions): TStringArray;
  851. begin
  852. Result:=Split(Separators,Length,Options);
  853. end;
  854. function TStringHelper.Split(const Separators: array of string;
  855. ACount: Integer; Options: TStringSplitOptions): TStringArray;
  856. begin
  857. Result:=Split(Separators,#0,#0,ACount,Options);
  858. end;
  859. function TStringHelper.Split(const Separators: array of Char; AQuote: Char
  860. ): TStringArray;
  861. begin
  862. Result:=Split(Separators,AQuote,AQuote);
  863. end;
  864. function TStringHelper.Split(const Separators: array of Char; AQuoteStart,
  865. AQuoteEnd: Char): TStringArray;
  866. begin
  867. Result:=Split(Separators,AQuoteStart,AQuoteEnd,TStringSplitOptions([]));
  868. end;
  869. function TStringHelper.Split(const Separators: array of Char; AQuoteStart,
  870. AQuoteEnd: Char; Options: TStringSplitOptions): TStringArray;
  871. begin
  872. Result:=Split(Separators,AQuoteStart,AQuoteEnd,Length,Options);
  873. end;
  874. function TStringHelper.Split(const Separators: array of Char; AQuoteStart,
  875. AQuoteEnd: Char; ACount: Integer): TStringArray;
  876. begin
  877. Result:=Split(Separators,AQuoteStart,AQuoteEnd,ACount,TStringSplitOptions([]));
  878. end;
  879. function TStringHelper.Split(const Separators: array of Char; AQuoteStart,
  880. AQuoteEnd: Char; ACount: Integer; Options: TStringSplitOptions): TStringArray;
  881. Const
  882. BlockSize = 10;
  883. Function NextSep(StartIndex : integer) : Integer;
  884. begin
  885. if (AQuoteStart<>#0) then
  886. Result:=Self.IndexOfAnyUnQuoted(Separators,AQuoteStart,AQuoteEnd,StartIndex)
  887. else
  888. Result:=Self.IndexOfAny(Separators,StartIndex);
  889. end;
  890. Procedure MaybeGrow(Curlen : Integer);
  891. begin
  892. if System.Length(Result)<=CurLen then
  893. SetLength(Result,System.Length(Result)+BlockSize);
  894. end;
  895. Var
  896. Sep,LastSep,Len : integer;
  897. T : String;
  898. begin
  899. SetLength(Result,BlockSize);
  900. Len:=0;
  901. LastSep:=0;
  902. Sep:=NextSep(0);
  903. While (Sep<>-1) and ((ACount=0) or (Len<ACount)) do
  904. begin
  905. T:=SubString(LastSep,Sep-LastSep);
  906. // Writeln('Examining >',T,'< at pos,',LastSep,' till pos ',Sep);
  907. If (T<>'') or (not (ExcludeEmpty=Options)) then
  908. begin
  909. MaybeGrow(Len);
  910. Result[Len]:=T;
  911. Inc(Len);
  912. end;
  913. LastSep:=Sep+1;
  914. Sep:=NextSep(LastSep);
  915. end;
  916. if (LastSep<Length-1) and ((ACount=0) or (Len<ACount)) then
  917. begin
  918. T:=SubString(LastSep);
  919. // Writeln('Examining >',T,'< at pos,',LastSep,' till pos ',Sep);
  920. MaybeGrow(Len);
  921. Result[Len]:=T;
  922. Inc(Len);
  923. end;
  924. SetLength(Result,Len);
  925. end;
  926. function TStringHelper.Split(const Separators: array of string; AQuote: Char
  927. ): TStringArray;
  928. begin
  929. Result:=SPlit(Separators,AQuote,AQuote);
  930. end;
  931. function TStringHelper.Split(const Separators: array of string; AQuoteStart,
  932. AQuoteEnd: Char): TStringArray;
  933. begin
  934. Result:=SPlit(Separators,AQuoteStart,AQuoteEnd,Length,TStringSplitOptions([]));
  935. end;
  936. function TStringHelper.Split(const Separators: array of string; AQuoteStart,
  937. AQuoteEnd: Char; Options: TStringSplitOptions): TStringArray;
  938. begin
  939. Result:=SPlit(Separators,AQuoteStart,AQuoteEnd,Length,Options);
  940. end;
  941. function TStringHelper.Split(const Separators: array of string; AQuoteStart,
  942. AQuoteEnd: Char; ACount: Integer): TStringArray;
  943. begin
  944. Result:=SPlit(Separators,AQuoteStart,AQuoteEnd,ACount,TStringSplitOptions([]));
  945. end;
  946. function TStringHelper.Split(const Separators: array of string; AQuoteStart,
  947. AQuoteEnd: Char; ACount: Integer; Options: TStringSplitOptions): TStringArray;
  948. Const
  949. BlockSize = 10;
  950. Function NextSep(StartIndex : integer; out Match : Integer) : Integer;
  951. begin
  952. if (AQuoteStart<>#0) then
  953. Result:=Self.IndexOfAnyUnQuoted(Separators,AQuoteStart,AQuoteEnd,StartIndex,Match)
  954. else
  955. Result:=Self.IndexOfAny(Separators,StartIndex,Length,Match);
  956. if Result<>-1 then
  957. end;
  958. Procedure MaybeGrow(Curlen : Integer);
  959. begin
  960. if System.Length(Result)<=CurLen then
  961. SetLength(Result,System.Length(Result)+BlockSize);
  962. end;
  963. Var
  964. Sep,LastSep,Len,Match : integer;
  965. T : String;
  966. begin
  967. SetLength(Result,BlockSize);
  968. Len:=0;
  969. LastSep:=0;
  970. Sep:=NextSep(0,Match);
  971. While (Sep<>-1) and ((ACount=0) or (Len<ACount)) do
  972. begin
  973. T:=SubString(LastSep,Sep-LastSep);
  974. If (T<>'') or (not (ExcludeEmpty=Options)) then
  975. begin
  976. MaybeGrow(Len);
  977. Result[Len]:=T;
  978. Inc(Len);
  979. end;
  980. LastSep:=Sep+System.Length(Separators[Match]);
  981. Sep:=NextSep(LastSep,Match);
  982. end;
  983. if (LastSep<Length-1) and ((ACount=0) or (Len<ACount)) then
  984. begin
  985. T:=SubString(LastSep);
  986. // Writeln('Examining >',T,'< at pos,',LastSep,' till pos ',Sep);
  987. MaybeGrow(Len);
  988. Result[Len]:=T;
  989. Inc(Len);
  990. end;
  991. SetLength(Result,Len);
  992. end;
  993. function TStringHelper.StartsWith(const AValue: string): Boolean;
  994. begin
  995. Result:=StartsWith(AValue,False);
  996. end;
  997. function TStringHelper.StartsWith(const AValue: string; IgnoreCase: Boolean
  998. ): Boolean;
  999. Var
  1000. L : Integer;
  1001. begin
  1002. L:=System.Length(AValue);
  1003. Result:=L>0;
  1004. if Result then
  1005. if IgnoreCase then
  1006. Result:=StrLiComp(PChar(AValue),PChar(Self),L)=0
  1007. else
  1008. Result:=StrLComp(PChar(AValue),PChar(Self),L)=0
  1009. end;
  1010. function TStringHelper.Substring(AStartIndex: Integer): string;
  1011. begin
  1012. Result:=Self.SubString(AStartIndex,Self.Length-AStartIndex);
  1013. end;
  1014. function TStringHelper.Substring(AStartIndex: Integer; ALen: Integer): string;
  1015. begin
  1016. Result:=system.Copy(Self,AStartIndex+1,ALen);
  1017. end;
  1018. function TStringHelper.ToBoolean: Boolean;
  1019. begin
  1020. Result:=StrToBool(Self);
  1021. end;
  1022. function TStringHelper.ToInteger: Integer;
  1023. begin
  1024. Result:=StrToInt(Self);
  1025. end;
  1026. function TStringHelper.ToInt64: Int64;
  1027. begin
  1028. Result:=StrToInt64(Self);
  1029. end;
  1030. function TStringHelper.ToSingle: Single;
  1031. begin
  1032. Result:=StrToFLoat(Self);
  1033. end;
  1034. function TStringHelper.ToDouble: Double;
  1035. begin
  1036. Result:=StrToFLoat(Self);
  1037. end;
  1038. function TStringHelper.ToExtended: Extended;
  1039. begin
  1040. Result:=StrToFLoat(Self);
  1041. end;
  1042. function TStringHelper.ToCharArray: TCharArray;
  1043. begin
  1044. Result:=ToCharArray(0,Self.Length);
  1045. end;
  1046. function TStringHelper.ToCharArray(AStartIndex: Integer; ALen: Integer
  1047. ): TCharArray;
  1048. Var
  1049. I : Integer;
  1050. begin
  1051. SetLength(Result,ALen);
  1052. For I:=0 to ALen-1 do
  1053. Result[I]:=Self[AStartIndex+I+1];
  1054. end;
  1055. function TStringHelper.ToLower: string;
  1056. begin
  1057. Result:=LowerCase(Self);
  1058. end;
  1059. function TStringHelper.ToLowerInvariant: string;
  1060. begin
  1061. Result:=LowerCase(Self);
  1062. end;
  1063. function TStringHelper.ToUpper: string;
  1064. begin
  1065. Result:=UpperCase(Self);
  1066. end;
  1067. function TStringHelper.ToUpperInvariant: string;
  1068. begin
  1069. Result:=UpperCase(Self);
  1070. end;
  1071. function TStringHelper.Trim: string;
  1072. begin
  1073. Result:=SysUtils.Trim(Self);
  1074. end;
  1075. function TStringHelper.TrimLeft: string;
  1076. begin
  1077. Result:=SysUtils.TrimLeft(Self);
  1078. end;
  1079. function TStringHelper.TrimRight: string;
  1080. begin
  1081. Result:=SysUtils.TrimRight(Self);
  1082. end;
  1083. function TStringHelper.Trim(const ATrimChars: array of Char): string;
  1084. begin
  1085. Result:=Self.TrimLeft(ATrimChars).TrimRight(ATrimChars);
  1086. end;
  1087. function TStringHelper.TrimLeft(const ATrimChars: array of Char): string;
  1088. Var
  1089. I,Len : Integer;
  1090. begin
  1091. I:=1;
  1092. Len:=Self.Length;
  1093. While (I<=Len) and HaveChar(Self[i],ATrimChars) do Inc(I);
  1094. if I=1 then
  1095. Result:=Self
  1096. else if I>Len then
  1097. Result:=''
  1098. else
  1099. Result:=system.Copy(Self,I,Len-I+1);
  1100. end;
  1101. function TStringHelper.TrimRight(const ATrimChars: array of Char): string;
  1102. Var
  1103. I,Len : Integer;
  1104. begin
  1105. Len:=Self.Length;
  1106. I:=Len;
  1107. While (I>=1) and HaveChar(Self[i],ATrimChars) do Dec(I);
  1108. if I<1 then
  1109. Result:=''
  1110. else if I=Len then
  1111. Result:=Self
  1112. else
  1113. Result:=system.Copy(Self,1,I);
  1114. end;
  1115. function TStringHelper.TrimEnd(const ATrimChars: array of Char): string;
  1116. begin
  1117. Result:=TrimRight(ATrimChars);
  1118. end;
  1119. function TStringHelper.TrimStart(const ATrimChars: array of Char): string;
  1120. begin
  1121. Result:=TrimLeft(ATrimChars);
  1122. end;
  1123. { ---------------------------------------------------------------------
  1124. TSingleHelper
  1125. ---------------------------------------------------------------------}
  1126. {$MACRO ON}
  1127. {$IFDEF FPC_HAS_TYPE_SINGLE}
  1128. {$define TFLOATHELPER:=TSingleHelper}
  1129. {$define FLOATTYPE:=Single}
  1130. {$i syshelpf.inc}
  1131. {$ENDIF FPC_HAS_TYPE_SINGLE}
  1132. { ---------------------------------------------------------------------
  1133. TDoubleHelper
  1134. ---------------------------------------------------------------------}
  1135. {$IFDEF FPC_HAS_TYPE_DOUBLE}
  1136. {$define TFLOATHELPER:=TDoubleHelper}
  1137. {$define FLOATTYPE:=Double}
  1138. {$i syshelpf.inc}
  1139. {$ENDIF FPC_HAS_TYPE_DOUBLE}
  1140. { ---------------------------------------------------------------------
  1141. TExtendedHelper
  1142. ---------------------------------------------------------------------}
  1143. {$ifdef FPC_HAS_TYPE_EXTENDED}
  1144. {$define TFLOATHELPER:=TExtendedHelper}
  1145. {$define FLOATTYPE:=Extended}
  1146. {$i syshelpf.inc}
  1147. {$ENDIF FPC_HAS_TYPE_EXTENDED}
  1148. { ---------------------------------------------------------------------
  1149. TByteHelper
  1150. ---------------------------------------------------------------------}
  1151. {$define TORDINALHELPER:=TByteHelper}
  1152. {$define TORDINALTYPE:=Byte}
  1153. {$i syshelpo.inc}
  1154. { ---------------------------------------------------------------------
  1155. TShortintHelper
  1156. ---------------------------------------------------------------------}
  1157. {$define TORDINALHELPER:=TShortIntHelper}
  1158. {$define TORDINALTYPE:=ShortInt}
  1159. {$i syshelpo.inc}
  1160. { ---------------------------------------------------------------------
  1161. TSmallintHelper
  1162. ---------------------------------------------------------------------}
  1163. {$define TORDINALHELPER:=TSmallIntHelper}
  1164. {$define TORDINALTYPE:=SmallInt}
  1165. {$i syshelpo.inc}
  1166. { ---------------------------------------------------------------------
  1167. TWordHelper
  1168. ---------------------------------------------------------------------}
  1169. {$define TORDINALHELPER:=TWordHelper}
  1170. {$define TORDINALTYPE:=Word}
  1171. {$i syshelpo.inc}
  1172. { ---------------------------------------------------------------------
  1173. TCardinalHelper
  1174. ---------------------------------------------------------------------}
  1175. {$define TORDINALHELPER:=TCardinalHelper}
  1176. {$define TORDINALTYPE:=Cardinal}
  1177. {$i syshelpo.inc}
  1178. { ---------------------------------------------------------------------
  1179. TIntegerHelper
  1180. ---------------------------------------------------------------------}
  1181. {$define TORDINALHELPER:=TIntegerHelper}
  1182. {$define TORDINALTYPE:=Integer}
  1183. {$i syshelpo.inc}
  1184. { ---------------------------------------------------------------------
  1185. TInt64Helper
  1186. ---------------------------------------------------------------------}
  1187. {$define TORDINALHELPER:=TInt64Helper}
  1188. {$define TORDINALTYPE:=Int64}
  1189. {$i syshelpo.inc}
  1190. { ---------------------------------------------------------------------
  1191. TQWordHelper
  1192. ---------------------------------------------------------------------}
  1193. {$define TORDINALHELPER:=TQWordHelper}
  1194. {$define TORDINALTYPE:=QWord}
  1195. {$i syshelpo.inc}
  1196. { ---------------------------------------------------------------------
  1197. TNativeIntHelper
  1198. ---------------------------------------------------------------------}
  1199. {$define TORDINALHELPER:=TNativeIntHelper}
  1200. {$define TORDINALTYPE:=NativeInt}
  1201. {$i syshelpo.inc}
  1202. { ---------------------------------------------------------------------
  1203. TNativeUIntHelper
  1204. ---------------------------------------------------------------------}
  1205. {$define TORDINALHELPER:=TNativeUIntHelper}
  1206. {$define TORDINALTYPE:=NativeUInt}
  1207. {$i syshelpo.inc}
  1208. { ---------------------------------------------------------------------
  1209. TBooleanHelper
  1210. ---------------------------------------------------------------------}
  1211. {$define TBOOLHELPER:=TBooleanHelper}
  1212. {$define TBOOLTYPE:=Boolean}
  1213. {$i syshelpb.inc}
  1214. { ---------------------------------------------------------------------
  1215. TByteBoolHelper
  1216. ---------------------------------------------------------------------}
  1217. {$define TBOOLHELPER:=TByteBoolHelper}
  1218. {$define TBOOLTYPE:=ByteBool}
  1219. {$i syshelpb.inc}
  1220. { ---------------------------------------------------------------------
  1221. TWordBoolHelper
  1222. ---------------------------------------------------------------------}
  1223. {$define TBOOLHELPER:=TWordBoolHelper}
  1224. {$define TBOOLTYPE:=WordBool}
  1225. {$i syshelpb.inc}
  1226. { ---------------------------------------------------------------------
  1227. TLongBoolHelper
  1228. ---------------------------------------------------------------------}
  1229. {$define TBOOLHELPER:=TLongBoolHelper}
  1230. {$define TBOOLTYPE:=LongBool}
  1231. {$i syshelpb.inc}