sysstr.inc 52 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156
  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
  474. P,Q,R: PChar;
  475. begin
  476. P := Src;
  477. Q := StrEnd(P);
  478. result:='';
  479. if P=Q then exit;
  480. if P^<>quote then exit;
  481. inc(p);
  482. setlength(result,(Q-P)+1);
  483. R:=@Result[1];
  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(trim(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. Begin
  796. S:=StrPas(Buffer);
  797. P:=Pos(ThousandSeparator,S);
  798. While (P<>0) do
  799. begin
  800. Delete(S,P,1);
  801. P:=Pos(ThousandSeparator,S);
  802. end;
  803. P:=Pos(DecimalSeparator,S);
  804. If (P<>0) Then
  805. S[P] := '.';
  806. case ValueType of
  807. fvCurrency:
  808. Val(S,Currency(Value),E);
  809. fvExtended:
  810. Val(S,Extended(Value),E);
  811. fvDouble:
  812. Val(S,Double(Value),E);
  813. fvSingle:
  814. Val(S,Single(Value),E);
  815. fvComp:
  816. Val(S,Comp(Value),E);
  817. fvReal:
  818. Val(S,Real(Value),E);
  819. end;
  820. Result:=(E=0);
  821. End;
  822. Function TryStrToFloat(Const S : String; Var Value: Single): Boolean;
  823. Begin
  824. Result := TextToFloat(PChar(S), Value, fvSingle);
  825. End;
  826. Function TryStrToFloat(Const S : String; Var Value: Double): Boolean;
  827. Begin
  828. Result := TextToFloat(PChar(S), Value, fvDouble);
  829. End;
  830. {$ifdef FPC_HAS_TYPE_EXTENDED}
  831. Function TryStrToFloat(Const S : String; Var Value: Extended): Boolean;
  832. Begin
  833. Result := TextToFloat(PChar(S), Value);
  834. End;
  835. {$endif FPC_HAS_TYPE_EXTENDED}
  836. Function FloatToStr(Value: Extended): String;
  837. Begin
  838. Result := FloatToStrF(Value, ffGeneral, 15, 0);
  839. End;
  840. Function FloatToText(Buffer: PChar; Value: Extended; format: TFloatFormat; Precision, Digits: Integer): Longint;
  841. Var
  842. Tmp: String[40];
  843. Begin
  844. Tmp := FloatToStrF(Value, format, Precision, Digits);
  845. Result := Length(Tmp);
  846. Move(Tmp[1], Buffer[0], Result);
  847. End;
  848. Function FloatToStrF(Value: Extended; format: TFloatFormat; Precision, Digits: Integer): String;
  849. Var
  850. P: Integer;
  851. Negative, TooSmall, TooLarge: Boolean;
  852. Begin
  853. Case format Of
  854. ffGeneral:
  855. Begin
  856. If (Precision = -1) Or (Precision > 15) Then Precision := 15;
  857. TooSmall := (Abs(Value) < 0.00001) and (Value>0.0);
  858. If Not TooSmall Then
  859. Begin
  860. Str(Value:digits:precision, Result);
  861. P := Pos('.', Result);
  862. if P<>0 then
  863. Result[P] := DecimalSeparator;
  864. TooLarge := P > Precision + 1;
  865. End;
  866. If TooSmall Or TooLarge Then
  867. begin
  868. Result := FloatToStrF(Value, ffExponent, Precision, Digits);
  869. // Strip unneeded zeroes.
  870. P:=Pos('E',result)-1;
  871. If P<>-1 then
  872. While (P>1) and (Result[P]='0') do
  873. begin
  874. system.Delete(Result,P,1);
  875. Dec(P);
  876. end;
  877. end
  878. else if (P<>0) then // we have a decimalseparator
  879. begin
  880. P := Length(Result);
  881. While (P>0) and (Result[P] = '0') Do
  882. Dec(P);
  883. If (P>0) and (Result[P]=DecimalSeparator) Then
  884. Dec(P);
  885. SetLength(Result, P);
  886. end;
  887. End;
  888. ffExponent:
  889. Begin
  890. If (Precision = -1) Or (Precision > 15) Then Precision := 15;
  891. Str(Value:Precision + 8, Result);
  892. Result[3] := DecimalSeparator;
  893. P:=4;
  894. While (P>0) and (Digits < P) And (Result[Precision + 5] = '0') do
  895. Begin
  896. If P<>1 then
  897. system.Delete(Result, Precision + 5, 1)
  898. else
  899. system.Delete(Result, Precision + 3, 3);
  900. Dec(P);
  901. end;
  902. If Result[1] = ' ' Then
  903. System.Delete(Result, 1, 1);
  904. End;
  905. ffFixed:
  906. Begin
  907. If Digits = -1 Then Digits := 2
  908. Else If Digits > 18 Then Digits := 18;
  909. Str(Value:0:Digits, Result);
  910. If Result[1] = ' ' Then
  911. System.Delete(Result, 1, 1);
  912. P := Pos('.', Result);
  913. If P <> 0 Then Result[P] := DecimalSeparator;
  914. End;
  915. ffNumber:
  916. Begin
  917. If Digits = -1 Then Digits := 2
  918. Else If Digits > 15 Then Digits := 15;
  919. Str(Value:0:Digits, Result);
  920. If Result[1] = ' ' Then System.Delete(Result, 1, 1);
  921. P := Pos('.', Result);
  922. If P <> 0 Then
  923. Result[P] := DecimalSeparator
  924. else
  925. P := Length(Result)+1;
  926. Dec(P, 3);
  927. While (P > 1) Do
  928. Begin
  929. If Result[P - 1] <> '-' Then Insert(ThousandSeparator, Result, P);
  930. Dec(P, 3);
  931. End;
  932. End;
  933. ffCurrency:
  934. Begin
  935. If Value < 0 Then
  936. Begin
  937. Negative := True;
  938. Value := -Value;
  939. End
  940. Else Negative := False;
  941. If Digits = -1 Then Digits := CurrencyDecimals
  942. Else If Digits > 18 Then Digits := 18;
  943. Str(Value:0:Digits, Result);
  944. If Result[1] = ' ' Then System.Delete(Result, 1, 1);
  945. P := Pos('.', Result);
  946. If P <> 0 Then Result[P] := DecimalSeparator;
  947. Dec(P, 3);
  948. While (P > 1) Do
  949. Begin
  950. Insert(ThousandSeparator, Result, P);
  951. Dec(P, 3);
  952. End;
  953. If Not Negative Then
  954. Begin
  955. Case CurrencyFormat Of
  956. 0: Result := CurrencyString + Result;
  957. 1: Result := Result + CurrencyString;
  958. 2: Result := CurrencyString + ' ' + Result;
  959. 3: Result := Result + ' ' + CurrencyString;
  960. End
  961. End
  962. Else
  963. Begin
  964. Case NegCurrFormat Of
  965. 0: Result := '(' + CurrencyString + Result + ')';
  966. 1: Result := '-' + CurrencyString + Result;
  967. 2: Result := CurrencyString + '-' + Result;
  968. 3: Result := CurrencyString + Result + '-';
  969. 4: Result := '(' + Result + CurrencyString + ')';
  970. 5: Result := '-' + Result + CurrencyString;
  971. 6: Result := Result + '-' + CurrencyString;
  972. 7: Result := Result + CurrencyString + '-';
  973. 8: Result := '-' + Result + ' ' + CurrencyString;
  974. 9: Result := '-' + CurrencyString + ' ' + Result;
  975. 10: Result := CurrencyString + ' ' + Result + '-';
  976. End;
  977. End;
  978. End;
  979. End;
  980. End;
  981. Function FloatToDateTime (Const Value : Extended) : TDateTime;
  982. begin
  983. If (Value<MinDateTime) or (Value>MaxDateTime) then
  984. Raise EConvertError.CreateFmt (SInvalidDateTime,[Value]);
  985. Result:=Value;
  986. end;
  987. function TryFloatToCurr(const Value: Extended; var AResult: Currency): Boolean;
  988. begin
  989. {$ifndef VER1_0}
  990. Result:=(Value>=MinCurrency) and (Value<=MaxCurrency);
  991. if Result then
  992. AResult := Value;
  993. {$else VER1_0}
  994. Result:=false;
  995. {$endif VER1_0}
  996. end;
  997. function FloatToCurr(const Value: Extended): Currency;
  998. begin
  999. if not TryFloatToCurr(Value, Result) then
  1000. Raise EConvertError.CreateFmt(SInvalidCurrency, [FloatToStr(Value)]);
  1001. end;
  1002. Function CurrToStr(Value: Currency): string;
  1003. begin
  1004. Result:=FloatToStrF(Value,ffNumber,15,2);
  1005. end;
  1006. function StrToCurr(const S: string): Currency;
  1007. begin
  1008. if not TextToFloat(PChar(S), Result, fvCurrency) then
  1009. Raise EConvertError.createfmt(SInValidFLoat,[S]);
  1010. end;
  1011. Function TryStrToCurr(Const S : String; Var Value: Currency): Boolean;
  1012. Begin
  1013. Result := TextToFloat(PChar(S), Value, fvCurrency);
  1014. End;
  1015. function StrToCurrDef(const S: string; Default : Currency): Currency;
  1016. begin
  1017. if not TextToFloat(PChar(S), Result, fvCurrency) then
  1018. Result:=Default;
  1019. end;
  1020. function StrToBool(const S: string): Boolean;
  1021. Var
  1022. Temp : String;
  1023. D : Double;
  1024. {$IFDEF VIRTUALPASCAL}
  1025. Code: longint;
  1026. {$ELSE}
  1027. Code: word;
  1028. {$ENDIF}
  1029. begin
  1030. Temp:=upcase(S);
  1031. Val(temp,D,code);
  1032. If Code=0 then
  1033. Result:=(D<>0.0)
  1034. else If Temp='TRUE' then
  1035. result:=true
  1036. else if Temp='FALSE' then
  1037. result:=false
  1038. else
  1039. Raise EConvertError.CreateFmt(SInvalidBoolean,[S]);
  1040. end;
  1041. function BoolToStr(B: Boolean): string;
  1042. begin
  1043. If B then
  1044. Result:='TRUE'
  1045. else
  1046. Result:='FALSE';
  1047. end;
  1048. Function FloatToTextFmt(Buffer: PChar; Value: Extended; format: PChar): Integer;
  1049. Var
  1050. Digits: String[40]; { String Of Digits }
  1051. Exponent: String[8]; { Exponent strin }
  1052. FmtStart, FmtStop: PChar; { Start And End Of relevant part }
  1053. { Of format String }
  1054. ExpFmt, ExpSize: Integer; { Type And Length Of }
  1055. { exponential format chosen }
  1056. Placehold: Array[1..4] Of Integer; { Number Of placeholders In All }
  1057. { four Sections }
  1058. thousand: Boolean; { thousand separators? }
  1059. UnexpectedDigits: Integer; { Number Of unexpected Digits that }
  1060. { have To be inserted before the }
  1061. { First placeholder. }
  1062. DigitExponent: Integer; { Exponent Of First digit In }
  1063. { Digits Array. }
  1064. { Find end of format section starting at P. False, if empty }
  1065. Function GetSectionEnd(Var P: PChar): Boolean;
  1066. Var
  1067. C: Char;
  1068. SQ, DQ: Boolean;
  1069. Begin
  1070. Result := False;
  1071. SQ := False;
  1072. DQ := False;
  1073. C := P[0];
  1074. While (C<>#0) And ((C<>';') Or SQ Or DQ) Do
  1075. Begin
  1076. Result := True;
  1077. Case C Of
  1078. #34: If Not SQ Then DQ := Not DQ;
  1079. #39: If Not DQ Then SQ := Not SQ;
  1080. End;
  1081. Inc(P);
  1082. C := P[0];
  1083. End;
  1084. End;
  1085. { Find start and end of format section to apply. If section doesn't exist,
  1086. use section 1. If section 2 is used, the sign of value is ignored. }
  1087. Procedure GetSectionRange(section: Integer);
  1088. Var
  1089. Sec: Array[1..3] Of PChar;
  1090. SecOk: Array[1..3] Of Boolean;
  1091. Begin
  1092. Sec[1] := format;
  1093. SecOk[1] := GetSectionEnd(Sec[1]);
  1094. If section > 1 Then
  1095. Begin
  1096. Sec[2] := Sec[1];
  1097. If Sec[2][0] <> #0 Then
  1098. Inc(Sec[2]);
  1099. SecOk[2] := GetSectionEnd(Sec[2]);
  1100. If section > 2 Then
  1101. Begin
  1102. Sec[3] := Sec[2];
  1103. If Sec[3][0] <> #0 Then
  1104. Inc(Sec[3]);
  1105. SecOk[3] := GetSectionEnd(Sec[3]);
  1106. End;
  1107. End;
  1108. If Not SecOk[1] Then
  1109. FmtStart := Nil
  1110. Else
  1111. Begin
  1112. If Not SecOk[section] Then
  1113. section := 1
  1114. Else If section = 2 Then
  1115. Value := -Value; { Remove sign }
  1116. If section = 1 Then FmtStart := format Else
  1117. Begin
  1118. FmtStart := Sec[section - 1];
  1119. Inc(FmtStart);
  1120. End;
  1121. FmtStop := Sec[section];
  1122. End;
  1123. End;
  1124. { Find format section ranging from FmtStart to FmtStop. }
  1125. Procedure GetFormatOptions;
  1126. Var
  1127. Fmt: PChar;
  1128. SQ, DQ: Boolean;
  1129. area: Integer;
  1130. Begin
  1131. SQ := False;
  1132. DQ := False;
  1133. Fmt := FmtStart;
  1134. ExpFmt := 0;
  1135. area := 1;
  1136. thousand := False;
  1137. Placehold[1] := 0;
  1138. Placehold[2] := 0;
  1139. Placehold[3] := 0;
  1140. Placehold[4] := 0;
  1141. While Fmt < FmtStop Do
  1142. Begin
  1143. Case Fmt[0] Of
  1144. #34:
  1145. Begin
  1146. If Not SQ Then
  1147. DQ := Not DQ;
  1148. Inc(Fmt);
  1149. End;
  1150. #39:
  1151. Begin
  1152. If Not DQ Then
  1153. SQ := Not SQ;
  1154. Inc(Fmt);
  1155. End;
  1156. Else
  1157. { This was 'if not SQ or DQ'. Looked wrong... }
  1158. If Not SQ Or DQ Then
  1159. Begin
  1160. Case Fmt[0] Of
  1161. '0':
  1162. Begin
  1163. Case area Of
  1164. 1:
  1165. area := 2;
  1166. 4:
  1167. Begin
  1168. area := 3;
  1169. Inc(Placehold[3], Placehold[4]);
  1170. Placehold[4] := 0;
  1171. End;
  1172. End;
  1173. Inc(Placehold[area]);
  1174. Inc(Fmt);
  1175. End;
  1176. '#':
  1177. Begin
  1178. If area=3 Then
  1179. area:=4;
  1180. Inc(Placehold[area]);
  1181. Inc(Fmt);
  1182. End;
  1183. '.':
  1184. Begin
  1185. If area<3 Then
  1186. area:=3;
  1187. Inc(Fmt);
  1188. End;
  1189. ',':
  1190. Begin
  1191. thousand := True;
  1192. Inc(Fmt);
  1193. End;
  1194. 'e', 'E':
  1195. If ExpFmt = 0 Then
  1196. Begin
  1197. If (Fmt[0]='E') Then
  1198. ExpFmt:=1
  1199. Else
  1200. ExpFmt := 3;
  1201. Inc(Fmt);
  1202. If (Fmt<FmtStop) Then
  1203. Begin
  1204. Case Fmt[0] Of
  1205. '+':
  1206. Begin
  1207. End;
  1208. '-':
  1209. Inc(ExpFmt);
  1210. Else
  1211. ExpFmt := 0;
  1212. End;
  1213. If ExpFmt <> 0 Then
  1214. Begin
  1215. Inc(Fmt);
  1216. ExpSize := 0;
  1217. While (Fmt<FmtStop) And
  1218. (ExpSize<4) And
  1219. (Fmt[0] In ['0'..'9']) Do
  1220. Begin
  1221. Inc(ExpSize);
  1222. Inc(Fmt);
  1223. End;
  1224. End;
  1225. End;
  1226. End
  1227. Else
  1228. Inc(Fmt);
  1229. Else { Case }
  1230. Inc(Fmt);
  1231. End; { Case }
  1232. End; { Begin }
  1233. End; { Case }
  1234. End; { While .. Begin }
  1235. End;
  1236. Procedure FloatToStr;
  1237. Var
  1238. I, J, Exp, Width, Decimals, DecimalPoint, len: Integer;
  1239. Begin
  1240. If ExpFmt = 0 Then
  1241. Begin
  1242. { Fixpoint }
  1243. Decimals:=Placehold[3]+Placehold[4];
  1244. Width:=Placehold[1]+Placehold[2]+Decimals;
  1245. If (Decimals=0) Then
  1246. Str(Value:Width:0,Digits)
  1247. Else
  1248. Str(Value:Width+1:Decimals,Digits);
  1249. len:=Length(Digits);
  1250. { Find the decimal point }
  1251. If (Decimals=0) Then
  1252. DecimalPoint:=len+1
  1253. Else
  1254. DecimalPoint:=len-Decimals;
  1255. { If value is very small, and no decimal places
  1256. are desired, remove the leading 0. }
  1257. If (Abs(Value) < 1) And (Placehold[2] = 0) Then
  1258. Begin
  1259. If (Placehold[1]=0) Then
  1260. Delete(Digits,DecimalPoint-1,1)
  1261. Else
  1262. Digits[DecimalPoint-1]:=' ';
  1263. End;
  1264. { Convert optional zeroes to spaces. }
  1265. I:=len;
  1266. J:=DecimalPoint+Placehold[3];
  1267. While (I>J) And (Digits[I]='0') Do
  1268. Begin
  1269. Digits[I] := ' ';
  1270. Dec(I);
  1271. End;
  1272. { If integer value and no obligatory decimal
  1273. places, remove decimal point. }
  1274. If (DecimalPoint < len) And (Digits[DecimalPoint + 1] = ' ') Then
  1275. Digits[DecimalPoint] := ' ';
  1276. { Convert spaces left from obligatory decimal point to zeroes. }
  1277. I:=DecimalPoint-Placehold[2];
  1278. While (I<DecimalPoint) And (Digits[I]=' ') Do
  1279. Begin
  1280. Digits[I] := '0';
  1281. Inc(I);
  1282. End;
  1283. Exp := 0;
  1284. End
  1285. Else
  1286. Begin
  1287. { Scientific: exactly <Width> Digits With <Precision> Decimals
  1288. And adjusted Exponent. }
  1289. If Placehold[1]+Placehold[2]=0 Then
  1290. Placehold[1]:=1;
  1291. Decimals := Placehold[3] + Placehold[4];
  1292. Width:=Placehold[1]+Placehold[2]+Decimals;
  1293. Str(Value:Width+8,Digits);
  1294. { Find and cut out exponent. Always the
  1295. last 6 characters in the string.
  1296. -> 0000E+0000 }
  1297. I:=Length(Digits)-5;
  1298. Val(Copy(Digits,I+1,5),Exp,J);
  1299. Exp:=Exp+1-(Placehold[1]+Placehold[2]);
  1300. Delete(Digits, I, 6);
  1301. { Str() always returns at least one digit after the decimal point.
  1302. If we don't want it, we have to remove it. }
  1303. If (Decimals=0) And (Placehold[1]+Placehold[2]<= 1) Then
  1304. Begin
  1305. If (Digits[4]>='5') Then
  1306. Begin
  1307. Inc(Digits[2]);
  1308. If (Digits[2]>'9') Then
  1309. Begin
  1310. Digits[2] := '1';
  1311. Inc(Exp);
  1312. End;
  1313. End;
  1314. Delete(Digits, 3, 2);
  1315. DecimalPoint := Length(Digits) + 1;
  1316. End
  1317. Else
  1318. Begin
  1319. { Move decimal point at the desired position }
  1320. Delete(Digits, 3, 1);
  1321. DecimalPoint:=2+Placehold[1]+Placehold[2];
  1322. If (Decimals<>0) Then
  1323. Insert('.',Digits,DecimalPoint);
  1324. End;
  1325. { Convert optional zeroes to spaces. }
  1326. I := Length(Digits);
  1327. J := DecimalPoint + Placehold[3];
  1328. While (I > J) And (Digits[I] = '0') Do
  1329. Begin
  1330. Digits[I] := ' ';
  1331. Dec(I);
  1332. End;
  1333. { If integer number and no obligatory decimal paces, remove decimal point }
  1334. If (DecimalPoint<Length(Digits)) And
  1335. (Digits[DecimalPoint+1]=' ') Then
  1336. Digits[DecimalPoint]:=' ';
  1337. If (Digits[1]=' ') Then
  1338. Begin
  1339. Delete(Digits, 1, 1);
  1340. Dec(DecimalPoint);
  1341. End;
  1342. { Calculate exponent string }
  1343. Str(Abs(Exp), Exponent);
  1344. While Length(Exponent)<ExpSize Do
  1345. Insert('0',Exponent,1);
  1346. If Exp >= 0 Then
  1347. Begin
  1348. If (ExpFmt In [1,3]) Then
  1349. Insert('+', Exponent, 1);
  1350. End
  1351. Else
  1352. Insert('-',Exponent,1);
  1353. If (ExpFmt<3) Then
  1354. Insert('E',Exponent,1)
  1355. Else
  1356. Insert('e',Exponent,1);
  1357. End;
  1358. DigitExponent:=DecimalPoint-2;
  1359. If (Digits[1]='-') Then
  1360. Dec(DigitExponent);
  1361. UnexpectedDigits:=DecimalPoint-1-(Placehold[1]+Placehold[2]);
  1362. End;
  1363. Function PutResult: LongInt;
  1364. Var
  1365. SQ, DQ: Boolean;
  1366. Fmt, Buf: PChar;
  1367. Dig, N: Integer;
  1368. Begin
  1369. SQ := False;
  1370. DQ := False;
  1371. Fmt := FmtStart;
  1372. Buf := Buffer;
  1373. Dig := 1;
  1374. While (Fmt<FmtStop) Do
  1375. Begin
  1376. //Write(Fmt[0]);
  1377. Case Fmt[0] Of
  1378. #34:
  1379. Begin
  1380. If Not SQ Then
  1381. DQ := Not DQ;
  1382. Inc(Fmt);
  1383. End;
  1384. #39:
  1385. Begin
  1386. If Not DQ Then
  1387. SQ := Not SQ;
  1388. Inc(Fmt);
  1389. End;
  1390. Else
  1391. If Not (SQ Or DQ) Then
  1392. Begin
  1393. Case Fmt[0] Of
  1394. '0', '#', '.':
  1395. Begin
  1396. If (Dig=1) And (UnexpectedDigits>0) Then
  1397. Begin
  1398. { Everything unexpected is written before the first digit }
  1399. For N := 1 To UnexpectedDigits Do
  1400. Begin
  1401. Buf[0] := Digits[N];
  1402. Inc(Buf);
  1403. If thousand And (Digits[N]<>'-') Then
  1404. Begin
  1405. If (DigitExponent Mod 3 = 0) And (DigitExponent>0) Then
  1406. Begin
  1407. Buf[0] := ThousandSeparator;
  1408. Inc(Buf);
  1409. End;
  1410. Dec(DigitExponent);
  1411. End;
  1412. End;
  1413. Inc(Dig, UnexpectedDigits);
  1414. End;
  1415. If (Digits[Dig]<>' ') Then
  1416. Begin
  1417. If (Digits[Dig]='.') Then
  1418. Buf[0] := DecimalSeparator
  1419. Else
  1420. Buf[0] := Digits[Dig];
  1421. Inc(Buf);
  1422. If thousand And (DigitExponent Mod 3 = 0) And (DigitExponent > 0) Then
  1423. Begin
  1424. Buf[0] := ThousandSeparator;
  1425. Inc(Buf);
  1426. End;
  1427. End;
  1428. Inc(Dig);
  1429. Dec(DigitExponent);
  1430. Inc(Fmt);
  1431. End;
  1432. 'e', 'E':
  1433. Begin
  1434. If ExpFmt <> 0 Then
  1435. Begin
  1436. Inc(Fmt);
  1437. If Fmt < FmtStop Then
  1438. Begin
  1439. If Fmt[0] In ['+', '-'] Then
  1440. Begin
  1441. Inc(Fmt, ExpSize);
  1442. For N:=1 To Length(Exponent) Do
  1443. Buf[N-1] := Exponent[N];
  1444. Inc(Buf,Length(Exponent));
  1445. ExpFmt:=0;
  1446. End;
  1447. Inc(Fmt);
  1448. End;
  1449. End
  1450. Else
  1451. Begin
  1452. { No legal exponential format.
  1453. Simply write the 'E' to the result. }
  1454. Buf[0] := Fmt[0];
  1455. Inc(Buf);
  1456. Inc(Fmt);
  1457. End;
  1458. End;
  1459. Else { Case }
  1460. { Usual character }
  1461. If (Fmt[0]<>',') Then
  1462. Begin
  1463. Buf[0] := Fmt[0];
  1464. Inc(Buf);
  1465. End;
  1466. Inc(Fmt);
  1467. End; { Case }
  1468. End
  1469. Else { IF }
  1470. Begin
  1471. { Character inside single or double quotes }
  1472. Buf[0] := Fmt[0];
  1473. Inc(Buf);
  1474. Inc(Fmt);
  1475. End;
  1476. End; { Case }
  1477. End; { While .. Begin }
  1478. Result:=PtrInt(Buf)-PtrInt(Buffer);
  1479. End;
  1480. Begin
  1481. If (Value>0) Then
  1482. GetSectionRange(1)
  1483. Else If (Value<0) Then
  1484. GetSectionRange(2)
  1485. Else
  1486. GetSectionRange(3);
  1487. If FmtStart = Nil Then
  1488. Begin
  1489. Result := FloatToText(Buffer, Value, ffGeneral, 15, 4);
  1490. End
  1491. Else
  1492. Begin
  1493. GetFormatOptions;
  1494. If (ExpFmt = 0) And (Abs(Value) >= 1E18) Then
  1495. Result := FloatToText(Buffer, Value, ffGeneral, 15, 4)
  1496. Else
  1497. Begin
  1498. FloatToStr;
  1499. Result := PutResult;
  1500. End;
  1501. End;
  1502. End;
  1503. Procedure FloatToDecimal(Var Result: TFloatRec; Value: Extended; Precision, Decimals : integer);
  1504. Var
  1505. Buffer: String[24];
  1506. Error, N: Integer;
  1507. Begin
  1508. Str(Value:23, Buffer);
  1509. Result.Negative := (Buffer[1] = '-');
  1510. Val(Copy(Buffer, 19, 5), Result.Exponent, Error);
  1511. Inc(Result. Exponent);
  1512. Result.Digits[0] := Buffer[2];
  1513. Move(Buffer[4], Result.Digits[1], 14);
  1514. If Decimals + Result.Exponent < Precision Then
  1515. N := Decimals + Result.Exponent
  1516. Else
  1517. N := Precision;
  1518. If N > 15 Then
  1519. N := 15;
  1520. If N = 0 Then
  1521. Begin
  1522. If Result.Digits[0] >= '5' Then
  1523. Begin
  1524. Result.Digits[0] := '1';
  1525. Result.Digits[1] := #0;
  1526. Inc(Result.Exponent);
  1527. End
  1528. Else
  1529. Result.Digits[0] := #0;
  1530. End
  1531. Else If N > 0 Then
  1532. Begin
  1533. If Result.Digits[N] >= '5' Then
  1534. Begin
  1535. Repeat
  1536. Result.Digits[N] := #0;
  1537. Dec(N);
  1538. Inc(Result.Digits[N]);
  1539. Until (N = 0) Or (Result.Digits[N] < ':');
  1540. If Result.Digits[0] = ':' Then
  1541. Begin
  1542. Result.Digits[0] := '1';
  1543. Inc(Result.Exponent);
  1544. End;
  1545. End
  1546. Else
  1547. Begin
  1548. Result.Digits[N] := '0';
  1549. While (Result.Digits[N] = '0') And (N > -1) Do
  1550. Begin
  1551. Result.Digits[N] := #0;
  1552. Dec(N);
  1553. End;
  1554. End;
  1555. End
  1556. Else
  1557. Result.Digits[0] := #0;
  1558. If Result.Digits[0] = #0 Then
  1559. Begin
  1560. Result.Exponent := 0;
  1561. Result.Negative := False;
  1562. End;
  1563. End;
  1564. Function FormatFloat(Const format: String; Value: Extended): String;
  1565. Var
  1566. buf : Array[0..1024] of char;
  1567. Begin
  1568. Buf[FloatToTextFmt(@Buf[0],Value,Pchar(Format))]:=#0;
  1569. Result:=StrPas(@Buf);
  1570. End;
  1571. function FormatCurr(const Format: string; Value: Currency): string;
  1572. begin
  1573. Result := FormatFloat(Format, Value);
  1574. end;
  1575. {==============================================================================}
  1576. { extra functions }
  1577. {==============================================================================}
  1578. { LeftStr returns Count left-most characters from S }
  1579. function LeftStr(const S: string; Count: integer): string;
  1580. begin
  1581. result := Copy(S, 1, Count);
  1582. end ;
  1583. { RightStr returns Count right-most characters from S }
  1584. function RightStr(const S: string; Count: integer): string;
  1585. begin
  1586. If Count>Length(S) then
  1587. Count:=Length(S);
  1588. result := Copy(S, 1 + Length(S) - Count, Count);
  1589. end;
  1590. { BCDToInt converts the BCD value Value to an integer }
  1591. function BCDToInt(Value: integer): integer;
  1592. var i, j: integer;
  1593. begin
  1594. result := 0;
  1595. j := 1;
  1596. for i := 0 to SizeOf(Value) shr 1 - 1 do begin
  1597. result := result + j * (Value and 15);
  1598. j := j * 10;
  1599. Value := Value shr 4;
  1600. end ;
  1601. end ;
  1602. Function LastDelimiter(const Delimiters, S: string): Integer;
  1603. begin
  1604. Result:=Length(S);
  1605. While (Result>0) and (Pos(S[Result],Delimiters)=0) do
  1606. Dec(Result);
  1607. end;
  1608. Function StringReplace(const S, OldPattern, NewPattern: string; Flags: TReplaceFlags): string;
  1609. var
  1610. Srch,OldP,RemS: string; // Srch and Oldp can contain uppercase versions of S,OldPattern
  1611. P : Integer;
  1612. begin
  1613. Srch:=S;
  1614. OldP:=OldPattern;
  1615. if rfIgnoreCase in Flags then
  1616. begin
  1617. Srch:=UpperCase(Srch);
  1618. OldP:=UpperCase(OldP);
  1619. end;
  1620. RemS:=S;
  1621. Result:='';
  1622. while (Length(Srch)<>0) do
  1623. begin
  1624. P:=Pos(OldP, Srch);
  1625. if P=0 then
  1626. begin
  1627. Result:=Result+RemS;
  1628. Srch:='';
  1629. end
  1630. else
  1631. begin
  1632. Result:=Result+Copy(RemS,1,P-1)+NewPattern;
  1633. P:=P+Length(OldP);
  1634. RemS:=Copy(RemS,P,Length(RemS)-P+1);
  1635. if not (rfReplaceAll in Flags) then
  1636. begin
  1637. Result:=Result+RemS;
  1638. Srch:='';
  1639. end
  1640. else
  1641. Srch:=Copy(Srch,P,Length(Srch)-P+1);
  1642. end;
  1643. end;
  1644. end;
  1645. Function IsDelimiter(const Delimiters, S: string; Index: Integer): Boolean;
  1646. begin
  1647. Result:=False;
  1648. If (Index>0) and (Index<=Length(S)) then
  1649. Result:=Pos(S[Index],Delimiters)<>0; // Note we don't do MBCS yet
  1650. end;
  1651. Function ByteToCharLen(const S: string; MaxLen: Integer): Integer;
  1652. begin
  1653. Result:=Length(S);
  1654. If Result>MaxLen then
  1655. Result:=MaxLen;
  1656. end;
  1657. Function ByteToCharIndex(const S: string; Index: Integer): Integer;
  1658. begin
  1659. Result:=Index;
  1660. end;
  1661. Function CharToByteLen(const S: string; MaxLen: Integer): Integer;
  1662. begin
  1663. Result:=Length(S);
  1664. If Result>MaxLen then
  1665. Result:=MaxLen;
  1666. end;
  1667. Function CharToByteIndex(const S: string; Index: Integer): Integer;
  1668. begin
  1669. Result:=Index;
  1670. end;
  1671. Function ByteType(const S: string; Index: Integer): TMbcsByteType;
  1672. begin
  1673. Result:=mbSingleByte;
  1674. end;
  1675. Function StrByteType(Str: PChar; Index: Cardinal): TMbcsByteType;
  1676. begin
  1677. Result:=mbSingleByte;
  1678. end;
  1679. Function StrCharLength(const Str: PChar): Integer;
  1680. begin
  1681. {$ifdef HASWIDESTRING}
  1682. result:=widestringmanager.CharLengthPCharProc(Str);
  1683. {$endif HASWIDESTRING}
  1684. end;
  1685. Function FindCmdLineSwitch(const Switch: string; const Chars: TSysCharSet;IgnoreCase: Boolean): Boolean;
  1686. Var
  1687. I,L : Integer;
  1688. S,T : String;
  1689. begin
  1690. Result:=False;
  1691. S:=Switch;
  1692. If IgnoreCase then
  1693. S:=UpperCase(S);
  1694. I:=ParamCount;
  1695. While (Not Result) and (I>0) do
  1696. begin
  1697. L:=Length(Paramstr(I));
  1698. If (L>0) and (ParamStr(I)[1] in Chars) then
  1699. begin
  1700. T:=Copy(ParamStr(I),2,L-1);
  1701. If IgnoreCase then
  1702. T:=UpperCase(T);
  1703. Result:=S=T;
  1704. end;
  1705. Dec(i);
  1706. end;
  1707. end;
  1708. Function FindCmdLineSwitch(const Switch: string; IgnoreCase: Boolean): Boolean;
  1709. begin
  1710. Result:=FindCmdLineSwitch(Switch,SwitchChars,IgnoreCase);
  1711. end;
  1712. Function FindCmdLineSwitch(const Switch: string): Boolean;
  1713. begin
  1714. Result:=FindCmdLineSwitch(Switch,SwitchChars,False);
  1715. end;
  1716. function WrapText(const Line, BreakStr: string; const BreakChars: TSysCharSet; MaxCol: Integer): string;
  1717. const
  1718. Quotes = ['''', '"'];
  1719. Var
  1720. L : String;
  1721. C,LQ,BC : Char;
  1722. P,BLen,Len : Integer;
  1723. HB,IBC : Boolean;
  1724. begin
  1725. Result:='';
  1726. L:=Line;
  1727. Blen:=Length(BreakStr);
  1728. If (BLen>0) then
  1729. BC:=BreakStr[1]
  1730. else
  1731. BC:=#0;
  1732. Len:=Length(L);
  1733. While (Len>0) do
  1734. begin
  1735. P:=1;
  1736. LQ:=#0;
  1737. HB:=False;
  1738. IBC:=False;
  1739. While ((P<=Len) and ((P<=MaxCol) or not IBC)) and ((LQ<>#0) or Not HB) do
  1740. begin
  1741. C:=L[P];
  1742. If (C=LQ) then
  1743. LQ:=#0
  1744. else If (C in Quotes) then
  1745. LQ:=C;
  1746. If (LQ<>#0) then
  1747. Inc(P)
  1748. else
  1749. begin
  1750. HB:=((C=BC) and (BreakStr=Copy(L,P,BLen)));
  1751. If HB then
  1752. Inc(P,Blen)
  1753. else
  1754. begin
  1755. If (P>MaxCol) then
  1756. IBC:=C in BreakChars;
  1757. Inc(P);
  1758. end;
  1759. end;
  1760. // Writeln('"',C,'" : IBC : ',IBC,' HB : ',HB,' LQ : ',LQ,' P>MaxCol : ',P>MaxCol);
  1761. end;
  1762. Result:=Result+Copy(L,1,P-1);
  1763. If Not HB then
  1764. Result:=Result+BreakStr;
  1765. Delete(L,1,P-1);
  1766. Len:=Length(L);
  1767. end;
  1768. end;
  1769. function WrapText(const Line: string; MaxCol: Integer): string;
  1770. begin
  1771. Result:=WrapText(Line,sLineBreak, [' ', '-', #9], MaxCol);
  1772. end;
  1773. {
  1774. Case Translation Tables
  1775. Can be used in internationalization support.
  1776. Although these tables can be obtained through system calls
  1777. it is better to not use those, since most implementation are not 100%
  1778. WARNING:
  1779. before modifying a translation table make sure that the current codepage
  1780. of the OS corresponds to the one you make changes to
  1781. }
  1782. const
  1783. { upper case translation table for character set 850 }
  1784. CP850UCT: array[128..255] of char =
  1785. ('€', 'š', '�', '¶', 'Ž', '¶', '�', '€', 'Ò', 'Ó', 'Ô', 'Ø', '×', 'Þ', 'Ž', '�',
  1786. '�', '’', '’', 'â', '™', 'ã', 'ê', 'ë', 'Y', '™', 'š', '�', 'œ', '�', 'ž', 'Ÿ',
  1787. 'µ', 'Ö', 'à', 'é', '¥', '¥', '¦', '§', '¨', '©', 'ª', '«', '¬', '­', '®', '¯',
  1788. '°', '±', '²', '³', '´', 'µ', '¶', '·', '¸', '¹', 'º', '»', '¼', '½', '¾', '¿',
  1789. 'À', 'Á', 'Â', 'Ã', 'Ä', 'Å', 'Ç', 'Ç', 'È', 'É', 'Ê', 'Ë', 'Ì', 'Í', 'Î', 'Ï',
  1790. 'Ð', 'Ñ', 'Ò', 'Ó', 'Ô', 'Õ', 'Ö', '×', 'Ø', 'Ù', 'Ú', 'Û', 'Ü', 'Ý', 'Þ', 'ß',
  1791. 'à', 'á', 'â', 'ã', 'å', 'å', 'æ', 'í', 'è', 'é', 'ê', 'ë', 'í', 'í', 'î', 'ï',
  1792. 'ð', 'ñ', 'ò', 'ó', 'ô', 'õ', 'ö', '÷', 'ø', 'ù', 'ú', 'û', 'ü', 'ý', 'þ', 'ÿ');
  1793. { lower case translation table for character set 850 }
  1794. CP850LCT: array[128..255] of char =
  1795. ('‡', '�', '‚', 'ƒ', '„', '…', '†', '‡', 'ˆ', '‰', 'Š', '‹', 'Œ', '�', '„', '†',
  1796. '‚', '‘', '‘', '“', '”', '•', '–', '—', '˜', '”', '�', '›', 'œ', '›', 'ž', 'Ÿ',
  1797. ' ', '¡', '¢', '£', '¤', '¤', '¦', '§', '¨', '©', 'ª', '«', '¬', '­', '®', '¯',
  1798. '°', '±', '²', '³', '´', ' ', 'ƒ', '…', '¸', '¹', 'º', '»', '¼', '½', '¾', '¿',
  1799. 'À', 'Á', 'Â', 'Ã', 'Ä', 'Å', 'Æ', 'Æ', 'È', 'É', 'Ê', 'Ë', 'Ì', 'Í', 'Î', 'Ï',
  1800. 'Ð', 'Ñ', 'ˆ', '‰', 'Š', 'Õ', '¡', 'Œ', '‹', 'Ù', 'Ú', 'Û', 'Ü', 'Ý', '�', 'ß',
  1801. '¢', 'á', '“', '•', 'ä', 'ä', 'æ', 'í', 'è', '£', '–', '—', 'ì', 'ì', 'î', 'ï',
  1802. 'ð', 'ñ', 'ò', 'ó', 'ô', 'õ', 'ö', '÷', 'ø', 'ù', 'ú', 'û', 'ü', 'ý', 'þ', 'ÿ');
  1803. { upper case translation table for character set ISO 8859/1 Latin 1 }
  1804. CPISO88591UCT: array[192..255] of char =
  1805. ( #192, #193, #194, #195, #196, #197, #198, #199,
  1806. #200, #201, #202, #203, #204, #205, #206, #207,
  1807. #208, #209, #210, #211, #212, #213, #214, #215,
  1808. #216, #217, #218, #219, #220, #221, #222, #223,
  1809. #192, #193, #194, #195, #196, #197, #198, #199,
  1810. #200, #201, #202, #203, #204, #205, #206, #207,
  1811. #208, #209, #210, #211, #212, #213, #214, #247,
  1812. #216, #217, #218, #219, #220, #221, #222, #89 );
  1813. { lower case translation table for character set ISO 8859/1 Latin 1 }
  1814. CPISO88591LCT: array[192..255] of char =
  1815. ( #224, #225, #226, #227, #228, #229, #230, #231,
  1816. #232, #233, #234, #235, #236, #237, #238, #239,
  1817. #240, #241, #242, #243, #244, #245, #246, #215,
  1818. #248, #249, #250, #251, #252, #253, #254, #223,
  1819. #224, #225, #226, #227, #228, #229, #230, #231,
  1820. #232, #233, #234, #235, #236, #237, #238, #239,
  1821. #240, #241, #242, #243, #244, #245, #246, #247,
  1822. #248, #249, #250, #251, #252, #253, #254, #255 );
  1823. {
  1824. $Log$
  1825. Revision 1.38 2005-05-09 18:35:06 michael
  1826. + Fixed bug 3957
  1827. Revision 1.37 2005/04/28 09:15:44 florian
  1828. + variants: string -> float/int casts
  1829. Revision 1.36 2005/04/26 16:40:51 michael
  1830. + Added FormatCurr by Uberto Barbini
  1831. Revision 1.35 2005/03/25 22:53:39 jonas
  1832. * fixed several warnings and notes about unused variables (mainly) or
  1833. uninitialised use of variables/function results (a few)
  1834. Revision 1.34 2005/03/13 14:30:24 marco
  1835. * some 1.0.x fixes
  1836. Revision 1.33 2005/03/12 14:56:22 florian
  1837. + added Ansi* routines to widestring manager
  1838. * made them using OS calls on windows
  1839. Revision 1.32 2005/03/01 19:23:03 jonas
  1840. * fixed newstr() and disposestr()
  1841. Revision 1.31 2005/02/28 11:12:17 jonas
  1842. * fixed web bug 3708
  1843. Revision 1.30 2005/02/26 10:21:17 florian
  1844. + implemented WideFormat
  1845. + some Widestring stuff implemented
  1846. * some Widestring stuff fixed
  1847. Revision 1.29 2005/02/14 17:13:31 peter
  1848. * truncate log
  1849. Revision 1.28 2005/02/07 08:29:00 michael
  1850. + Patch from peter to fix 1.0 compile
  1851. Revision 1.27 2005/02/06 09:38:45 florian
  1852. + StrCharLength infrastructure
  1853. Revision 1.26 2005/01/17 18:38:48 peter
  1854. * extended overload disabled for powerpc
  1855. Revision 1.25 2005/01/16 17:53:27 michael
  1856. + Patch from Colin Western to implemenet TryStrToFLoat
  1857. }