wstrings.inc 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1999-2001 by Florian Klaempfl,
  5. member of the Free Pascal development team.
  6. This file implements support routines for WideStrings/Unicode with FPC
  7. See the file COPYING.FPC, included in this distribution,
  8. for details about the copyright.
  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.
  12. **********************************************************************}
  13. {
  14. This file contains the implementation of the WideString type,
  15. and all things that are needed for it.
  16. WideString is defined as a 'silent' pwidechar :
  17. a pwidechar that points to :
  18. @-8 : SizeInt for reference count;
  19. @-4 : SizeInt for size;
  20. @ : String + Terminating #0;
  21. Pwidechar(Widestring) is a valid typecast.
  22. So WS[i] is converted to the address @WS+i-1.
  23. Constants should be assigned a reference count of -1
  24. Meaning that they can't be disposed of.
  25. }
  26. Type
  27. PWideRec = ^TWideRec;
  28. TWideRec = Packed Record
  29. Ref,
  30. Len : SizeInt;
  31. First : WideChar;
  32. end;
  33. Const
  34. WideRecLen = SizeOf(TWideRec);
  35. WideFirstOff = SizeOf(TWideRec)-sizeof(WideChar);
  36. {
  37. Default WideChar <-> Char conversion is to only convert the
  38. lower 127 chars, all others are translated to spaces.
  39. These routines can be overwritten for the Current Locale
  40. }
  41. procedure Wide2AnsiMove(source:pwidechar;dest:pchar;len:SizeInt);
  42. var
  43. i : SizeInt;
  44. begin
  45. for i:=1 to len do
  46. begin
  47. if word(source^)<128 then
  48. dest^:=char(word(source^))
  49. else
  50. dest^:=' ';
  51. inc(dest);
  52. inc(source);
  53. end;
  54. end;
  55. procedure Ansi2WideMove(source:pchar;dest:pwidechar;len:SizeInt);
  56. var
  57. i : SizeInt;
  58. begin
  59. for i:=1 to len do
  60. begin
  61. if byte(source^)<128 then
  62. dest^:=widechar(byte(source^))
  63. else
  64. dest^:=' ';
  65. inc(dest);
  66. inc(source);
  67. end;
  68. end;
  69. Const
  70. Wide2AnsiMoveProc:TWide2AnsiMove=@Wide2AnsiMove;
  71. Ansi2WideMoveProc:TAnsi2WideMove=@Ansi2WideMove;
  72. Procedure GetWideStringManager (Var Manager : TWideStringManager);
  73. begin
  74. Manager.Wide2AnsiMove:=Wide2AnsiMoveProc;
  75. Manager.Ansi2WideMove:=Ansi2WideMoveProc;
  76. end;
  77. Procedure SetWideStringManager (Const New : TWideStringManager; Var Old: TWideStringManager);
  78. begin
  79. GetWideStringManager(Old);
  80. SetWideStringManager(New);
  81. end;
  82. Procedure SetWideStringManager (Const New : TWideStringManager);
  83. begin
  84. Wide2AnsiMoveProc:=New.Wide2AnsiMove;
  85. Ansi2WideMoveProc:=New.Ansi2WideMove;
  86. end;
  87. (*
  88. Procedure UniqueWideString(Var S : WideString); [Public,Alias : 'FPC_WIDESTR_UNIQUE'];
  89. {
  90. Make sure reference count of S is 1,
  91. using copy-on-write semantics.
  92. }
  93. begin
  94. end;
  95. *)
  96. {****************************************************************************
  97. Internal functions, not in interface.
  98. ****************************************************************************}
  99. {$ifdef WideStrDebug}
  100. Procedure DumpWideRec(S : Pointer);
  101. begin
  102. If S=Nil then
  103. Writeln ('String is nil')
  104. Else
  105. Begin
  106. With PWideRec(S-WideFirstOff)^ do
  107. begin
  108. Write ('(Maxlen: ',maxlen);
  109. Write (' Len:',len);
  110. Writeln (' Ref: ',ref,')');
  111. end;
  112. end;
  113. end;
  114. {$endif}
  115. Function NewWideString(Len : SizeInt) : Pointer;
  116. {
  117. Allocate a new WideString on the heap.
  118. initialize it to zero length and reference count 1.
  119. }
  120. Var
  121. P : Pointer;
  122. begin
  123. GetMem(P,Len*sizeof(WideChar)+WideRecLen);
  124. If P<>Nil then
  125. begin
  126. PWideRec(P)^.Len:=0; { Initial length }
  127. PWideRec(P)^.Ref:=1; { Set reference count }
  128. PWideRec(P)^.First:=#0; { Terminating #0 }
  129. inc(p,WideFirstOff); { Points to string now }
  130. end;
  131. NewWideString:=P;
  132. end;
  133. Procedure DisposeWideString(Var S : Pointer);
  134. {
  135. Deallocates a WideString From the heap.
  136. }
  137. begin
  138. If S=Nil then
  139. exit;
  140. Dec (S,WideFirstOff);
  141. FreeMem (S);
  142. S:=Nil;
  143. end;
  144. Procedure fpc_WideStr_Decr_Ref (Var S : Pointer);saveregisters;[Public,Alias:'FPC_WIDESTR_DECR_REF']; {$ifdef hascompilerproc} compilerproc; {$endif}
  145. {
  146. Decreases the ReferenceCount of a non constant widestring;
  147. If the reference count is zero, deallocate the string;
  148. }
  149. Type
  150. pSizeInt = ^SizeInt;
  151. Var
  152. l : pSizeInt;
  153. Begin
  154. { Zero string }
  155. If S=Nil then exit;
  156. { check for constant strings ...}
  157. l:=@PWIDEREC(S-WideFirstOff)^.Ref;
  158. If l^<0 then exit;
  159. { declocked does a MT safe dec and returns true, if the counter is 0 }
  160. If declocked(l^) then
  161. { Ref count dropped to zero }
  162. DisposeWideString (S); { Remove...}
  163. {$ifndef decrrefnotnil}
  164. s:=nil;
  165. {$endif}
  166. end;
  167. {$ifdef hascompilerproc}
  168. { alias for internal use }
  169. Procedure fpc_WideStr_Decr_Ref (Var S : Pointer);saveregisters;[external name 'FPC_WIDESTR_DECR_REF'];
  170. {$endif compilerproc}
  171. {$ifdef hascompilerproc}
  172. Procedure fpc_WideStr_Incr_Ref (S : Pointer);saveregisters;[Public,Alias:'FPC_WIDESTR_INCR_REF']; {$ifdef hascompilerproc} compilerproc; {$endif}
  173. {$else}
  174. Procedure fpc_WideStr_Incr_Ref (Var S : Pointer);saveregisters;[Public,Alias:'FPC_WIDESTR_INCR_REF'];
  175. {$endif compilerproc}
  176. Begin
  177. If S=Nil then
  178. exit;
  179. { Let's be paranoid : Constant string ??}
  180. If PWideRec(S-WideFirstOff)^.Ref<0 then exit;
  181. inclocked(PWideRec(S-WideFirstOff)^.Ref);
  182. end;
  183. {$ifdef hascompilerproc}
  184. { alias for internal use }
  185. Procedure fpc_WideStr_Incr_Ref (S : Pointer);saveregisters;[external name 'FPC_WIDESTR_INCR_REF'];
  186. {$endif compilerproc}
  187. function fpc_WideStr_To_ShortStr (high_of_res: SizeInt;const S2 : WideString): shortstring;[Public, alias: 'FPC_WIDESTR_TO_SHORTSTR']; {$ifdef hascompilerproc} compilerproc; {$endif}
  188. {
  189. Converts a WideString to a ShortString;
  190. }
  191. Var
  192. Size : SizeInt;
  193. begin
  194. if S2='' then
  195. fpc_WideStr_To_ShortStr:=''
  196. else
  197. begin
  198. Size:=Length(S2);
  199. If Size>high_of_res then
  200. Size:=high_of_res;
  201. Wide2AnsiMoveProc(PWideChar(S2),PChar(@fpc_WideStr_To_ShortStr[1]),Size);
  202. byte(fpc_WideStr_To_ShortStr[0]):=byte(Size);
  203. end;
  204. end;
  205. Function fpc_ShortStr_To_WideStr (Const S2 : ShortString): WideString; {$ifdef hascompilerproc} compilerproc; {$endif}
  206. {
  207. Converts a ShortString to a WideString;
  208. }
  209. Var
  210. Size : SizeInt;
  211. begin
  212. Size:=Length(S2);
  213. Setlength (fpc_ShortStr_To_WideStr,Size);
  214. if Size>0 then
  215. begin
  216. Ansi2WideMoveProc(PChar(@S2[1]),PWideChar(Pointer(fpc_ShortStr_To_WideStr)),Size);
  217. { Terminating Zero }
  218. PWideChar(Pointer(fpc_ShortStr_To_WideStr)+Size*sizeof(WideChar))^:=#0;
  219. end;
  220. end;
  221. { old style helper }
  222. {$ifndef hascompilerproc}
  223. Procedure fpc_ShortStr_To_WideStr (Var S1 : Pointer; Const S2 : ShortString);[Public, alias: 'FPC_SHORTSTR_TO_WIDESTR'];
  224. begin
  225. s1 := pointer(fpc_ShortStr_To_WideStr(s2));
  226. end;
  227. {$endif hascompilerproc}
  228. Function fpc_WideStr_To_AnsiStr (const S2 : WideString): AnsiString; {$ifdef hascompilerproc} compilerproc; {$endif}
  229. {
  230. Converts a WideString to an AnsiString
  231. }
  232. Var
  233. Size : SizeInt;
  234. begin
  235. if s2='' then
  236. exit;
  237. Size:=Length(WideString(S2));
  238. Setlength (fpc_WideStr_To_AnsiStr,Size);
  239. if Size>0 then
  240. begin
  241. Wide2AnsiMoveProc(PWideChar(Pointer(S2)),PChar(Pointer(fpc_WideStr_To_AnsiStr)),Size);
  242. { Terminating Zero }
  243. PChar(Pointer(fpc_WideStr_To_AnsiStr)+Size)^:=#0;
  244. end;
  245. end;
  246. { old style helper }
  247. {$ifndef hascompilerproc}
  248. Procedure fpc_WideStr_To_AnsiStr (Var S1 : Pointer;const S2 : WideString);[Public, alias: 'FPC_WIDESTR_TO_ANSISTR'];
  249. begin
  250. s1 := pointer(fpc_WideStr_To_AnsiStr(s2));
  251. end;
  252. {$endif hascompilerproc}
  253. Function fpc_AnsiStr_To_WideStr (Const S2 : AnsiString): WideString; {$ifdef hascompilerproc} compilerproc; {$endif}
  254. {
  255. Converts an AnsiString to a WideString;
  256. }
  257. Var
  258. Size : SizeInt;
  259. begin
  260. if s2='' then
  261. exit;
  262. Size:=Length(S2);
  263. Setlength (result,Size);
  264. if Size>0 then
  265. begin
  266. Ansi2WideMoveProc(PChar(S2),PWideChar(Pointer(result)),Size);
  267. { Terminating Zero }
  268. PWideChar(Pointer(result)+Size*sizeof(WideChar))^:=#0;
  269. end;
  270. end;
  271. { compilers with widestrings should have compiler procs }
  272. Function fpc_PWideChar_To_AnsiStr(const p : pwidechar): ansistring; compilerproc;
  273. var
  274. Size : SizeInt;
  275. begin
  276. if p=nil then
  277. exit;
  278. Size := IndexWord(p^, -1, 0);
  279. Setlength (result,Size);
  280. if Size>0 then
  281. begin
  282. Wide2AnsiMoveProc(P,PChar(Pointer(result)),Size);
  283. { Terminating Zero }
  284. PChar(Pointer(result)+Size)^:=#0;
  285. end;
  286. end;
  287. Function fpc_PWideChar_To_WideStr(const p : pwidechar): widestring; compilerproc;
  288. var
  289. Size : SizeInt;
  290. begin
  291. if p=nil then
  292. exit;
  293. Size := IndexWord(p^, -1, 0);
  294. Setlength (result,Size);
  295. if Size>0 then
  296. begin
  297. Move(p^,PWideChar(Pointer(result))^,Size*sizeof(WideChar));
  298. { Terminating Zero }
  299. PWideChar(Pointer(result)+Size*sizeof(WideChar))^:=#0;
  300. end;
  301. end;
  302. Function fpc_PWideChar_To_ShortStr(const p : pwidechar): shortstring; compilerproc;
  303. var
  304. Size : SizeInt;
  305. begin
  306. if p=nil then
  307. begin
  308. fpc_PWideChar_To_ShortStr:='';
  309. exit;
  310. end;
  311. Size := IndexWord(p^, $7fffffff, 0);
  312. Setlength (result,Size+1);
  313. if Size>0 then
  314. begin
  315. If Size>255 then
  316. Size:=255;
  317. Wide2AnsiMoveProc(p,PChar(@result[1]),Size);
  318. byte(result[0]):=byte(Size);
  319. end;
  320. end;
  321. { old style helper }
  322. {$ifndef hascompilerproc}
  323. Procedure fpc_AnsiStr_To_WideStr (Var S1 : Pointer; Const S2 : AnsiString);[Public, alias: 'FPC_ANSISTR_TO_WIDESTR'];
  324. begin
  325. s1 := pointer(fpc_AnsiStr_To_WideStr(s2));
  326. end;
  327. {$endif hascompilerproc}
  328. { checked against the ansistring routine, 2001-05-27 (FK) }
  329. Procedure fpc_WideStr_Assign (Var S1 : Pointer;S2 : Pointer);[Public,Alias:'FPC_WIDESTR_ASSIGN']; {$ifdef hascompilerproc} compilerproc; {$endif}
  330. {
  331. Assigns S2 to S1 (S1:=S2), taking in account reference counts.
  332. }
  333. begin
  334. If S2<>nil then
  335. If PWideRec(S2-WideFirstOff)^.Ref>0 then
  336. Inc(PWideRec(S2-WideFirstOff)^.ref);
  337. { Decrease the reference count on the old S1 }
  338. fpc_widestr_decr_ref (S1);
  339. { And finally, have S1 pointing to S2 (or its copy) }
  340. S1:=S2;
  341. end;
  342. {$ifdef hascompilerproc}
  343. { alias for internal use }
  344. Procedure fpc_WideStr_Assign (Var S1 : Pointer;S2 : Pointer);[external name 'FPC_WIDESTR_ASSIGN'];
  345. {$endif hascompilerproc}
  346. { checked against the ansistring routine, 2001-05-27 (FK) }
  347. {$ifdef hascompilerproc}
  348. function fpc_WideStr_Concat (const S1,S2 : WideString): WideString; compilerproc;
  349. var
  350. S3: WideString absolute result;
  351. {$else hascompilerproc}
  352. Procedure fpc_WideStr_Concat (S1,S2 : WideString;var S3 : WideString);[Public, alias: 'FPC_WIDESTR_CONCAT'];
  353. {$endif hascompilerproc}
  354. {
  355. Concatenates 2 WideStrings : S1+S2.
  356. Result Goes to S3;
  357. }
  358. Var
  359. Size,Location : SizeInt;
  360. begin
  361. { only assign if s1 or s2 is empty }
  362. if (S1='') then
  363. S3 := S2
  364. else
  365. if (S2='') then
  366. S3 := S1
  367. else
  368. begin
  369. { create new result }
  370. Size:=Length(S2);
  371. Location:=Length(S1);
  372. SetLength (S3,Size+Location);
  373. Move (S1[1],S3[1],Location*sizeof(WideChar));
  374. Move (S2[1],S3[location+1],(Size+1)*sizeof(WideChar));
  375. end;
  376. end;
  377. Function fpc_Char_To_WideStr(const c : WideChar): WideString; {$ifdef hascompilerproc} compilerproc; {$endif}
  378. {
  379. Converts a Char to a WideString;
  380. }
  381. begin
  382. if c = #0 then
  383. { result is automatically set to '' }
  384. exit;
  385. Setlength (fpc_Char_To_WideStr,1);
  386. fpc_Char_To_WideStr[1]:=c;
  387. { Terminating Zero }
  388. PWideChar(Pointer(fpc_Char_To_WideStr)+sizeof(WideChar))^:=#0;
  389. end;
  390. { old style helper }
  391. {$ifndef hascompilerproc}
  392. Procedure fpc_Char_To_WideStr(var S1 : Pointer; c : WideChar);[Public, alias: 'FPC_CHAR_TO_WIDESTR'];
  393. begin
  394. s1 := pointer(fpc_Char_To_WideStr(c));
  395. end;
  396. {$endif hascompilerproc}
  397. Function fpc_PChar_To_WideStr(const p : pchar): WideString; {$ifdef hascompilerproc} compilerproc; {$endif}
  398. Var
  399. L : SizeInt;
  400. begin
  401. if (not assigned(p)) or (p[0]=#0) Then
  402. { result is automatically set to '' }
  403. exit;
  404. l:=IndexChar(p^,-1,#0);
  405. SetLength(fpc_PChar_To_WideStr,L);
  406. Ansi2WideMoveProc(P,PWideChar(Pointer(fpc_PChar_To_WideStr)),l);
  407. end;
  408. { old style helper }
  409. {$ifndef hascompilerproc}
  410. Procedure fpc_PChar_To_WideStr(var a : WideString;p : pchar);[Public,Alias : 'FPC_PCHAR_TO_WIDESTR']; {$ifdef hascompilerproc} compilerproc; {$endif}
  411. begin
  412. pointer(a) := pointer(fpc_PChar_To_WideStr(p));
  413. end;
  414. {$endif hascompilerproc}
  415. Function fpc_CharArray_To_WideStr(const arr: array of char): WideString; {$ifdef hascompilerproc} compilerproc; {$endif}
  416. var
  417. i : SizeInt;
  418. begin
  419. if arr[0]=#0 Then
  420. { result is automatically set to '' }
  421. exit;
  422. i:=IndexChar(arr,high(arr)+1,#0);
  423. if i = -1 then
  424. i := high(arr)+1;
  425. SetLength(fpc_CharArray_To_WideStr,i);
  426. Ansi2WideMoveProc (pchar(@arr),PWideChar(Pointer(fpc_CharArray_To_WideStr)),i);
  427. end;
  428. { old style helper }
  429. {$ifndef hascompilerproc}
  430. Procedure fpc_CharArray_To_WideStr(var a : WideString; p: pointer; len: SizeInt); [Public,Alias : 'FPC_CHARARRAY_TO_WIDESTR']; {$ifdef hascompilerproc} compilerproc; {$endif}
  431. var
  432. src: pchar;
  433. i: SizeInt;
  434. begin
  435. src := pchar(p);
  436. if src[0]=#0 Then
  437. begin
  438. pointer(a) := nil;
  439. exit;
  440. end;
  441. i:=IndexChar(src^,len,#0);
  442. if i = -1 then
  443. i := len;
  444. pointer(a) := NewWideString(i);
  445. Ansi2WideMoveProc (src,PWideChar(Pointer(@a[1])),i);
  446. end;
  447. {$endif not hascompilerproc}
  448. {$ifdef hascompilerproc}
  449. { inside the compiler, the resulttype is modified to that of the actual }
  450. { chararray we're converting to (JM) }
  451. function fpc_widestr_to_chararray(arraysize: SizeInt; const src: WideString): fpc_big_chararray;[public,alias: 'FPC_WIDESTR_TO_CHARARRAY']; compilerproc;
  452. var
  453. len: SizeInt;
  454. begin
  455. len := length(src);
  456. if len > arraysize then
  457. len := arraysize;
  458. { make sure we don't dereference src if it can be nil (JM) }
  459. if len > 0 then
  460. wide2ansimoveproc(pwidechar(@src[1]),pchar(@fpc_widestr_to_chararray[0]),len);
  461. fillchar(fpc_widestr_to_chararray[len],arraysize-len,0);
  462. end;
  463. {$endif hascompilerproc}
  464. Function fpc_WideStr_Compare(const S1,S2 : WideString): SizeInt;[Public,Alias : 'FPC_WIDESTR_COMPARE']; {$ifdef hascompilerproc} compilerproc; {$endif}
  465. {
  466. Compares 2 WideStrings;
  467. The result is
  468. <0 if S1<S2
  469. 0 if S1=S2
  470. >0 if S1>S2
  471. }
  472. Var
  473. MaxI,Temp : SizeInt;
  474. begin
  475. if pointer(S1)=pointer(S2) then
  476. begin
  477. fpc_WideStr_Compare:=0;
  478. exit;
  479. end;
  480. Maxi:=Length(S1);
  481. temp:=Length(S2);
  482. If MaxI>Temp then
  483. MaxI:=Temp;
  484. Temp:=CompareWord(S1[1],S2[1],MaxI);
  485. if temp=0 then
  486. temp:=Length(S1)-Length(S2);
  487. fpc_WideStr_Compare:=Temp;
  488. end;
  489. Procedure fpc_WideStr_CheckZero(p : pointer);[Public,Alias : 'FPC_WIDESTR_CHECKZERO']; {$ifdef hascompilerproc} compilerproc; {$endif}
  490. begin
  491. if p=nil then
  492. HandleErrorFrame(201,get_frame);
  493. end;
  494. Procedure fpc_WideStr_CheckRange(len,index : SizeInt);[Public,Alias : 'FPC_WIDESTR_RANGECHECK']; {$ifdef hascompilerproc} compilerproc; {$endif}
  495. begin
  496. if (index>len) or (Index<1) then
  497. HandleErrorFrame(201,get_frame);
  498. end;
  499. {$ifndef INTERNSETLENGTH}
  500. Procedure SetLength (Var S : WideString; l : SizeInt);
  501. {$else INTERNSETLENGTH}
  502. Procedure fpc_WideStr_SetLength (Var S : WideString; l : SizeInt);[Public,Alias : 'FPC_WIDESTR_SETLENGTH']; {$ifdef hascompilerproc} compilerproc; {$endif}
  503. {$endif INTERNSETLENGTH}
  504. {
  505. Sets The length of string S to L.
  506. Makes sure S is unique, and contains enough room.
  507. }
  508. Var
  509. Temp : Pointer;
  510. movelen: SizeInt;
  511. begin
  512. if (l>0) then
  513. begin
  514. if Pointer(S)=nil then
  515. begin
  516. { Need a complete new string...}
  517. Pointer(s):=NewWideString(l);
  518. end
  519. else if (PWideRec(Pointer(S)-WideFirstOff)^.Ref = 1) then
  520. begin
  521. Dec(Pointer(S),WideFirstOff);
  522. if L*sizeof(WideChar)+WideRecLen>MemSize(Pointer(S)) then
  523. reallocmem(pointer(S), L*sizeof(WideChar)+WideRecLen);
  524. Inc(Pointer(S), WideFirstOff);
  525. end
  526. else
  527. begin
  528. { Reallocation is needed... }
  529. Temp:=Pointer(NewWideString(L));
  530. if Length(S)>0 then
  531. begin
  532. if l < succ(length(s)) then
  533. movelen := l
  534. { also move terminating null }
  535. else movelen := succ(length(s));
  536. Move(Pointer(S)^,Temp^,movelen * Sizeof(WideChar));
  537. end;
  538. fpc_widestr_decr_ref(Pointer(S));
  539. Pointer(S):=Temp;
  540. end;
  541. { Force nil termination in case it gets shorter }
  542. PWord(Pointer(S)+l*sizeof(WideChar))^:=0;
  543. PWideRec(Pointer(S)-FirstOff)^.Len:=l;
  544. end
  545. else
  546. begin
  547. { Length=0 }
  548. if Pointer(S)<>nil then
  549. fpc_widestr_decr_ref (Pointer(S));
  550. Pointer(S):=Nil;
  551. end;
  552. end;
  553. {*****************************************************************************
  554. Public functions, In interface.
  555. *****************************************************************************}
  556. function WideCharToString(S : PWideChar) : AnsiString;
  557. begin
  558. result:=WideCharLenToString(s,Length(WideString(s)));
  559. end;
  560. function StringToWideChar(const Src : AnsiString;Dest : PWideChar;DestSize : SizeInt) : PWideChar;
  561. begin
  562. if Length(Src)<DestSize then
  563. Ansi2WideMoveProc(PChar(Src),Dest,Length(Src))
  564. else
  565. Ansi2WideMoveProc(PChar(Src),Dest,DestSize);
  566. result:=Dest;
  567. end;
  568. function WideCharLenToString(S : PWideChar;Len : SizeInt) : AnsiString;
  569. begin
  570. SetLength(result,Len);
  571. Wide2AnsiMove(S,PChar(result),Len);
  572. end;
  573. procedure WideCharLenToStrVar(Src : PWideChar;Len : SizeInt;var Dest : AnsiString);
  574. begin
  575. Dest:=WideCharLenToString(Src,Len);
  576. end;
  577. procedure WideCharToStrVar(S : PWideChar;var Dest : AnsiString);
  578. begin
  579. Dest:=WideCharToString(S);
  580. end;
  581. {$ifndef INTERNLENGTH}
  582. Function Length (Const S : WideString) : SizeInt;
  583. {
  584. Returns the length of an WideString.
  585. Takes in acount that zero strings are NIL;
  586. }
  587. begin
  588. If Pointer(S)=Nil then
  589. Length:=0
  590. else
  591. Length:=PWideRec(Pointer(S)-WideFirstOff)^.Len;
  592. end;
  593. {$endif INTERNLENGTH}
  594. { overloaded version of UniqueString for interface }
  595. procedure UniqueString(Var S : WideString); [external name 'FPC_WIDESTR_UNIQUE'];
  596. Function fpc_widestr_Unique(Var S : Pointer): Pointer; [Public,Alias : 'FPC_WIDESTR_UNIQUE']; {$ifdef hascompilerproc} compilerproc; {$endif}
  597. {
  598. Make sure reference count of S is 1,
  599. using copy-on-write semantics.
  600. }
  601. Var
  602. SNew : Pointer;
  603. L : SizeInt;
  604. begin
  605. pointer(result) := pointer(s);
  606. If Pointer(S)=Nil then
  607. exit;
  608. if PWideRec(Pointer(S)-WideFirstOff)^.Ref<>1 then
  609. begin
  610. L:=PWideRec(Pointer(S)-WideFirstOff)^.len;
  611. SNew:=NewWideString (L);
  612. Move (PWideChar(S)^,SNew^,(L+1)*sizeof(WideChar));
  613. PWideRec(SNew-WideFirstOff)^.len:=L;
  614. fpc_widestr_decr_ref (Pointer(S)); { Thread safe }
  615. pointer(S):=SNew;
  616. pointer(result):=SNew;
  617. end;
  618. end;
  619. {$ifdef interncopy}
  620. Function Fpc_WideStr_Copy (Const S : WideString; Index,Size : SizeInt) : WideString;compilerproc;
  621. {$else}
  622. Function Copy (Const S : WideString; Index,Size : SizeInt) : WideString;
  623. {$endif}
  624. var
  625. ResultAddress : Pointer;
  626. begin
  627. ResultAddress:=Nil;
  628. dec(index);
  629. if Index < 0 then
  630. Index := 0;
  631. { Check Size. Accounts for Zero-length S, the double check is needed because
  632. Size can be maxint and will get <0 when adding index }
  633. if (Size>Length(S)) or
  634. (Index+Size>Length(S)) then
  635. Size:=Length(S)-Index;
  636. If Size>0 then
  637. begin
  638. If Index<0 Then
  639. Index:=0;
  640. ResultAddress:=Pointer(NewWideString (Size));
  641. if ResultAddress<>Nil then
  642. begin
  643. Move (PWideChar(S)[Index],ResultAddress^,Size*sizeof(WideChar));
  644. PWideRec(ResultAddress-WideFirstOff)^.Len:=Size;
  645. PWideChar(ResultAddress+Size*sizeof(WideChar))^:=#0;
  646. end;
  647. end;
  648. {$ifdef interncopy}
  649. Pointer(fpc_widestr_Copy):=ResultAddress;
  650. {$else}
  651. Pointer(Copy):=ResultAddress;
  652. {$endif}
  653. end;
  654. Function Pos (Const Substr : WideString; Const Source : WideString) : SizeInt;
  655. var
  656. i,MaxLen : SizeInt;
  657. pc : pwidechar;
  658. begin
  659. Pos:=0;
  660. if Length(SubStr)>0 then
  661. begin
  662. MaxLen:=Length(source)-Length(SubStr);
  663. i:=0;
  664. pc:=@source[1];
  665. while (i<=MaxLen) do
  666. begin
  667. inc(i);
  668. if (SubStr[1]=pc^) and
  669. (CompareWord(Substr[1],pc^,Length(SubStr))=0) then
  670. begin
  671. Pos:=i;
  672. exit;
  673. end;
  674. inc(pc);
  675. end;
  676. end;
  677. end;
  678. { Faster version for a widechar alone }
  679. Function Pos (c : WideChar; Const s : WideString) : SizeInt;
  680. var
  681. i: SizeInt;
  682. pc : pwidechar;
  683. begin
  684. pc:=@s[1];
  685. for i:=1 to length(s) do
  686. begin
  687. if pc^=c then
  688. begin
  689. pos:=i;
  690. exit;
  691. end;
  692. inc(pc);
  693. end;
  694. pos:=0;
  695. end;
  696. { Faster version for a char alone. Must be implemented because }
  697. { pos(c: char; const s: shortstring) also exists, so otherwise }
  698. { using pos(char,pchar) will always call the shortstring version }
  699. { (exact match for first argument), also with $h+ (JM) }
  700. Function Pos (c : Char; Const s : WideString) : SizeInt;
  701. var
  702. i: SizeInt;
  703. wc : widechar;
  704. pc : pwidechar;
  705. begin
  706. wc:=c;
  707. pc:=@s[1];
  708. for i:=1 to length(s) do
  709. begin
  710. if pc^=wc then
  711. begin
  712. pos:=i;
  713. exit;
  714. end;
  715. inc(pc);
  716. end;
  717. pos:=0;
  718. end;
  719. Procedure Delete (Var S : WideString; Index,Size: SizeInt);
  720. Var
  721. LS : SizeInt;
  722. begin
  723. If Length(S)=0 then
  724. exit;
  725. if index<=0 then
  726. exit;
  727. LS:=PWideRec(Pointer(S)-WideFirstOff)^.Len;
  728. if (Index<=LS) and (Size>0) then
  729. begin
  730. UniqueString (S);
  731. if Size+Index>LS then
  732. Size:=LS-Index+1;
  733. if Index+Size<=LS then
  734. begin
  735. Dec(Index);
  736. Move(PWideChar(S)[Index+Size],PWideChar(S)[Index],(LS-Index+1)*sizeof(WideChar));
  737. end;
  738. Setlength(s,LS-Size);
  739. end;
  740. end;
  741. Procedure Insert (Const Source : WideString; Var S : WideString; Index : SizeInt);
  742. var
  743. Temp : WideString;
  744. LS : SizeInt;
  745. begin
  746. If Length(Source)=0 then
  747. exit;
  748. if index <= 0 then
  749. index := 1;
  750. Ls:=Length(S);
  751. if index > LS then
  752. index := LS+1;
  753. Dec(Index);
  754. Pointer(Temp) := NewWideString(Length(Source)+LS);
  755. SetLength(Temp,Length(Source)+LS);
  756. If Index>0 then
  757. move (PWideChar(S)^,PWideChar(Temp)^,Index*sizeof(WideChar));
  758. Move (PWideChar(Source)^,PWideChar(Temp)[Index],Length(Source)*sizeof(WideChar));
  759. If (LS-Index)>0 then
  760. Move(PWideChar(S)[Index],PWideChar(temp)[Length(Source)+index],(LS-Index)*sizeof(WideChar));
  761. S:=Temp;
  762. end;
  763. Procedure SetString (Var S : WideString; Buf : PWideChar; Len : SizeInt);
  764. var
  765. BufLen: SizeInt;
  766. begin
  767. SetLength(S,Len);
  768. If (Buf<>Nil) and (Len>0) then
  769. begin
  770. BufLen := IndexWord(Buf^, Len+1, 0);
  771. If (BufLen>0) and (BufLen < Len) then
  772. Len := BufLen;
  773. Move (Buf[0],S[1],Len*sizeof(WideChar));
  774. PWideChar(Pointer(S)+Len*sizeof(WideChar))^:=#0;
  775. end;
  776. end;
  777. Procedure SetString (Var S : WideString; Buf : PChar; Len : SizeInt);
  778. var
  779. BufLen: SizeInt;
  780. begin
  781. SetLength(S,Len);
  782. If (Buf<>Nil) and (Len>0) then
  783. begin
  784. BufLen := IndexByte(Buf^, Len+1, 0);
  785. If (BufLen>0) and (BufLen < Len) then
  786. Len := BufLen;
  787. Ansi2WideMoveProc(Buf,PWideChar(S),Len);
  788. PWideChar(Pointer(S)+Len*sizeof(WideChar))^:=#0;
  789. end;
  790. end;
  791. Function fpc_Val_Real_WideStr(Const S : WideString; Var Code : ValSInt): ValReal; [public, alias:'FPC_VAL_REAL_WIDESTR']; {$ifdef hascompilerproc} compilerproc; {$endif}
  792. Var
  793. SS : String;
  794. begin
  795. fpc_Val_Real_WideStr := 0;
  796. if length(S) > 255 then
  797. code := 256
  798. else
  799. begin
  800. SS := S;
  801. Val(SS,fpc_Val_Real_WideStr,code);
  802. end;
  803. end;
  804. Function fpc_Val_UInt_WideStr (Const S : WideString; Var Code : ValSInt): ValUInt; [public, alias:'FPC_VAL_UINT_WIDESTR']; {$ifdef hascompilerproc} compilerproc; {$endif}
  805. Var
  806. SS : ShortString;
  807. begin
  808. fpc_Val_UInt_WideStr := 0;
  809. if length(S) > 255 then
  810. code := 256
  811. else
  812. begin
  813. SS := S;
  814. Val(SS,fpc_Val_UInt_WideStr,code);
  815. end;
  816. end;
  817. Function fpc_Val_SInt_WideStr (DestSize: SizeInt; Const S : WideString; Var Code : ValSInt): ValSInt; [public, alias:'FPC_VAL_SINT_WIDESTR']; {$ifdef hascompilerproc} compilerproc; {$endif}
  818. Var
  819. SS : ShortString;
  820. begin
  821. fpc_Val_SInt_WideStr:=0;
  822. if length(S)>255 then
  823. code:=256
  824. else
  825. begin
  826. SS := S;
  827. fpc_Val_SInt_WideStr := fpc_Val_SInt_ShortStr(DestSize,SS,Code);
  828. end;
  829. end;
  830. {$ifndef CPU64}
  831. Function fpc_Val_qword_WideStr (Const S : WideString; Var Code : ValSInt): qword; [public, alias:'FPC_VAL_QWORD_WIDESTR']; {$ifdef hascompilerproc} compilerproc; {$endif}
  832. Var
  833. SS : ShortString;
  834. begin
  835. fpc_Val_qword_WideStr:=0;
  836. if length(S)>255 then
  837. code:=256
  838. else
  839. begin
  840. SS := S;
  841. Val(SS,fpc_Val_qword_WideStr,Code);
  842. end;
  843. end;
  844. Function fpc_Val_int64_WideStr (Const S : WideString; Var Code : ValSInt): Int64; [public, alias:'FPC_VAL_INT64_WIDESTR']; {$ifdef hascompilerproc} compilerproc; {$endif}
  845. Var
  846. SS : ShortString;
  847. begin
  848. fpc_Val_int64_WideStr:=0;
  849. if length(S)>255 then
  850. code:=256
  851. else
  852. begin
  853. SS := S;
  854. Val(SS,fpc_Val_int64_WideStr,Code);
  855. end;
  856. end;
  857. {$endif CPU64}
  858. procedure fpc_WideStr_Float(d : ValReal;len,fr,rt : SizeInt;var s : WideString);{$ifdef hascompilerproc} compilerproc; {$endif}
  859. var
  860. ss : shortstring;
  861. begin
  862. str_real(len,fr,d,treal_type(rt),ss);
  863. s:=ss;
  864. end;
  865. {$ifdef STR_USES_VALINT}
  866. Procedure fpc_WideStr_SInt(v : ValSint; Len : SizeInt; Var S : WideString);{$ifdef hascompilerproc} compilerproc; {$endif}
  867. {$else}
  868. Procedure fpc_WideStr_Longint(v : Longint; Len : SizeInt; Var S : WideString);{$ifdef hascompilerproc} compilerproc; {$endif}
  869. {$endif}
  870. Var
  871. SS : ShortString;
  872. begin
  873. Str (v:Len,SS);
  874. S:=SS;
  875. end;
  876. {$ifdef STR_USES_VALINT}
  877. Procedure fpc_WideStr_UInt(v : ValUInt;Len : SizeInt; Var S : WideString);{$ifdef hascompilerproc} compilerproc; {$endif}
  878. {$else}
  879. Procedure fpc_WideStr_Longword(v : Longword;Len : SizeInt; Var S : WideString);{$ifdef hascompilerproc} compilerproc; {$endif}
  880. {$endif}
  881. Var
  882. SS : ShortString;
  883. begin
  884. str(v:Len,SS);
  885. S:=SS;
  886. end;
  887. {$ifndef CPU64}
  888. Procedure fpc_WideStr_Int64(v : Int64; Len : SizeInt; Var S : WideString);{$ifdef hascompilerproc} compilerproc; {$endif}
  889. Var
  890. SS : ShortString;
  891. begin
  892. Str (v:Len,SS);
  893. S:=SS;
  894. end;
  895. Procedure fpc_WideStr_Qword(v : Qword;Len : SizeInt; Var S : WideString);{$ifdef hascompilerproc} compilerproc; {$endif}
  896. Var
  897. SS : ShortString;
  898. begin
  899. str(v:Len,SS);
  900. S:=SS;
  901. end;
  902. {$endif CPU64}
  903. function UnicodeToUtf8(Dest: PChar; Source: PWideChar; MaxBytes: SizeInt): SizeInt;{$ifdef SYSTEMINLINE}inline;{$endif}
  904. begin
  905. if assigned(Source) then
  906. Result:=UnicodeToUtf8(Dest,MaxBytes,Source,IndexWord(Source^,-1,0))
  907. else
  908. Result:=0;
  909. end;
  910. function UnicodeToUtf8(Dest: PChar; MaxDestBytes: SizeUInt; Source: PWideChar; SourceChars: SizeUInt): SizeUInt;
  911. var
  912. i,j : SizeUInt;
  913. w : word;
  914. begin
  915. result:=0;
  916. if source=nil then
  917. exit;
  918. i:=0;
  919. j:=0;
  920. if assigned(Dest) then
  921. begin
  922. while (i<SourceChars) and (j<MaxDestBytes) do
  923. begin
  924. w:=word(Source[i]);
  925. case w of
  926. 0..$7f:
  927. begin
  928. Dest[j]:=char(w);
  929. inc(j);
  930. end;
  931. $80..$7ff:
  932. begin
  933. if j+1>=MaxDestBytes then
  934. break;
  935. Dest[j]:=char($c0 or (w shr 6));
  936. Dest[j+1]:=char($80 or (w and $3f));
  937. inc(j,2);
  938. end;
  939. else
  940. begin
  941. if j+2>=MaxDestBytes then
  942. break;
  943. Dest[j]:=char($e0 or (w shr 12));
  944. Dest[j+1]:=char($80 or ((w shr 6)and $3f));
  945. Dest[j+2]:=char($80 or (w and $3f));
  946. inc(j,3);
  947. end;
  948. end;
  949. inc(i);
  950. end;
  951. if j>MaxDestBytes-1 then
  952. j:=MaxDestBytes-1;
  953. Dest[j]:=#0;
  954. end
  955. else
  956. begin
  957. while i<SourceChars do
  958. begin
  959. case word(Source[i]) of
  960. $0..$7f:
  961. inc(j);
  962. $80..$7ff:
  963. inc(j,2);
  964. else
  965. inc(j,3);
  966. end;
  967. end;
  968. end;
  969. result:=j+1;
  970. end;
  971. function Utf8ToUnicode(Dest: PWideChar; Source: PChar; MaxChars: SizeInt): SizeInt;{$ifdef SYSTEMINLINE}inline;{$endif}
  972. begin
  973. if assigned(Source) then
  974. Result:=Utf8ToUnicode(Dest,MaxChars,Source,strlen(Source))
  975. else
  976. Result:=0;
  977. end;
  978. function Utf8ToUnicode(Dest: PWideChar; MaxDestChars: SizeUInt; Source: PChar; SourceBytes: SizeUInt): SizeUInt;
  979. var
  980. i,j : SizeUInt;
  981. w : word;
  982. b : byte;
  983. begin
  984. result:=0;
  985. i:=0;
  986. j:=0;
  987. if assigned(Dest) then
  988. begin
  989. while (j<MaxDestChars) and (i<SourceBytes) do
  990. begin
  991. b:=byte(Source[i]);
  992. inc(i);
  993. // 2 or 3 bytes?
  994. if b>=$80 then
  995. begin
  996. w:=b and $3c;
  997. if i>=SourceBytes then
  998. exit;
  999. // 3 bytes?
  1000. if (b and $20)<>0 then
  1001. begin
  1002. b:=byte(Source[i]);
  1003. inc(i);
  1004. if i>=SourceBytes then
  1005. exit;
  1006. if (b and $c0)<>$80 then
  1007. exit;
  1008. w:=(w shl 6) or (b and $3c);
  1009. end;
  1010. b:=byte(Source[i]);
  1011. w:=(w shl 6) or (b and $3c);
  1012. if (b and $c0)<>$80 then
  1013. exit;
  1014. inc(i);
  1015. end;
  1016. Dest[j]:=WideChar(w);
  1017. inc(j);
  1018. end;
  1019. end
  1020. else
  1021. begin
  1022. while i<SourceBytes do
  1023. begin
  1024. b:=byte(Source[i]);
  1025. inc(i);
  1026. // 2 or 3 bytes?
  1027. if b>=$80 then
  1028. begin
  1029. if i>=SourceBytes then
  1030. exit;
  1031. // 3 bytes?
  1032. if (b and $20)<>0 then
  1033. begin
  1034. b:=byte(Source[i]);
  1035. inc(i);
  1036. if i>=SourceBytes then
  1037. exit;
  1038. if (b and $c0)<>$80 then
  1039. exit;
  1040. end;
  1041. if (byte(Source[i]) and $c0)<>$80 then
  1042. exit;
  1043. inc(i);
  1044. end;
  1045. inc(j);
  1046. end;
  1047. end;
  1048. result:=j+1;
  1049. end;
  1050. function UTF8Encode(const s : WideString) : UTF8String;
  1051. var
  1052. i : SizeInt;
  1053. hs : UTF8String;
  1054. begin
  1055. result:='';
  1056. if s='' then
  1057. exit;
  1058. SetLength(hs,length(s)*3);
  1059. i:=UnicodeToUtf8(pchar(hs),length(hs)+1,PWideChar(s),length(s));
  1060. if i>0 then
  1061. begin
  1062. SetLength(hs,i-1);
  1063. result:=hs;
  1064. end;
  1065. end;
  1066. function UTF8Decode(const s : UTF8String): WideString;
  1067. var
  1068. i : SizeInt;
  1069. hs : WideString;
  1070. begin
  1071. result:='';
  1072. if s='' then
  1073. exit;
  1074. SetLength(hs,length(s));
  1075. i:=Utf8ToUnicode(PWideChar(hs),length(hs)+1,pchar(s),length(s));
  1076. if i>0 then
  1077. begin
  1078. SetLength(hs,i-1);
  1079. result:=hs;
  1080. end;
  1081. end;
  1082. function AnsiToUtf8(const s : ansistring): UTF8String;{$ifdef SYSTEMINLINE}inline;{$endif}
  1083. begin
  1084. Result:=Utf8Encode(s);
  1085. end;
  1086. function Utf8ToAnsi(const s : UTF8String) : ansistring;{$ifdef SYSTEMINLINE}inline;{$endif}
  1087. begin
  1088. Result:=Utf8Decode(s);
  1089. end;
  1090. {
  1091. $Log$
  1092. Revision 1.44 2004-09-29 14:55:49 mazen
  1093. * widestring conversion routines takes a widechar so no
  1094. information is lost
  1095. Revision 1.43 2004/09/18 10:23:08 jonas
  1096. - removed unused local variable
  1097. * fixed bug in Utf8ToUnicode (use of uninitialised variable)
  1098. Revision 1.42 2004/07/18 20:21:44 florian
  1099. + several unicode (to/from utf-8 conversion) stuff added
  1100. * some longint -> SizeInt changes
  1101. Revision 1.41 2004/07/12 17:58:19 peter
  1102. * remove maxlen field from ansistring/widestrings
  1103. Revision 1.40 2004/07/02 21:21:09 peter
  1104. * decr ref doesn't reset pointer
  1105. * finalize resets pointer for astring,wstring
  1106. Revision 1.39 2004/05/31 14:31:57 peter
  1107. * remove comment warnings
  1108. Revision 1.38 2004/05/29 15:39:08 florian
  1109. * the decr functions set the data now to nil
  1110. Revision 1.37 2004/05/01 23:55:18 peter
  1111. * replace strlenint with sizeint
  1112. Revision 1.36 2004/04/29 18:59:43 peter
  1113. * str() helpers now also use valint/valuint
  1114. * int64/qword helpers disabled for cpu64
  1115. Revision 1.35 2004/01/22 22:09:05 peter
  1116. * finalize needs to reset to nil after decr_ref
  1117. Revision 1.34 2003/11/29 17:27:05 michael
  1118. + Added overloaded version of SetWideStringManager without old parameter
  1119. Revision 1.33 2003/11/28 20:36:13 michael
  1120. + Added WideStringManager
  1121. Revision 1.32 2003/11/05 15:33:51 florian
  1122. * made Index* usage consistent with astrings.inc
  1123. Revision 1.31 2003/06/17 19:24:08 jonas
  1124. * fixed conversion of fpc_*str_unique to compilerproc
  1125. Revision 1.30 2003/06/17 16:38:53 jonas
  1126. * fpc_ansistr|widestr_unique is now a function so it can be used as
  1127. compilerproc
  1128. Revision 1.29 2003/05/01 08:05:23 florian
  1129. * started to make the rtl 64 bit save by introducing SizeInt and SizeUInt (similar to size_t of C)
  1130. Revision 1.28 2002/12/29 16:59:17 peter
  1131. * implemented some more conversions
  1132. Revision 1.27 2002/12/15 22:33:12 peter
  1133. * SetString(WideString,[PChar|PWideChar],Len) added
  1134. Revision 1.26 2002/12/14 19:16:45 sg
  1135. * Ported improvements from the AnsiString equivalents to NewWideString and
  1136. fpc_WideStr_SetLength
  1137. Revision 1.25 2002/12/07 14:35:34 carl
  1138. - avoid warnings (add typecast)
  1139. Revision 1.24 2002/10/10 16:08:50 florian
  1140. + several widestring/pwidechar related helpers added
  1141. Revision 1.23 2002/10/02 18:21:52 peter
  1142. * Copy() changed to internal function calling compilerprocs
  1143. * FPC_SHORTSTR_COPY renamed to FPC_SHORTSTR_ASSIGN because of the
  1144. new copy functions
  1145. Revision 1.22 2002/09/26 21:50:38 florian
  1146. + some WideString<->AnsiString conversion functions added
  1147. Revision 1.21 2002/09/14 11:20:50 carl
  1148. * Delphi compatibility fix (with string routines)
  1149. Revision 1.20 2002/09/07 21:16:45 carl
  1150. * cardinal -> longword
  1151. Revision 1.19 2002/09/07 15:07:46 peter
  1152. * old logs removed and tabs fixed
  1153. Revision 1.18 2002/07/29 21:28:17 florian
  1154. * several fixes to get further with linux/ppc system unit compilation
  1155. Revision 1.17 2002/04/26 15:19:05 peter
  1156. * use saveregisters for incr routines, saves also problems with
  1157. the optimizer
  1158. Revision 1.16 2002/04/25 20:14:57 peter
  1159. * updated compilerprocs
  1160. * incr ref count has now a value argument instead of var
  1161. }