sysstr.inc 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133
  1. {
  2. *********************************************************************
  3. $Id$
  4. Copyright (C) 1997, 1998 Gertjan Schouten
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. *********************************************************************
  17. System Utilities For Free Pascal
  18. }
  19. { NewStr creates a new PString and assigns S to it
  20. if length(s) = 0 NewStr returns Nil }
  21. function NewStr(const S: string): PString;
  22. begin
  23. if (S='') then
  24. Result:=nil
  25. else
  26. begin
  27. new(result);
  28. if (Result<>nil) then
  29. Result^:=s;
  30. end;
  31. end;
  32. { DisposeStr frees the memory occupied by S }
  33. procedure DisposeStr(S: PString);
  34. begin
  35. if S <> Nil then
  36. begin
  37. dispose(s);
  38. S:=nil;
  39. end;
  40. end;
  41. { AssignStr assigns S to P^ }
  42. procedure AssignStr(var P: PString; const S: string);
  43. begin
  44. P^ := s;
  45. end ;
  46. { AppendStr appends S to Dest }
  47. procedure AppendStr(var Dest: String; const S: string);
  48. begin
  49. Dest := Dest + S;
  50. end ;
  51. { UpperCase returns a copy of S where all lowercase characters ( from a to z )
  52. have been converted to uppercase }
  53. function UpperCase(const S: string): string;
  54. var i: integer;
  55. begin
  56. result := S;
  57. i := Length(S);
  58. while i <> 0 do begin
  59. if (result[i] in ['a'..'z']) then result[i] := char(byte(result[i]) - 32);
  60. Dec(i);
  61. end;
  62. end;
  63. { LowerCase returns a copy of S where all uppercase characters ( from A to Z )
  64. have been converted to lowercase }
  65. function LowerCase(const S: string): string;
  66. var i: integer;
  67. begin
  68. result := S;
  69. i := Length(result);
  70. while i <> 0 do begin
  71. if (result[i] in ['A'..'Z']) then result[i] := char(byte(result[i]) + 32);
  72. dec(i);
  73. end;
  74. end;
  75. { CompareStr compares S1 and S2, the result is the based on
  76. substraction of the ascii values of the characters in S1 and S2
  77. case result
  78. S1 < S2 < 0
  79. S1 > S2 > 0
  80. S1 = S2 = 0 }
  81. function CompareStr(const S1, S2: string): Integer;
  82. var count, count1, count2: integer;
  83. begin
  84. result := 0;
  85. Count1 := Length(S1);
  86. Count2 := Length(S2);
  87. if Count1>Count2 then
  88. Count:=Count2
  89. else
  90. Count:=Count1;
  91. result := CompareMemRange(Pointer(S1),Pointer(S2), Count);
  92. if result=0 then
  93. result:=Count1-Count2;
  94. end;
  95. { CompareMemRange returns the result of comparison of Length bytes at P1 and P2
  96. case result
  97. P1 < P2 < 0
  98. P1 > P2 > 0
  99. P1 = P2 = 0 }
  100. function CompareMemRange(P1, P2: Pointer; Length: cardinal): integer;
  101. var
  102. i: cardinal;
  103. begin
  104. i := 0;
  105. result := 0;
  106. while (result=0) and (I<length) do
  107. begin
  108. result:=byte(P1^)-byte(P2^);
  109. P1:=pchar(P1)+1; // VP compat.
  110. P2:=pchar(P2)+1;
  111. i := i + 1;
  112. end ;
  113. end ;
  114. function CompareMem(P1, P2: Pointer; Length: cardinal): Boolean;
  115. var
  116. i: cardinal;
  117. begin
  118. Result:=True;
  119. I:=0;
  120. If (P1)<>(P2) then
  121. While Result and (i<Length) do
  122. begin
  123. Result:=PByte(P1)^=PByte(P2)^;
  124. Inc(I);
  125. Inc(pchar(P1));
  126. Inc(pchar(P2));
  127. end;
  128. end;
  129. { CompareText compares S1 and S2, the result is the based on
  130. substraction of the ascii values of characters in S1 and S2
  131. comparison is case-insensitive
  132. case result
  133. S1 < S2 < 0
  134. S1 > S2 > 0
  135. S1 = S2 = 0 }
  136. function CompareText(const S1, S2: string): integer;
  137. var
  138. i, count, count1, count2: integer; Chr1, Chr2: byte;
  139. begin
  140. result := 0;
  141. Count1 := Length(S1);
  142. Count2 := Length(S2);
  143. if (Count1>Count2) then
  144. Count := Count2
  145. else
  146. Count := Count1;
  147. i := 0;
  148. while (result=0) and (i<count) do
  149. begin
  150. inc (i);
  151. Chr1 := byte(s1[i]);
  152. Chr2 := byte(s2[i]);
  153. if Chr1 in [97..122] then
  154. dec(Chr1,32);
  155. if Chr2 in [97..122] then
  156. dec(Chr2,32);
  157. result := Chr1 - Chr2;
  158. end ;
  159. if (result = 0) then
  160. result:=(count1-count2);
  161. end;
  162. function SameText(const s1,s2:String):Boolean;
  163. begin
  164. Result:=CompareText(S1,S2)=0;
  165. end;
  166. {==============================================================================}
  167. { Ansi string functions }
  168. { these functions rely on the character set loaded by the OS }
  169. {==============================================================================}
  170. function GenericAnsiUpperCase(const s: string): string;
  171. var
  172. len, i: integer;
  173. begin
  174. len := length(s);
  175. SetLength(result, len);
  176. for i := 1 to len do
  177. result[i] := UpperCaseTable[ord(s[i])];
  178. end;
  179. function GenericAnsiLowerCase(const s: string): string;
  180. var
  181. len, i: integer;
  182. begin
  183. len := length(s);
  184. SetLength(result, len);
  185. for i := 1 to len do
  186. result[i] := LowerCaseTable[ord(s[i])];
  187. end;
  188. function GenericAnsiCompareStr(const S1, S2: string): PtrInt;
  189. Var
  190. I,L1,L2 : SizeInt;
  191. begin
  192. Result:=0;
  193. L1:=Length(S1);
  194. L2:=Length(S2);
  195. I:=1;
  196. While (Result=0) and ((I<=L1) and (I<=L2)) do
  197. begin
  198. Result:=Ord(S1[I])-Ord(S2[I]); //!! Must be replaced by ansi characters !!
  199. Inc(I);
  200. end;
  201. If Result=0 Then
  202. Result:=L1-L2;
  203. end;
  204. function GenericAnsiCompareText(const S1, S2: string): PtrInt;
  205. Var
  206. I,L1,L2 : SizeInt;
  207. begin
  208. Result:=0;
  209. L1:=Length(S1);
  210. L2:=Length(S2);
  211. I:=1;
  212. While (Result=0) and ((I<=L1) and (I<=L2)) do
  213. begin
  214. Result:=Ord(LowerCaseTable[Ord(S1[I])])-Ord(LowerCaseTable[Ord(S2[I])]); //!! Must be replaced by ansi characters !!
  215. Inc(I);
  216. end;
  217. If Result=0 Then
  218. Result:=L1-L2;
  219. end;
  220. function AnsiSameText(const s1,s2:String):Boolean;{$ifdef SYSUTILSINLINE}inline;{$endif}
  221. begin
  222. AnsiSameText:=AnsiCompareText(S1,S2)=0;
  223. end;
  224. function AnsiSameStr(const s1,s2:String):Boolean;{$ifdef SYSUTILSINLINE}inline;{$endif}
  225. begin
  226. AnsiSameStr:=AnsiCompareStr(S1,S2)=0;
  227. end;
  228. function GenericAnsiStrComp(S1, S2: PChar): PtrInt;
  229. begin
  230. Result:=0;
  231. If S1=Nil then
  232. begin
  233. If S2=Nil Then Exit;
  234. result:=-1;
  235. exit;
  236. end;
  237. If S2=Nil then
  238. begin
  239. Result:=1;
  240. exit;
  241. end;
  242. Repeat
  243. Result:=Ord(S1[0])-Ord(S2[0]); //!! Must be replaced by ansi characters !!
  244. Inc(S1);
  245. Inc(S2);
  246. Until (Result<>0) or ((S1[0]=#0) or (S2[0]=#0))
  247. end;
  248. function GenericAnsiStrIComp(S1, S2: PChar): PtrInt;
  249. begin
  250. Result:=0;
  251. If S1=Nil then
  252. begin
  253. If S2=Nil Then Exit;
  254. result:=-1;
  255. exit;
  256. end;
  257. If S2=Nil then
  258. begin
  259. Result:=1;
  260. exit;
  261. end;
  262. Repeat
  263. Result:=Ord(LowerCaseTable[Ord(S1[0])])-Ord(LowerCaseTable[Ord(S2[0])]); //!! Must be replaced by ansi characters !!
  264. Inc(S1);
  265. Inc(S2);
  266. Until (Result<>0) or ((S1[0]=#0) or (S2[0]=#0))
  267. end;
  268. function GenericAnsiStrLComp(S1, S2: PChar; MaxLen: PtrUInt): PtrInt;
  269. Var I : cardinal;
  270. begin
  271. Result:=0;
  272. If MaxLen=0 then exit;
  273. If S1=Nil then
  274. begin
  275. If S2=Nil Then Exit;
  276. result:=-1;
  277. exit;
  278. end;
  279. If S2=Nil then
  280. begin
  281. Result:=1;
  282. exit;
  283. end;
  284. I:=0;
  285. Repeat
  286. Result:=Ord(S1[0])-Ord(S2[0]); //!! Must be replaced by ansi characters !!
  287. Inc(S1);
  288. Inc(S2);
  289. Inc(I);
  290. Until (Result<>0) or ((S1[0]=#0) or (S2[0]=#0)) or (I=MaxLen)
  291. end;
  292. function GenericAnsiStrLIComp(S1, S2: PChar; MaxLen: PtrUInt): PtrInt;
  293. Var I : cardinal;
  294. begin
  295. Result:=0;
  296. If MaxLen=0 then exit;
  297. If S1=Nil then
  298. begin
  299. If S2=Nil Then Exit;
  300. result:=-1;
  301. exit;
  302. end;
  303. If S2=Nil then
  304. begin
  305. Result:=1;
  306. exit;
  307. end;
  308. I:=0;
  309. Repeat
  310. Result:=Ord(LowerCaseTable[Ord(S1[0])])-Ord(LowerCaseTable[Ord(S2[0])]); //!! Must be replaced by ansi characters !!
  311. Inc(S1);
  312. Inc(S2);
  313. Inc(I);
  314. Until (Result<>0) or ((S1[0]=#0) or (S2[0]=#0)) or (I=MaxLen)
  315. end;
  316. function GenericAnsiStrLower(Str: PChar): PChar;
  317. begin
  318. result := Str;
  319. if Str <> Nil then begin
  320. while Str^ <> #0 do begin
  321. Str^ := LowerCaseTable[byte(Str^)];
  322. Str := Str + 1;
  323. end;
  324. end;
  325. end;
  326. function GenericAnsiStrUpper(Str: PChar): PChar;
  327. begin
  328. result := Str;
  329. if Str <> Nil then begin
  330. while Str^ <> #0 do begin
  331. Str^ := UpperCaseTable[byte(Str^)];
  332. Str := Str + 1;
  333. end ;
  334. end ;
  335. end ;
  336. function AnsiLastChar(const S: string): PChar;
  337. begin
  338. //!! No multibyte yet, so we return the last one.
  339. result:=StrEnd(Pchar(S));
  340. Dec(Result);
  341. end ;
  342. function AnsiStrLastChar(Str: PChar): PChar;
  343. begin
  344. //!! No multibyte yet, so we return the last one.
  345. result:=StrEnd(Str);
  346. Dec(Result);
  347. end ;
  348. function AnsiUpperCase(const s: string): string;{$ifdef SYSUTILSINLINE}inline;{$endif}
  349. begin
  350. {$ifndef ver1_0}
  351. result:=widestringmanager.UpperAnsiStringProc(s);
  352. {$endif}
  353. end;
  354. function AnsiLowerCase(const s: string): string;{$ifdef SYSUTILSINLINE}inline;{$endif}
  355. begin
  356. {$ifndef ver1_0}
  357. result:=widestringmanager.LowerAnsiStringProc(s);
  358. {$endif}
  359. end;
  360. function AnsiCompareStr(const S1, S2: string): integer;{$ifdef SYSUTILSINLINE}inline;{$endif}
  361. begin
  362. {$ifndef ver1_0}
  363. result:=widestringmanager.CompareStrAnsiStringProc(s1,s2);
  364. {$endif}
  365. end;
  366. function AnsiCompareText(const S1, S2: string): integer;{$ifdef SYSUTILSINLINE}inline;{$endif}
  367. begin
  368. {$ifndef ver1_0}
  369. result:=widestringmanager.CompareTextAnsiStringProc(s1,s2);
  370. {$endif}
  371. end;
  372. function AnsiStrComp(S1, S2: PChar): integer;{$ifdef SYSUTILSINLINE}inline;{$endif}
  373. begin
  374. {$ifndef ver1_0}
  375. result:=widestringmanager.StrCompAnsiStringProc(s1,s2);
  376. {$endif}
  377. end;
  378. function AnsiStrIComp(S1, S2: PChar): integer;{$ifdef SYSUTILSINLINE}inline;{$endif}
  379. begin
  380. {$ifndef ver1_0}
  381. result:=widestringmanager.StrICompAnsiStringProc(s1,s2);
  382. {$endif}
  383. end;
  384. function AnsiStrLComp(S1, S2: PChar; MaxLen: cardinal): integer;{$ifdef SYSUTILSINLINE}inline;{$endif}
  385. begin
  386. {$ifndef ver1_0}
  387. result:=widestringmanager.StrLCompAnsiStringProc(s1,s2,maxlen);
  388. {$endif}
  389. end;
  390. function AnsiStrLIComp(S1, S2: PChar; MaxLen: cardinal): integer;{$ifdef SYSUTILSINLINE}inline;{$endif}
  391. begin
  392. {$ifndef ver1_0}
  393. result:=widestringmanager.StrLICompAnsiStringProc(s1,s2,maxlen);
  394. {$endif}
  395. end;
  396. function AnsiStrLower(Str: PChar): PChar;{$ifdef SYSUTILSINLINE}inline;{$endif}
  397. begin
  398. {$ifndef ver1_0}
  399. result:=widestringmanager.StrLowerAnsiStringProc(Str);
  400. {$endif}
  401. end;
  402. function AnsiStrUpper(Str: PChar): PChar;{$ifdef SYSUTILSINLINE}inline;{$endif}
  403. begin
  404. {$ifndef ver1_0}
  405. result:=widestringmanager.StrUpperAnsiStringProc(Str);
  406. {$endif}
  407. end;
  408. {==============================================================================}
  409. { End of Ansi functions }
  410. {==============================================================================}
  411. { Trim returns a copy of S with blanks characters on the left and right stripped off }
  412. Const WhiteSpace = [' ',#10,#13,#9];
  413. function Trim(const S: string): string;
  414. var Ofs, Len: integer;
  415. begin
  416. len := Length(S);
  417. while (Len>0) and (S[Len] in WhiteSpace) do
  418. dec(Len);
  419. Ofs := 1;
  420. while (Ofs<=Len) and (S[Ofs] in WhiteSpace) do
  421. Inc(Ofs);
  422. result := Copy(S, Ofs, 1 + Len - Ofs);
  423. end ;
  424. { TrimLeft returns a copy of S with all blank characters on the left stripped off }
  425. function TrimLeft(const S: string): string;
  426. var i,l:integer;
  427. begin
  428. l := length(s);
  429. i := 1;
  430. while (i<=l) and (s[i] in whitespace) do
  431. inc(i);
  432. Result := copy(s, i, l);
  433. end ;
  434. { TrimRight returns a copy of S with all blank characters on the right stripped off }
  435. function TrimRight(const S: string): string;
  436. var l:integer;
  437. begin
  438. l := length(s);
  439. while (l>0) and (s[l] in whitespace) do
  440. dec(l);
  441. result := copy(s,1,l);
  442. end ;
  443. { QuotedStr returns S quoted left and right and every single quote in S
  444. replaced by two quotes }
  445. function QuotedStr(const S: string): string;
  446. begin
  447. result := AnsiQuotedStr(s, '''');
  448. end ;
  449. { AnsiQuotedStr returns S quoted left and right by Quote,
  450. and every single occurance of Quote replaced by two }
  451. function AnsiQuotedStr(const S: string; Quote: char): string;
  452. var i, j, count: integer;
  453. begin
  454. result := '' + Quote;
  455. count := length(s);
  456. i := 0;
  457. j := 0;
  458. while i < count do begin
  459. i := i + 1;
  460. if S[i] = Quote then begin
  461. result := result + copy(S, 1 + j, i - j) + Quote;
  462. j := i;
  463. end ;
  464. end ;
  465. if i <> j then
  466. result := result + copy(S, 1 + j, i - j);
  467. result := result + Quote;
  468. end ;
  469. { AnsiExtractQuotedStr returns a copy of Src with quote characters
  470. deleted to the left and right and double occurances
  471. of Quote replaced by a single Quote }
  472. function AnsiExtractQuotedStr(var Src: PChar; Quote: Char): string;
  473. var i: integer; P, Q,R: PChar;
  474. begin
  475. P := Src;
  476. Q := StrEnd(P);
  477. result:='';
  478. if P=Q then exit;
  479. if P^<>quote then exit;
  480. inc(p);
  481. setlength(result,(Q-P)+1);
  482. R:=@Result[1];
  483. i := 0;
  484. while P <> Q do
  485. begin
  486. R^:=P^;
  487. inc(R);
  488. if (P^ = Quote) then
  489. begin
  490. P := P + 1;
  491. if (p^ <> Quote) then
  492. begin
  493. dec(R);
  494. break;
  495. end;
  496. end;
  497. P := P + 1;
  498. end ;
  499. src:=p;
  500. SetLength(result, (R-pchar(@Result[1])));
  501. end ;
  502. { AdjustLineBreaks returns S with all CR characters not followed by LF
  503. replaced with CR/LF }
  504. // under Linux all CR characters or CR/LF combinations should be replaced with LF
  505. function AdjustLineBreaks(const S: string): string;
  506. begin
  507. Result:=AdjustLineBreaks(S,DefaultTextLineBreakStyle);
  508. end;
  509. function AdjustLineBreaks(const S: string; Style: TTextLineBreakStyle): string;
  510. var
  511. Source,Dest: PChar;
  512. DestLen: Integer;
  513. I,J,L: Longint;
  514. begin
  515. Source:=Pointer(S);
  516. L:=Length(S);
  517. DestLen:=L;
  518. I:=1;
  519. while (I<=L) do
  520. begin
  521. case S[i] of
  522. #10: if (Style=tlbsCRLF) then
  523. Inc(DestLen);
  524. #13: if (Style=tlbsCRLF) then
  525. if (I<L) and (S[i+1]=#10) then
  526. Inc(I)
  527. else
  528. Inc(DestLen)
  529. else if (I<L) and (S[I+1]=#10) then
  530. Dec(DestLen);
  531. end;
  532. Inc(I);
  533. end;
  534. if (DestLen=L) then
  535. Result:=S
  536. else
  537. begin
  538. SetLength(Result, DestLen);
  539. FillChar(Result[1],DestLen,0);
  540. Dest := Pointer(Result);
  541. J:=0;
  542. I:=0;
  543. While I<L do
  544. case Source[I] of
  545. #10: begin
  546. if Style=tlbsCRLF then
  547. begin
  548. Dest[j]:=#13;
  549. Inc(J);
  550. end;
  551. Dest[J] := #10;
  552. Inc(J);
  553. Inc(I);
  554. end;
  555. #13: begin
  556. if Style=tlbsCRLF then
  557. begin
  558. Dest[j] := #13;
  559. Inc(J);
  560. end;
  561. Dest[j]:=#10;
  562. Inc(J);
  563. Inc(I);
  564. if Source[I]=#10 then
  565. Inc(I);
  566. end;
  567. else
  568. Dest[j]:=Source[i];
  569. Inc(J);
  570. Inc(I);
  571. end;
  572. end;
  573. end;
  574. { IsValidIdent returns true if the first character of Ident is in:
  575. 'A' to 'Z', 'a' to 'z' or '_' and the following characters are
  576. on of: 'A' to 'Z', 'a' to 'z', '0'..'9' or '_' }
  577. function IsValidIdent(const Ident: string): boolean;
  578. var i, len: integer;
  579. begin
  580. result := false;
  581. len := length(Ident);
  582. if len <> 0 then begin
  583. result := Ident[1] in ['A'..'Z', 'a'..'z', '_'];
  584. i := 1;
  585. while (result) and (i < len) do begin
  586. i := i + 1;
  587. result := result and (Ident[i] in ['A'..'Z', 'a'..'z', '0'..'9', '_']);
  588. end ;
  589. end ;
  590. end ;
  591. { IntToStr returns a string representing the value of Value }
  592. function IntToStr(Value: integer): string;
  593. begin
  594. System.Str(Value, result);
  595. end ;
  596. {$IFNDEF VIRTUALPASCAL}
  597. function IntToStr(Value: int64): string;
  598. begin
  599. System.Str(Value, result);
  600. end ;
  601. {$ENDIF}
  602. function IntToStr(Value: QWord): string;
  603. begin
  604. System.Str(Value, result);
  605. end ;
  606. { IntToHex returns a string representing the hexadecimal value of Value }
  607. const
  608. HexDigits: array[0..15] of char = '0123456789ABCDEF';
  609. function IntToHex(Value: integer; Digits: integer): string;
  610. var i: integer;
  611. begin
  612. SetLength(result, digits);
  613. for i := 0 to digits - 1 do
  614. begin
  615. result[digits - i] := HexDigits[value and 15];
  616. value := value shr 4;
  617. end ;
  618. while value <> 0 do begin
  619. result := HexDigits[value and 15] + result;
  620. value := value shr 4;
  621. end;
  622. end ;
  623. {$IFNDEF VIRTUALPASCAL} // overloading
  624. function IntToHex(Value: int64; Digits: integer): string;
  625. var i: integer;
  626. begin
  627. SetLength(result, digits);
  628. for i := 0 to digits - 1 do
  629. begin
  630. result[digits - i] := HexDigits[value and 15];
  631. value := value shr 4;
  632. end ;
  633. while value <> 0 do begin
  634. result := HexDigits[value and 15] + result;
  635. value := value shr 4;
  636. end;
  637. end ;
  638. {$ENDIF}
  639. function TryStrToInt(const s: string; var i : integer) : boolean;
  640. var Error : word;
  641. begin
  642. Val(s, i, Error);
  643. TryStrToInt:=Error=0
  644. end;
  645. { StrToInt converts the string S to an integer value,
  646. if S does not represent a valid integer value EConvertError is raised }
  647. function StrToInt(const S: string): integer;
  648. {$IFDEF VIRTUALPASCAL}
  649. var Error: longint;
  650. {$ELSE}
  651. var Error: word;
  652. {$ENDIF}
  653. begin
  654. Val(S, result, Error);
  655. if Error <> 0 then raise EConvertError.createfmt(SInValidInteger,[S]);
  656. end ;
  657. function StrToInt64(const S: string): int64;
  658. {$IFDEF VIRTUALPASCAL}
  659. var Error: longint;
  660. {$ELSE}
  661. var Error: word;
  662. {$ENDIF}
  663. begin
  664. Val(S, result, Error);
  665. if Error <> 0 then raise EConvertError.createfmt(SInValidInteger,[S]);
  666. end;
  667. function TryStrToInt64(const s: string; var i : int64) : boolean;
  668. var Error : word;
  669. begin
  670. Val(s, i, Error);
  671. TryStrToInt64:=Error=0
  672. end;
  673. { StrToIntDef converts the string S to an integer value,
  674. Default is returned in case S does not represent a valid integer value }
  675. function StrToIntDef(const S: string; Default: integer): integer;
  676. {$IFDEF VIRTUALPASCAL}
  677. var Error: longint;
  678. {$ELSE}
  679. var Error: word;
  680. {$ENDIF}
  681. begin
  682. Val(S, result, Error);
  683. if Error <> 0 then result := Default;
  684. end ;
  685. { StrToIntDef converts the string S to an integer value,
  686. Default is returned in case S does not represent a valid integer value }
  687. function StrToInt64Def(const S: string; Default: int64): int64;
  688. {$IFDEF VIRTUALPASCAL}
  689. var Error: longint;
  690. {$ELSE}
  691. var Error: word;
  692. {$ENDIF}
  693. begin
  694. Val(S, result, Error);
  695. if Error <> 0 then result := Default;
  696. end ;
  697. { LoadStr returns the string resource Ident. }
  698. function LoadStr(Ident: integer): string;
  699. begin
  700. result:='';
  701. end ;
  702. { FmtLoadStr returns the string resource Ident and formats it accordingly }
  703. function FmtLoadStr(Ident: integer; const Args: array of const): string;
  704. begin
  705. result:='';
  706. end;
  707. Const
  708. feInvalidFormat = 1;
  709. feMissingArgument = 2;
  710. feInvalidArgIndex = 3;
  711. {$ifdef fmtdebug}
  712. Procedure Log (Const S: String);
  713. begin
  714. Writeln (S);
  715. end;
  716. {$endif}
  717. Procedure DoFormatError (ErrCode : Longint);
  718. Var
  719. S : String;
  720. begin
  721. //!! must be changed to contain format string...
  722. S:='';
  723. Case ErrCode of
  724. feInvalidFormat : raise EConvertError.Createfmt(SInvalidFormat,[s]);
  725. feMissingArgument : raise EConvertError.Createfmt(SArgumentMissing,[s]);
  726. feInvalidArgIndex : raise EConvertError.Createfmt(SInvalidArgIndex,[s]);
  727. end;
  728. end;
  729. { we've no templates, but with includes we can simulate this :) }
  730. {$macro on}
  731. {$define INFORMAT}
  732. {$define TFormatString:=ansistring}
  733. {$define TFormatChar:=char}
  734. Function Format (Const Fmt : AnsiString; const Args : Array of const) : AnsiString;
  735. {$i sysformt.inc}
  736. {$undef TFormatString}
  737. {$undef TFormatChar}
  738. {$undef INFORMAT}
  739. {$macro off}
  740. Function FormatBuf (Var Buffer; BufLen : Cardinal;
  741. Const Fmt; fmtLen : Cardinal;
  742. Const Args : Array of const) : Cardinal;
  743. Var S,F : String;
  744. begin
  745. Setlength(F,fmtlen);
  746. if fmtlen > 0 then
  747. Move(fmt,F[1],fmtlen);
  748. S:=Format (F,Args);
  749. If Cardinal(Length(S))<Buflen then
  750. Result:=Length(S)
  751. else
  752. Result:=Buflen;
  753. Move(S[1],Buffer,Result);
  754. end;
  755. Procedure FmtStr(Var Res: String; Const Fmt : String; Const args: Array of const);
  756. begin
  757. Res:=Format(fmt,Args);
  758. end;
  759. Function StrFmt(Buffer,Fmt : PChar; Const args: Array of const) : Pchar;
  760. begin
  761. Buffer[FormatBuf(Buffer^,Maxint,Fmt^,strlen(fmt),args)]:=#0;
  762. Result:=Buffer;
  763. end;
  764. Function StrLFmt(Buffer : PCHar; Maxlen : Cardinal;Fmt : PChar; Const args: Array of const) : Pchar;
  765. begin
  766. Buffer[FormatBuf(Buffer^,MaxLen,Fmt^,strlen(fmt),args)]:=#0;
  767. Result:=Buffer;
  768. end;
  769. Function StrToFloat(Const S: String): Extended;
  770. Begin
  771. If Not TextToFloat(Pchar(S),Result) then
  772. Raise EConvertError.createfmt(SInValidFLoat,[S]);
  773. End;
  774. function StrToFloatDef(const S: string; const Default: Extended): Extended;
  775. begin
  776. if not TextToFloat(PChar(S),Result,fvExtended) then
  777. Result:=Default;
  778. end;
  779. Function TextToFloat(Buffer: PChar; Var Value: Extended): Boolean;
  780. Var
  781. E,P : Integer;
  782. S : String;
  783. Begin
  784. S:=StrPas(Buffer);
  785. P:=Pos(DecimalSeparator,S);
  786. If (P<>0) Then
  787. S[P] := '.';
  788. Val(S,Value,E);
  789. Result:=(E=0);
  790. End;
  791. Function TextToFloat(Buffer: PChar; Var Value; ValueType: TFloatValue): Boolean;
  792. Var
  793. E,P : Integer;
  794. S : String;
  795. C : Currency;
  796. Ext : Extended;
  797. Begin
  798. S:=StrPas(Buffer);
  799. P:=Pos(ThousandSeparator,S);
  800. While (P<>0) do
  801. begin
  802. Delete(S,P,1);
  803. P:=Pos(ThousandSeparator,S);
  804. end;
  805. P:=Pos(DecimalSeparator,S);
  806. If (P<>0) Then
  807. S[P] := '.';
  808. case ValueType of
  809. fvCurrency:
  810. Val(S,Currency(Value),E);
  811. fvExtended:
  812. Val(S,Extended(Value),E);
  813. fvDouble:
  814. Val(S,Double(Value),E);
  815. fvSingle:
  816. Val(S,Single(Value),E);
  817. fvComp:
  818. Val(S,Comp(Value),E);
  819. fvReal:
  820. Val(S,Real(Value),E);
  821. end;
  822. Result:=(E=0);
  823. End;
  824. Function TryStrToFloat(Const S : String; Var Value: Single): Boolean;
  825. Begin
  826. Result := TextToFloat(PChar(S), Value, fvSingle);
  827. End;
  828. Function TryStrToFloat(Const S : String; Var Value: Double): Boolean;
  829. Begin
  830. Result := TextToFloat(PChar(S), Value, fvDouble);
  831. End;
  832. {$ifdef FPC_HAS_TYPE_EXTENDED}
  833. Function TryStrToFloat(Const S : String; Var Value: Extended): Boolean;
  834. Begin
  835. Result := TextToFloat(PChar(S), Value);
  836. End;
  837. {$endif FPC_HAS_TYPE_EXTENDED}
  838. Function FloatToStr(Value: Extended): String;
  839. Begin
  840. Result := FloatToStrF(Value, ffGeneral, 15, 0);
  841. End;
  842. Function FloatToText(Buffer: PChar; Value: Extended; format: TFloatFormat; Precision, Digits: Integer): Longint;
  843. Var
  844. Tmp: String[40];
  845. Begin
  846. Tmp := FloatToStrF(Value, format, Precision, Digits);
  847. Result := Length(Tmp);
  848. Move(Tmp[1], Buffer[0], Result);
  849. End;
  850. Function FloatToStrF(Value: Extended; format: TFloatFormat; Precision, Digits: Integer): String;
  851. Var
  852. P: Integer;
  853. Negative, TooSmall, TooLarge: Boolean;
  854. Begin
  855. Case format Of
  856. ffGeneral:
  857. Begin
  858. If (Precision = -1) Or (Precision > 15) Then Precision := 15;
  859. TooSmall := (Abs(Value) < 0.00001) and (Value>0.0);
  860. If Not TooSmall Then
  861. Begin
  862. Str(Value:digits:precision, Result);
  863. P := Pos('.', Result);
  864. Result[P] := DecimalSeparator;
  865. TooLarge := P > Precision + 1;
  866. End;
  867. If TooSmall Or TooLarge Then
  868. begin
  869. Result := FloatToStrF(Value, ffExponent, Precision, Digits);
  870. // Strip unneeded zeroes.
  871. P:=Pos('E',result)-1;
  872. If P<>-1 then
  873. While (P>1) and (Result[P]='0') do
  874. begin
  875. system.Delete(Result,P,1);
  876. Dec(P);
  877. end;
  878. end
  879. else
  880. begin
  881. P := Length(Result);
  882. While Result[P] = '0' Do Dec(P);
  883. If Result[P] = DecimalSeparator Then Dec(P);
  884. SetLength(Result, P);
  885. end;
  886. End;
  887. ffExponent:
  888. Begin
  889. If (Precision = -1) Or (Precision > 15) Then Precision := 15;
  890. Str(Value:Precision + 8, Result);
  891. Result[3] := DecimalSeparator;
  892. P:=4;
  893. While (P>0) and (Digits < P) And (Result[Precision + 5] = '0') do
  894. Begin
  895. If P<>1 then
  896. system.Delete(Result, Precision + 5, 1)
  897. else
  898. system.Delete(Result, Precision + 3, 3);
  899. Dec(P);
  900. end;
  901. If Result[1] = ' ' Then
  902. System.Delete(Result, 1, 1);
  903. End;
  904. ffFixed:
  905. Begin
  906. If Digits = -1 Then Digits := 2
  907. Else If Digits > 18 Then Digits := 18;
  908. Str(Value:0:Digits, Result);
  909. If Result[1] = ' ' Then
  910. System.Delete(Result, 1, 1);
  911. P := Pos('.', Result);
  912. If P <> 0 Then Result[P] := DecimalSeparator;
  913. End;
  914. ffNumber:
  915. Begin
  916. If Digits = -1 Then Digits := 2
  917. Else If Digits > 15 Then Digits := 15;
  918. Str(Value:0:Digits, Result);
  919. If Result[1] = ' ' Then System.Delete(Result, 1, 1);
  920. P := Pos('.', Result);
  921. If P <> 0 Then
  922. Result[P] := DecimalSeparator
  923. else
  924. P := Length(Result)+1;
  925. Dec(P, 3);
  926. While (P > 1) Do
  927. Begin
  928. If Result[P - 1] <> '-' Then Insert(ThousandSeparator, Result, P);
  929. Dec(P, 3);
  930. End;
  931. End;
  932. ffCurrency:
  933. Begin
  934. If Value < 0 Then
  935. Begin
  936. Negative := True;
  937. Value := -Value;
  938. End
  939. Else Negative := False;
  940. If Digits = -1 Then Digits := CurrencyDecimals
  941. Else If Digits > 18 Then Digits := 18;
  942. Str(Value:0:Digits, Result);
  943. If Result[1] = ' ' Then System.Delete(Result, 1, 1);
  944. P := Pos('.', Result);
  945. If P <> 0 Then Result[P] := DecimalSeparator;
  946. Dec(P, 3);
  947. While (P > 1) Do
  948. Begin
  949. Insert(ThousandSeparator, Result, P);
  950. Dec(P, 3);
  951. End;
  952. If Not Negative Then
  953. Begin
  954. Case CurrencyFormat Of
  955. 0: Result := CurrencyString + Result;
  956. 1: Result := Result + CurrencyString;
  957. 2: Result := CurrencyString + ' ' + Result;
  958. 3: Result := Result + ' ' + CurrencyString;
  959. End
  960. End
  961. Else
  962. Begin
  963. Case NegCurrFormat Of
  964. 0: Result := '(' + CurrencyString + Result + ')';
  965. 1: Result := '-' + CurrencyString + Result;
  966. 2: Result := CurrencyString + '-' + Result;
  967. 3: Result := CurrencyString + Result + '-';
  968. 4: Result := '(' + Result + CurrencyString + ')';
  969. 5: Result := '-' + Result + CurrencyString;
  970. 6: Result := Result + '-' + CurrencyString;
  971. 7: Result := Result + CurrencyString + '-';
  972. 8: Result := '-' + Result + ' ' + CurrencyString;
  973. 9: Result := '-' + CurrencyString + ' ' + Result;
  974. 10: Result := CurrencyString + ' ' + Result + '-';
  975. End;
  976. End;
  977. End;
  978. End;
  979. End;
  980. Function FloatToDateTime (Const Value : Extended) : TDateTime;
  981. begin
  982. If (Value<MinDateTime) or (Value>MaxDateTime) then
  983. Raise EConvertError.CreateFmt (SInvalidDateTime,[Value]);
  984. Result:=Value;
  985. end;
  986. function TryFloatToCurr(const Value: Extended; var AResult: Currency): Boolean;
  987. begin
  988. {$ifndef VER1_0}
  989. Result:=(Value>=MinCurrency) and (Value<=MaxCurrency);
  990. if Result then
  991. AResult := Value;
  992. {$else VER1_0}
  993. Result:=false;
  994. {$endif VER1_0}
  995. end;
  996. function FloatToCurr(const Value: Extended): Currency;
  997. begin
  998. if not TryFloatToCurr(Value, Result) then
  999. Raise EConvertError.CreateFmt(SInvalidCurrency, [FloatToStr(Value)]);
  1000. end;
  1001. Function CurrToStr(Value: Currency): string;
  1002. begin
  1003. Result:=FloatToStrF(Value,ffNumber,15,2);
  1004. end;
  1005. function StrToCurr(const S: string): Currency;
  1006. begin
  1007. if not TextToFloat(PChar(S), Result, fvCurrency) then
  1008. Raise EConvertError.createfmt(SInValidFLoat,[S]);
  1009. end;
  1010. function StrToCurrDef(const S: string; Default : Currency): Currency;
  1011. begin
  1012. if not TextToFloat(PChar(S), Result, fvCurrency) then
  1013. Result:=Default;
  1014. end;
  1015. function StrToBool(const S: string): Boolean;
  1016. Var
  1017. Temp : String;
  1018. D : Double;
  1019. {$IFDEF VIRTUALPASCAL}
  1020. Code: longint;
  1021. {$ELSE}
  1022. Code: word;
  1023. {$ENDIF}
  1024. begin
  1025. Temp:=upcase(S);
  1026. Val(temp,D,code);
  1027. If Code=0 then
  1028. Result:=(D<>0.0)
  1029. else If Temp='TRUE' then
  1030. result:=true
  1031. else if Temp='FALSE' then
  1032. result:=false
  1033. else
  1034. Raise EConvertError.CreateFmt(SInvalidBoolean,[S]);
  1035. end;
  1036. function BoolToStr(B: Boolean): string;
  1037. begin
  1038. If B then
  1039. Result:='TRUE'
  1040. else
  1041. Result:='FALSE';
  1042. end;
  1043. Function FloatToTextFmt(Buffer: PChar; Value: Extended; format: PChar): Integer;
  1044. Var
  1045. Digits: String[40]; { String Of Digits }
  1046. Exponent: String[8]; { Exponent strin }
  1047. FmtStart, FmtStop: PChar; { Start And End Of relevant part }
  1048. { Of format String }
  1049. ExpFmt, ExpSize: Integer; { Type And Length Of }
  1050. { exponential format chosen }
  1051. Placehold: Array[1..4] Of Integer; { Number Of placeholders In All }
  1052. { four Sections }
  1053. thousand: Boolean; { thousand separators? }
  1054. UnexpectedDigits: Integer; { Number Of unexpected Digits that }
  1055. { have To be inserted before the }
  1056. { First placeholder. }
  1057. DigitExponent: Integer; { Exponent Of First digit In }
  1058. { Digits Array. }
  1059. { Find end of format section starting at P. False, if empty }
  1060. Function GetSectionEnd(Var P: PChar): Boolean;
  1061. Var
  1062. C: Char;
  1063. SQ, DQ: Boolean;
  1064. Begin
  1065. Result := False;
  1066. SQ := False;
  1067. DQ := False;
  1068. C := P[0];
  1069. While (C<>#0) And ((C<>';') Or SQ Or DQ) Do
  1070. Begin
  1071. Result := True;
  1072. Case C Of
  1073. #34: If Not SQ Then DQ := Not DQ;
  1074. #39: If Not DQ Then SQ := Not SQ;
  1075. End;
  1076. Inc(P);
  1077. C := P[0];
  1078. End;
  1079. End;
  1080. { Find start and end of format section to apply. If section doesn't exist,
  1081. use section 1. If section 2 is used, the sign of value is ignored. }
  1082. Procedure GetSectionRange(section: Integer);
  1083. Var
  1084. Sec: Array[1..3] Of PChar;
  1085. SecOk: Array[1..3] Of Boolean;
  1086. Begin
  1087. Sec[1] := format;
  1088. SecOk[1] := GetSectionEnd(Sec[1]);
  1089. If section > 1 Then
  1090. Begin
  1091. Sec[2] := Sec[1];
  1092. If Sec[2][0] <> #0 Then
  1093. Inc(Sec[2]);
  1094. SecOk[2] := GetSectionEnd(Sec[2]);
  1095. If section > 2 Then
  1096. Begin
  1097. Sec[3] := Sec[2];
  1098. If Sec[3][0] <> #0 Then
  1099. Inc(Sec[3]);
  1100. SecOk[3] := GetSectionEnd(Sec[3]);
  1101. End;
  1102. End;
  1103. If Not SecOk[1] Then
  1104. FmtStart := Nil
  1105. Else
  1106. Begin
  1107. If Not SecOk[section] Then
  1108. section := 1
  1109. Else If section = 2 Then
  1110. Value := -Value; { Remove sign }
  1111. If section = 1 Then FmtStart := format Else
  1112. Begin
  1113. FmtStart := Sec[section - 1];
  1114. Inc(FmtStart);
  1115. End;
  1116. FmtStop := Sec[section];
  1117. End;
  1118. End;
  1119. { Find format section ranging from FmtStart to FmtStop. }
  1120. Procedure GetFormatOptions;
  1121. Var
  1122. Fmt: PChar;
  1123. SQ, DQ: Boolean;
  1124. area: Integer;
  1125. Begin
  1126. SQ := False;
  1127. DQ := False;
  1128. Fmt := FmtStart;
  1129. ExpFmt := 0;
  1130. area := 1;
  1131. thousand := False;
  1132. Placehold[1] := 0;
  1133. Placehold[2] := 0;
  1134. Placehold[3] := 0;
  1135. Placehold[4] := 0;
  1136. While Fmt < FmtStop Do
  1137. Begin
  1138. Case Fmt[0] Of
  1139. #34:
  1140. Begin
  1141. If Not SQ Then
  1142. DQ := Not DQ;
  1143. Inc(Fmt);
  1144. End;
  1145. #39:
  1146. Begin
  1147. If Not DQ Then
  1148. SQ := Not SQ;
  1149. Inc(Fmt);
  1150. End;
  1151. Else
  1152. { This was 'if not SQ or DQ'. Looked wrong... }
  1153. If Not SQ Or DQ Then
  1154. Begin
  1155. Case Fmt[0] Of
  1156. '0':
  1157. Begin
  1158. Case area Of
  1159. 1:
  1160. area := 2;
  1161. 4:
  1162. Begin
  1163. area := 3;
  1164. Inc(Placehold[3], Placehold[4]);
  1165. Placehold[4] := 0;
  1166. End;
  1167. End;
  1168. Inc(Placehold[area]);
  1169. Inc(Fmt);
  1170. End;
  1171. '#':
  1172. Begin
  1173. If area=3 Then
  1174. area:=4;
  1175. Inc(Placehold[area]);
  1176. Inc(Fmt);
  1177. End;
  1178. '.':
  1179. Begin
  1180. If area<3 Then
  1181. area:=3;
  1182. Inc(Fmt);
  1183. End;
  1184. ',':
  1185. Begin
  1186. thousand := True;
  1187. Inc(Fmt);
  1188. End;
  1189. 'e', 'E':
  1190. If ExpFmt = 0 Then
  1191. Begin
  1192. If (Fmt[0]='E') Then
  1193. ExpFmt:=1
  1194. Else
  1195. ExpFmt := 3;
  1196. Inc(Fmt);
  1197. If (Fmt<FmtStop) Then
  1198. Begin
  1199. Case Fmt[0] Of
  1200. '+':
  1201. Begin
  1202. End;
  1203. '-':
  1204. Inc(ExpFmt);
  1205. Else
  1206. ExpFmt := 0;
  1207. End;
  1208. If ExpFmt <> 0 Then
  1209. Begin
  1210. Inc(Fmt);
  1211. ExpSize := 0;
  1212. While (Fmt<FmtStop) And
  1213. (ExpSize<4) And
  1214. (Fmt[0] In ['0'..'9']) Do
  1215. Begin
  1216. Inc(ExpSize);
  1217. Inc(Fmt);
  1218. End;
  1219. End;
  1220. End;
  1221. End
  1222. Else
  1223. Inc(Fmt);
  1224. Else { Case }
  1225. Inc(Fmt);
  1226. End; { Case }
  1227. End; { Begin }
  1228. End; { Case }
  1229. End; { While .. Begin }
  1230. End;
  1231. Procedure FloatToStr;
  1232. Var
  1233. I, J, Exp, Width, Decimals, DecimalPoint, len: Integer;
  1234. Begin
  1235. If ExpFmt = 0 Then
  1236. Begin
  1237. { Fixpoint }
  1238. Decimals:=Placehold[3]+Placehold[4];
  1239. Width:=Placehold[1]+Placehold[2]+Decimals;
  1240. If (Decimals=0) Then
  1241. Str(Value:Width:0,Digits)
  1242. Else
  1243. Str(Value:Width+1:Decimals,Digits);
  1244. len:=Length(Digits);
  1245. { Find the decimal point }
  1246. If (Decimals=0) Then
  1247. DecimalPoint:=len+1
  1248. Else
  1249. DecimalPoint:=len-Decimals;
  1250. { If value is very small, and no decimal places
  1251. are desired, remove the leading 0. }
  1252. If (Abs(Value) < 1) And (Placehold[2] = 0) Then
  1253. Begin
  1254. If (Placehold[1]=0) Then
  1255. Delete(Digits,DecimalPoint-1,1)
  1256. Else
  1257. Digits[DecimalPoint-1]:=' ';
  1258. End;
  1259. { Convert optional zeroes to spaces. }
  1260. I:=len;
  1261. J:=DecimalPoint+Placehold[3];
  1262. While (I>J) And (Digits[I]='0') Do
  1263. Begin
  1264. Digits[I] := ' ';
  1265. Dec(I);
  1266. End;
  1267. { If integer value and no obligatory decimal
  1268. places, remove decimal point. }
  1269. If (DecimalPoint < len) And (Digits[DecimalPoint + 1] = ' ') Then
  1270. Digits[DecimalPoint] := ' ';
  1271. { Convert spaces left from obligatory decimal point to zeroes. }
  1272. I:=DecimalPoint-Placehold[2];
  1273. While (I<DecimalPoint) And (Digits[I]=' ') Do
  1274. Begin
  1275. Digits[I] := '0';
  1276. Inc(I);
  1277. End;
  1278. Exp := 0;
  1279. End
  1280. Else
  1281. Begin
  1282. { Scientific: exactly <Width> Digits With <Precision> Decimals
  1283. And adjusted Exponent. }
  1284. If Placehold[1]+Placehold[2]=0 Then
  1285. Placehold[1]:=1;
  1286. Decimals := Placehold[3] + Placehold[4];
  1287. Width:=Placehold[1]+Placehold[2]+Decimals;
  1288. Str(Value:Width+8,Digits);
  1289. { Find and cut out exponent. Always the
  1290. last 6 characters in the string.
  1291. -> 0000E+0000 }
  1292. I:=Length(Digits)-5;
  1293. Val(Copy(Digits,I+1,5),Exp,J);
  1294. Exp:=Exp+1-(Placehold[1]+Placehold[2]);
  1295. Delete(Digits, I, 6);
  1296. { Str() always returns at least one digit after the decimal point.
  1297. If we don't want it, we have to remove it. }
  1298. If (Decimals=0) And (Placehold[1]+Placehold[2]<= 1) Then
  1299. Begin
  1300. If (Digits[4]>='5') Then
  1301. Begin
  1302. Inc(Digits[2]);
  1303. If (Digits[2]>'9') Then
  1304. Begin
  1305. Digits[2] := '1';
  1306. Inc(Exp);
  1307. End;
  1308. End;
  1309. Delete(Digits, 3, 2);
  1310. DecimalPoint := Length(Digits) + 1;
  1311. End
  1312. Else
  1313. Begin
  1314. { Move decimal point at the desired position }
  1315. Delete(Digits, 3, 1);
  1316. DecimalPoint:=2+Placehold[1]+Placehold[2];
  1317. If (Decimals<>0) Then
  1318. Insert('.',Digits,DecimalPoint);
  1319. End;
  1320. { Convert optional zeroes to spaces. }
  1321. I := Length(Digits);
  1322. J := DecimalPoint + Placehold[3];
  1323. While (I > J) And (Digits[I] = '0') Do
  1324. Begin
  1325. Digits[I] := ' ';
  1326. Dec(I);
  1327. End;
  1328. { If integer number and no obligatory decimal paces, remove decimal point }
  1329. If (DecimalPoint<Length(Digits)) And
  1330. (Digits[DecimalPoint+1]=' ') Then
  1331. Digits[DecimalPoint]:=' ';
  1332. If (Digits[1]=' ') Then
  1333. Begin
  1334. Delete(Digits, 1, 1);
  1335. Dec(DecimalPoint);
  1336. End;
  1337. { Calculate exponent string }
  1338. Str(Abs(Exp), Exponent);
  1339. While Length(Exponent)<ExpSize Do
  1340. Insert('0',Exponent,1);
  1341. If Exp >= 0 Then
  1342. Begin
  1343. If (ExpFmt In [1,3]) Then
  1344. Insert('+', Exponent, 1);
  1345. End
  1346. Else
  1347. Insert('-',Exponent,1);
  1348. If (ExpFmt<3) Then
  1349. Insert('E',Exponent,1)
  1350. Else
  1351. Insert('e',Exponent,1);
  1352. End;
  1353. DigitExponent:=DecimalPoint-2;
  1354. If (Digits[1]='-') Then
  1355. Dec(DigitExponent);
  1356. UnexpectedDigits:=DecimalPoint-1-(Placehold[1]+Placehold[2]);
  1357. End;
  1358. Function PutResult: LongInt;
  1359. Var
  1360. SQ, DQ: Boolean;
  1361. Fmt, Buf: PChar;
  1362. Dig, N: Integer;
  1363. Begin
  1364. SQ := False;
  1365. DQ := False;
  1366. Fmt := FmtStart;
  1367. Buf := Buffer;
  1368. Dig := 1;
  1369. While (Fmt<FmtStop) Do
  1370. Begin
  1371. //Write(Fmt[0]);
  1372. Case Fmt[0] Of
  1373. #34:
  1374. Begin
  1375. If Not SQ Then
  1376. DQ := Not DQ;
  1377. Inc(Fmt);
  1378. End;
  1379. #39:
  1380. Begin
  1381. If Not DQ Then
  1382. SQ := Not SQ;
  1383. Inc(Fmt);
  1384. End;
  1385. Else
  1386. If Not (SQ Or DQ) Then
  1387. Begin
  1388. Case Fmt[0] Of
  1389. '0', '#', '.':
  1390. Begin
  1391. If (Dig=1) And (UnexpectedDigits>0) Then
  1392. Begin
  1393. { Everything unexpected is written before the first digit }
  1394. For N := 1 To UnexpectedDigits Do
  1395. Begin
  1396. Buf[0] := Digits[N];
  1397. Inc(Buf);
  1398. If thousand And (Digits[N]<>'-') Then
  1399. Begin
  1400. If (DigitExponent Mod 3 = 0) And (DigitExponent>0) Then
  1401. Begin
  1402. Buf[0] := ThousandSeparator;
  1403. Inc(Buf);
  1404. End;
  1405. Dec(DigitExponent);
  1406. End;
  1407. End;
  1408. Inc(Dig, UnexpectedDigits);
  1409. End;
  1410. If (Digits[Dig]<>' ') Then
  1411. Begin
  1412. If (Digits[Dig]='.') Then
  1413. Buf[0] := DecimalSeparator
  1414. Else
  1415. Buf[0] := Digits[Dig];
  1416. Inc(Buf);
  1417. If thousand And (DigitExponent Mod 3 = 0) And (DigitExponent > 0) Then
  1418. Begin
  1419. Buf[0] := ThousandSeparator;
  1420. Inc(Buf);
  1421. End;
  1422. End;
  1423. Inc(Dig);
  1424. Dec(DigitExponent);
  1425. Inc(Fmt);
  1426. End;
  1427. 'e', 'E':
  1428. Begin
  1429. If ExpFmt <> 0 Then
  1430. Begin
  1431. Inc(Fmt);
  1432. If Fmt < FmtStop Then
  1433. Begin
  1434. If Fmt[0] In ['+', '-'] Then
  1435. Begin
  1436. Inc(Fmt, ExpSize);
  1437. For N:=1 To Length(Exponent) Do
  1438. Buf[N-1] := Exponent[N];
  1439. Inc(Buf,Length(Exponent));
  1440. ExpFmt:=0;
  1441. End;
  1442. Inc(Fmt);
  1443. End;
  1444. End
  1445. Else
  1446. Begin
  1447. { No legal exponential format.
  1448. Simply write the 'E' to the result. }
  1449. Buf[0] := Fmt[0];
  1450. Inc(Buf);
  1451. Inc(Fmt);
  1452. End;
  1453. End;
  1454. Else { Case }
  1455. { Usual character }
  1456. If (Fmt[0]<>',') Then
  1457. Begin
  1458. Buf[0] := Fmt[0];
  1459. Inc(Buf);
  1460. End;
  1461. Inc(Fmt);
  1462. End; { Case }
  1463. End
  1464. Else { IF }
  1465. Begin
  1466. { Character inside single or double quotes }
  1467. Buf[0] := Fmt[0];
  1468. Inc(Buf);
  1469. Inc(Fmt);
  1470. End;
  1471. End; { Case }
  1472. End; { While .. Begin }
  1473. Result:=PtrInt(Buf)-PtrInt(Buffer);
  1474. End;
  1475. Begin
  1476. If (Value>0) Then
  1477. GetSectionRange(1)
  1478. Else If (Value<0) Then
  1479. GetSectionRange(2)
  1480. Else
  1481. GetSectionRange(3);
  1482. If FmtStart = Nil Then
  1483. Begin
  1484. Result := FloatToText(Buffer, Value, ffGeneral, 15, 4);
  1485. End
  1486. Else
  1487. Begin
  1488. GetFormatOptions;
  1489. If (ExpFmt = 0) And (Abs(Value) >= 1E18) Then
  1490. Result := FloatToText(Buffer, Value, ffGeneral, 15, 4)
  1491. Else
  1492. Begin
  1493. FloatToStr;
  1494. Result := PutResult;
  1495. End;
  1496. End;
  1497. End;
  1498. Procedure FloatToDecimal(Var Result: TFloatRec; Value: Extended; Precision, Decimals : integer);
  1499. Var
  1500. Buffer: String[24];
  1501. Error, N: Integer;
  1502. Begin
  1503. Str(Value:23, Buffer);
  1504. Result.Negative := (Buffer[1] = '-');
  1505. Val(Copy(Buffer, 19, 5), Result.Exponent, Error);
  1506. Inc(Result. Exponent);
  1507. Result.Digits[0] := Buffer[2];
  1508. Move(Buffer[4], Result.Digits[1], 14);
  1509. If Decimals + Result.Exponent < Precision Then
  1510. N := Decimals + Result.Exponent
  1511. Else
  1512. N := Precision;
  1513. If N > 15 Then
  1514. N := 15;
  1515. If N = 0 Then
  1516. Begin
  1517. If Result.Digits[0] >= '5' Then
  1518. Begin
  1519. Result.Digits[0] := '1';
  1520. Result.Digits[1] := #0;
  1521. Inc(Result.Exponent);
  1522. End
  1523. Else
  1524. Result.Digits[0] := #0;
  1525. End
  1526. Else If N > 0 Then
  1527. Begin
  1528. If Result.Digits[N] >= '5' Then
  1529. Begin
  1530. Repeat
  1531. Result.Digits[N] := #0;
  1532. Dec(N);
  1533. Inc(Result.Digits[N]);
  1534. Until (N = 0) Or (Result.Digits[N] < ':');
  1535. If Result.Digits[0] = ':' Then
  1536. Begin
  1537. Result.Digits[0] := '1';
  1538. Inc(Result.Exponent);
  1539. End;
  1540. End
  1541. Else
  1542. Begin
  1543. Result.Digits[N] := '0';
  1544. While (Result.Digits[N] = '0') And (N > -1) Do
  1545. Begin
  1546. Result.Digits[N] := #0;
  1547. Dec(N);
  1548. End;
  1549. End;
  1550. End
  1551. Else
  1552. Result.Digits[0] := #0;
  1553. If Result.Digits[0] = #0 Then
  1554. Begin
  1555. Result.Exponent := 0;
  1556. Result.Negative := False;
  1557. End;
  1558. End;
  1559. Function FormatFloat(Const format: String; Value: Extended): String;
  1560. Var
  1561. Temp: ShortString;
  1562. buf : Array[0..1024] of char;
  1563. Begin
  1564. Buf[FloatToTextFmt(@Buf[0],Value,Pchar(Format))]:=#0;
  1565. Result:=StrPas(@Buf);
  1566. End;
  1567. {==============================================================================}
  1568. { extra functions }
  1569. {==============================================================================}
  1570. { LeftStr returns Count left-most characters from S }
  1571. function LeftStr(const S: string; Count: integer): string;
  1572. begin
  1573. result := Copy(S, 1, Count);
  1574. end ;
  1575. { RightStr returns Count right-most characters from S }
  1576. function RightStr(const S: string; Count: integer): string;
  1577. begin
  1578. If Count>Length(S) then
  1579. Count:=Length(S);
  1580. result := Copy(S, 1 + Length(S) - Count, Count);
  1581. end;
  1582. { BCDToInt converts the BCD value Value to an integer }
  1583. function BCDToInt(Value: integer): integer;
  1584. var i, j: integer;
  1585. begin
  1586. result := 0;
  1587. j := 1;
  1588. for i := 0 to SizeOf(Value) shr 1 - 1 do begin
  1589. result := result + j * (Value and 15);
  1590. j := j * 10;
  1591. Value := Value shr 4;
  1592. end ;
  1593. end ;
  1594. Function LastDelimiter(const Delimiters, S: string): Integer;
  1595. begin
  1596. Result:=Length(S);
  1597. While (Result>0) and (Pos(S[Result],Delimiters)=0) do
  1598. Dec(Result);
  1599. end;
  1600. Function StringReplace(const S, OldPattern, NewPattern: string; Flags: TReplaceFlags): string;
  1601. var
  1602. Srch,OldP,RemS: string; // Srch and Oldp can contain uppercase versions of S,OldPattern
  1603. P : Integer;
  1604. begin
  1605. Srch:=S;
  1606. OldP:=OldPattern;
  1607. if rfIgnoreCase in Flags then
  1608. begin
  1609. Srch:=UpperCase(Srch);
  1610. OldP:=UpperCase(OldP);
  1611. end;
  1612. RemS:=S;
  1613. Result:='';
  1614. while (Length(Srch)<>0) do
  1615. begin
  1616. P:=Pos(OldP, Srch);
  1617. if P=0 then
  1618. begin
  1619. Result:=Result+RemS;
  1620. Srch:='';
  1621. end
  1622. else
  1623. begin
  1624. Result:=Result+Copy(RemS,1,P-1)+NewPattern;
  1625. P:=P+Length(OldP);
  1626. RemS:=Copy(RemS,P,Length(RemS)-P+1);
  1627. if not (rfReplaceAll in Flags) then
  1628. begin
  1629. Result:=Result+RemS;
  1630. Srch:='';
  1631. end
  1632. else
  1633. Srch:=Copy(Srch,P,Length(Srch)-P+1);
  1634. end;
  1635. end;
  1636. end;
  1637. Function IsDelimiter(const Delimiters, S: string; Index: Integer): Boolean;
  1638. begin
  1639. Result:=False;
  1640. If (Index>0) and (Index<=Length(S)) then
  1641. Result:=Pos(S[Index],Delimiters)<>0; // Note we don't do MBCS yet
  1642. end;
  1643. Function ByteToCharLen(const S: string; MaxLen: Integer): Integer;
  1644. begin
  1645. Result:=Length(S);
  1646. If Result>MaxLen then
  1647. Result:=MaxLen;
  1648. end;
  1649. Function ByteToCharIndex(const S: string; Index: Integer): Integer;
  1650. begin
  1651. Result:=Index;
  1652. end;
  1653. Function CharToByteLen(const S: string; MaxLen: Integer): Integer;
  1654. begin
  1655. Result:=Length(S);
  1656. If Result>MaxLen then
  1657. Result:=MaxLen;
  1658. end;
  1659. Function CharToByteIndex(const S: string; Index: Integer): Integer;
  1660. begin
  1661. Result:=Index;
  1662. end;
  1663. Function ByteType(const S: string; Index: Integer): TMbcsByteType;
  1664. begin
  1665. Result:=mbSingleByte;
  1666. end;
  1667. Function StrByteType(Str: PChar; Index: Cardinal): TMbcsByteType;
  1668. begin
  1669. Result:=mbSingleByte;
  1670. end;
  1671. Function StrCharLength(const Str: PChar): Integer;
  1672. begin
  1673. {$ifdef HASWIDESTRING}
  1674. result:=widestringmanager.CharLengthPCharProc(Str);
  1675. {$endif HASWIDESTRING}
  1676. end;
  1677. Function FindCmdLineSwitch(const Switch: string; const Chars: TSysCharSet;IgnoreCase: Boolean): Boolean;
  1678. Var
  1679. I,L : Integer;
  1680. S,T : String;
  1681. begin
  1682. Result:=False;
  1683. S:=Switch;
  1684. If IgnoreCase then
  1685. S:=UpperCase(S);
  1686. I:=ParamCount;
  1687. While (Not Result) and (I>0) do
  1688. begin
  1689. L:=Length(Paramstr(I));
  1690. If (L>0) and (ParamStr(I)[1] in Chars) then
  1691. begin
  1692. T:=Copy(ParamStr(I),2,L-1);
  1693. If IgnoreCase then
  1694. T:=UpperCase(T);
  1695. Result:=S=T;
  1696. end;
  1697. Dec(i);
  1698. end;
  1699. end;
  1700. Function FindCmdLineSwitch(const Switch: string; IgnoreCase: Boolean): Boolean;
  1701. begin
  1702. Result:=FindCmdLineSwitch(Switch,SwitchChars,IgnoreCase);
  1703. end;
  1704. Function FindCmdLineSwitch(const Switch: string): Boolean;
  1705. begin
  1706. Result:=FindCmdLineSwitch(Switch,SwitchChars,False);
  1707. end;
  1708. function WrapText(const Line, BreakStr: string; const BreakChars: TSysCharSet; MaxCol: Integer): string;
  1709. const
  1710. Quotes = ['''', '"'];
  1711. Var
  1712. L : String;
  1713. C,LQ,BC : Char;
  1714. P,BLen,Len : Integer;
  1715. HB,IBC : Boolean;
  1716. begin
  1717. Result:='';
  1718. L:=Line;
  1719. Blen:=Length(BreakStr);
  1720. If (BLen>0) then
  1721. BC:=BreakStr[1]
  1722. else
  1723. BC:=#0;
  1724. Len:=Length(L);
  1725. While (Len>0) do
  1726. begin
  1727. P:=1;
  1728. LQ:=#0;
  1729. HB:=False;
  1730. IBC:=False;
  1731. While ((P<=Len) and ((P<=MaxCol) or not IBC)) and ((LQ<>#0) or Not HB) do
  1732. begin
  1733. C:=L[P];
  1734. If (C=LQ) then
  1735. LQ:=#0
  1736. else If (C in Quotes) then
  1737. LQ:=C;
  1738. If (LQ<>#0) then
  1739. Inc(P)
  1740. else
  1741. begin
  1742. HB:=((C=BC) and (BreakStr=Copy(L,P,BLen)));
  1743. If HB then
  1744. Inc(P,Blen)
  1745. else
  1746. begin
  1747. If (P>MaxCol) then
  1748. IBC:=C in BreakChars;
  1749. Inc(P);
  1750. end;
  1751. end;
  1752. // Writeln('"',C,'" : IBC : ',IBC,' HB : ',HB,' LQ : ',LQ,' P>MaxCol : ',P>MaxCol);
  1753. end;
  1754. Result:=Result+Copy(L,1,P-1);
  1755. If Not HB then
  1756. Result:=Result+BreakStr;
  1757. Delete(L,1,P-1);
  1758. Len:=Length(L);
  1759. end;
  1760. end;
  1761. function WrapText(const Line: string; MaxCol: Integer): string;
  1762. begin
  1763. Result:=WrapText(Line,sLineBreak, [' ', '-', #9], MaxCol);
  1764. end;
  1765. {
  1766. Case Translation Tables
  1767. Can be used in internationalization support.
  1768. Although these tables can be obtained through system calls
  1769. it is better to not use those, since most implementation are not 100%
  1770. WARNING:
  1771. before modifying a translation table make sure that the current codepage
  1772. of the OS corresponds to the one you make changes to
  1773. }
  1774. const
  1775. { upper case translation table for character set 850 }
  1776. CP850UCT: array[128..255] of char =
  1777. ('€', 'š', '�', '¶', 'Ž', '¶', '�', '€', 'Ò', 'Ó', 'Ô', 'Ø', '×', 'Þ', 'Ž', '�',
  1778. '�', '’', '’', 'â', '™', 'ã', 'ê', 'ë', 'Y', '™', 'š', '�', 'œ', '�', 'ž', 'Ÿ',
  1779. 'µ', 'Ö', 'à', 'é', '¥', '¥', '¦', '§', '¨', '©', 'ª', '«', '¬', '­', '®', '¯',
  1780. '°', '±', '²', '³', '´', 'µ', '¶', '·', '¸', '¹', 'º', '»', '¼', '½', '¾', '¿',
  1781. 'À', 'Á', 'Â', 'Ã', 'Ä', 'Å', 'Ç', 'Ç', 'È', 'É', 'Ê', 'Ë', 'Ì', 'Í', 'Î', 'Ï',
  1782. 'Ð', 'Ñ', 'Ò', 'Ó', 'Ô', 'Õ', 'Ö', '×', 'Ø', 'Ù', 'Ú', 'Û', 'Ü', 'Ý', 'Þ', 'ß',
  1783. 'à', 'á', 'â', 'ã', 'å', 'å', 'æ', 'í', 'è', 'é', 'ê', 'ë', 'í', 'í', 'î', 'ï',
  1784. 'ð', 'ñ', 'ò', 'ó', 'ô', 'õ', 'ö', '÷', 'ø', 'ù', 'ú', 'û', 'ü', 'ý', 'þ', 'ÿ');
  1785. { lower case translation table for character set 850 }
  1786. CP850LCT: array[128..255] of char =
  1787. ('‡', '�', '‚', 'ƒ', '„', '…', '†', '‡', 'ˆ', '‰', 'Š', '‹', 'Œ', '�', '„', '†',
  1788. '‚', '‘', '‘', '“', '”', '•', '–', '—', '˜', '”', '�', '›', 'œ', '›', 'ž', 'Ÿ',
  1789. ' ', '¡', '¢', '£', '¤', '¤', '¦', '§', '¨', '©', 'ª', '«', '¬', '­', '®', '¯',
  1790. '°', '±', '²', '³', '´', ' ', 'ƒ', '…', '¸', '¹', 'º', '»', '¼', '½', '¾', '¿',
  1791. 'À', 'Á', 'Â', 'Ã', 'Ä', 'Å', 'Æ', 'Æ', 'È', 'É', 'Ê', 'Ë', 'Ì', 'Í', 'Î', 'Ï',
  1792. 'Ð', 'Ñ', 'ˆ', '‰', 'Š', 'Õ', '¡', 'Œ', '‹', 'Ù', 'Ú', 'Û', 'Ü', 'Ý', '�', 'ß',
  1793. '¢', 'á', '“', '•', 'ä', 'ä', 'æ', 'í', 'è', '£', '–', '—', 'ì', 'ì', 'î', 'ï',
  1794. 'ð', 'ñ', 'ò', 'ó', 'ô', 'õ', 'ö', '÷', 'ø', 'ù', 'ú', 'û', 'ü', 'ý', 'þ', 'ÿ');
  1795. { upper case translation table for character set ISO 8859/1 Latin 1 }
  1796. CPISO88591UCT: array[192..255] of char =
  1797. ( #192, #193, #194, #195, #196, #197, #198, #199,
  1798. #200, #201, #202, #203, #204, #205, #206, #207,
  1799. #208, #209, #210, #211, #212, #213, #214, #215,
  1800. #216, #217, #218, #219, #220, #221, #222, #223,
  1801. #192, #193, #194, #195, #196, #197, #198, #199,
  1802. #200, #201, #202, #203, #204, #205, #206, #207,
  1803. #208, #209, #210, #211, #212, #213, #214, #247,
  1804. #216, #217, #218, #219, #220, #221, #222, #89 );
  1805. { lower case translation table for character set ISO 8859/1 Latin 1 }
  1806. CPISO88591LCT: array[192..255] of char =
  1807. ( #224, #225, #226, #227, #228, #229, #230, #231,
  1808. #232, #233, #234, #235, #236, #237, #238, #239,
  1809. #240, #241, #242, #243, #244, #245, #246, #215,
  1810. #248, #249, #250, #251, #252, #253, #254, #223,
  1811. #224, #225, #226, #227, #228, #229, #230, #231,
  1812. #232, #233, #234, #235, #236, #237, #238, #239,
  1813. #240, #241, #242, #243, #244, #245, #246, #247,
  1814. #248, #249, #250, #251, #252, #253, #254, #255 );
  1815. {
  1816. $Log$
  1817. Revision 1.34 2005-03-13 14:30:24 marco
  1818. * some 1.0.x fixes
  1819. Revision 1.33 2005/03/12 14:56:22 florian
  1820. + added Ansi* routines to widestring manager
  1821. * made them using OS calls on windows
  1822. Revision 1.32 2005/03/01 19:23:03 jonas
  1823. * fixed newstr() and disposestr()
  1824. Revision 1.31 2005/02/28 11:12:17 jonas
  1825. * fixed web bug 3708
  1826. Revision 1.30 2005/02/26 10:21:17 florian
  1827. + implemented WideFormat
  1828. + some Widestring stuff implemented
  1829. * some Widestring stuff fixed
  1830. Revision 1.29 2005/02/14 17:13:31 peter
  1831. * truncate log
  1832. Revision 1.28 2005/02/07 08:29:00 michael
  1833. + Patch from peter to fix 1.0 compile
  1834. Revision 1.27 2005/02/06 09:38:45 florian
  1835. + StrCharLength infrastructure
  1836. Revision 1.26 2005/01/17 18:38:48 peter
  1837. * extended overload disabled for powerpc
  1838. Revision 1.25 2005/01/16 17:53:27 michael
  1839. + Patch from Colin Western to implemenet TryStrToFLoat
  1840. }