wstrings.inc 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341
  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);{$ifndef NOSAVEREGISTERS}saveregisters;{$endif}[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);{$ifndef NOSAVEREGISTERS}saveregisters;{$endif}[external name 'FPC_WIDESTR_DECR_REF'];
  170. {$endif compilerproc}
  171. {$ifdef hascompilerproc}
  172. Procedure fpc_WideStr_Incr_Ref (S : Pointer);{$ifndef NOSAVEREGISTERS}saveregisters;{$endif}[Public,Alias:'FPC_WIDESTR_INCR_REF']; {$ifdef hascompilerproc} compilerproc; {$endif}
  173. {$else}
  174. Procedure fpc_WideStr_Incr_Ref (Var S : Pointer);{$ifndef NOSAVEREGISTERS}saveregisters;{$endif}[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);{$ifndef NOSAVEREGISTERS}saveregisters;{$endif}[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. Function fpc_widestr_Unique(Var S : Pointer): Pointer; [Public,Alias : 'FPC_WIDESTR_UNIQUE']; {$ifdef hascompilerproc} compilerproc; {$endif}
  595. {
  596. Make sure reference count of S is 1,
  597. using copy-on-write semantics.
  598. }
  599. Var
  600. SNew : Pointer;
  601. L : SizeInt;
  602. begin
  603. pointer(result) := pointer(s);
  604. If Pointer(S)=Nil then
  605. exit;
  606. if PWideRec(Pointer(S)-WideFirstOff)^.Ref<>1 then
  607. begin
  608. L:=PWideRec(Pointer(S)-WideFirstOff)^.len;
  609. SNew:=NewWideString (L);
  610. Move (PWideChar(S)^,SNew^,(L+1)*sizeof(WideChar));
  611. PWideRec(SNew-WideFirstOff)^.len:=L;
  612. fpc_widestr_decr_ref (Pointer(S)); { Thread safe }
  613. pointer(S):=SNew;
  614. pointer(result):=SNew;
  615. end;
  616. end;
  617. {$ifdef interncopy}
  618. Function Fpc_WideStr_Copy (Const S : WideString; Index,Size : SizeInt) : WideString;compilerproc;
  619. {$else}
  620. Function Copy (Const S : WideString; Index,Size : SizeInt) : WideString;
  621. {$endif}
  622. var
  623. ResultAddress : Pointer;
  624. begin
  625. ResultAddress:=Nil;
  626. dec(index);
  627. if Index < 0 then
  628. Index := 0;
  629. { Check Size. Accounts for Zero-length S, the double check is needed because
  630. Size can be maxint and will get <0 when adding index }
  631. if (Size>Length(S)) or
  632. (Index+Size>Length(S)) then
  633. Size:=Length(S)-Index;
  634. If Size>0 then
  635. begin
  636. If Index<0 Then
  637. Index:=0;
  638. ResultAddress:=Pointer(NewWideString (Size));
  639. if ResultAddress<>Nil then
  640. begin
  641. Move (PWideChar(S)[Index],ResultAddress^,Size*sizeof(WideChar));
  642. PWideRec(ResultAddress-WideFirstOff)^.Len:=Size;
  643. PWideChar(ResultAddress+Size*sizeof(WideChar))^:=#0;
  644. end;
  645. end;
  646. {$ifdef interncopy}
  647. Pointer(fpc_widestr_Copy):=ResultAddress;
  648. {$else}
  649. Pointer(Copy):=ResultAddress;
  650. {$endif}
  651. end;
  652. Function Pos (Const Substr : WideString; Const Source : WideString) : SizeInt;
  653. var
  654. i,MaxLen : SizeInt;
  655. pc : pwidechar;
  656. begin
  657. Pos:=0;
  658. if Length(SubStr)>0 then
  659. begin
  660. MaxLen:=Length(source)-Length(SubStr);
  661. i:=0;
  662. pc:=@source[1];
  663. while (i<=MaxLen) do
  664. begin
  665. inc(i);
  666. if (SubStr[1]=pc^) and
  667. (CompareWord(Substr[1],pc^,Length(SubStr))=0) then
  668. begin
  669. Pos:=i;
  670. exit;
  671. end;
  672. inc(pc);
  673. end;
  674. end;
  675. end;
  676. { Faster version for a widechar alone }
  677. Function Pos (c : WideChar; Const s : WideString) : SizeInt;
  678. var
  679. i: SizeInt;
  680. pc : pwidechar;
  681. begin
  682. pc:=@s[1];
  683. for i:=1 to length(s) do
  684. begin
  685. if pc^=c then
  686. begin
  687. pos:=i;
  688. exit;
  689. end;
  690. inc(pc);
  691. end;
  692. pos:=0;
  693. end;
  694. { Faster version for a char alone. Must be implemented because }
  695. { pos(c: char; const s: shortstring) also exists, so otherwise }
  696. { using pos(char,pchar) will always call the shortstring version }
  697. { (exact match for first argument), also with $h+ (JM) }
  698. Function Pos (c : Char; Const s : WideString) : SizeInt;
  699. var
  700. i: SizeInt;
  701. wc : widechar;
  702. pc : pwidechar;
  703. begin
  704. wc:=c;
  705. pc:=@s[1];
  706. for i:=1 to length(s) do
  707. begin
  708. if pc^=wc then
  709. begin
  710. pos:=i;
  711. exit;
  712. end;
  713. inc(pc);
  714. end;
  715. pos:=0;
  716. end;
  717. Procedure Delete (Var S : WideString; Index,Size: SizeInt);
  718. Var
  719. LS : SizeInt;
  720. begin
  721. If Length(S)=0 then
  722. exit;
  723. if index<=0 then
  724. exit;
  725. LS:=PWideRec(Pointer(S)-WideFirstOff)^.Len;
  726. if (Index<=LS) and (Size>0) then
  727. begin
  728. UniqueString (S);
  729. if Size+Index>LS then
  730. Size:=LS-Index+1;
  731. if Index+Size<=LS then
  732. begin
  733. Dec(Index);
  734. Move(PWideChar(S)[Index+Size],PWideChar(S)[Index],(LS-Index+1)*sizeof(WideChar));
  735. end;
  736. Setlength(s,LS-Size);
  737. end;
  738. end;
  739. Procedure Insert (Const Source : WideString; Var S : WideString; Index : SizeInt);
  740. var
  741. Temp : WideString;
  742. LS : SizeInt;
  743. begin
  744. If Length(Source)=0 then
  745. exit;
  746. if index <= 0 then
  747. index := 1;
  748. Ls:=Length(S);
  749. if index > LS then
  750. index := LS+1;
  751. Dec(Index);
  752. Pointer(Temp) := NewWideString(Length(Source)+LS);
  753. SetLength(Temp,Length(Source)+LS);
  754. If Index>0 then
  755. move (PWideChar(S)^,PWideChar(Temp)^,Index*sizeof(WideChar));
  756. Move (PWideChar(Source)^,PWideChar(Temp)[Index],Length(Source)*sizeof(WideChar));
  757. If (LS-Index)>0 then
  758. Move(PWideChar(S)[Index],PWideChar(temp)[Length(Source)+index],(LS-Index)*sizeof(WideChar));
  759. S:=Temp;
  760. end;
  761. Procedure SetString (Var S : WideString; Buf : PWideChar; Len : SizeInt);
  762. var
  763. BufLen: SizeInt;
  764. begin
  765. SetLength(S,Len);
  766. If (Buf<>Nil) and (Len>0) then
  767. begin
  768. BufLen := IndexWord(Buf^, Len+1, 0);
  769. If (BufLen>0) and (BufLen < Len) then
  770. Len := BufLen;
  771. Move (Buf[0],S[1],Len*sizeof(WideChar));
  772. PWideChar(Pointer(S)+Len*sizeof(WideChar))^:=#0;
  773. end;
  774. end;
  775. Procedure SetString (Var S : WideString; Buf : PChar; Len : SizeInt);
  776. var
  777. BufLen: SizeInt;
  778. begin
  779. SetLength(S,Len);
  780. If (Buf<>Nil) and (Len>0) then
  781. begin
  782. BufLen := IndexByte(Buf^, Len+1, 0);
  783. If (BufLen>0) and (BufLen < Len) then
  784. Len := BufLen;
  785. Ansi2WideMoveProc(Buf,PWideChar(S),Len);
  786. PWideChar(Pointer(S)+Len*sizeof(WideChar))^:=#0;
  787. end;
  788. end;
  789. Function fpc_Val_Real_WideStr(Const S : WideString; Var Code : ValSInt): ValReal; [public, alias:'FPC_VAL_REAL_WIDESTR']; {$ifdef hascompilerproc} compilerproc; {$endif}
  790. Var
  791. SS : String;
  792. begin
  793. fpc_Val_Real_WideStr := 0;
  794. if length(S) > 255 then
  795. code := 256
  796. else
  797. begin
  798. SS := S;
  799. Val(SS,fpc_Val_Real_WideStr,code);
  800. end;
  801. end;
  802. Function fpc_Val_UInt_WideStr (Const S : WideString; Var Code : ValSInt): ValUInt; [public, alias:'FPC_VAL_UINT_WIDESTR']; {$ifdef hascompilerproc} compilerproc; {$endif}
  803. Var
  804. SS : ShortString;
  805. begin
  806. fpc_Val_UInt_WideStr := 0;
  807. if length(S) > 255 then
  808. code := 256
  809. else
  810. begin
  811. SS := S;
  812. Val(SS,fpc_Val_UInt_WideStr,code);
  813. end;
  814. end;
  815. Function fpc_Val_SInt_WideStr (DestSize: SizeInt; Const S : WideString; Var Code : ValSInt): ValSInt; [public, alias:'FPC_VAL_SINT_WIDESTR']; {$ifdef hascompilerproc} compilerproc; {$endif}
  816. Var
  817. SS : ShortString;
  818. begin
  819. fpc_Val_SInt_WideStr:=0;
  820. if length(S)>255 then
  821. code:=256
  822. else
  823. begin
  824. SS := S;
  825. fpc_Val_SInt_WideStr := int_Val_SInt_ShortStr(DestSize,SS,Code);
  826. end;
  827. end;
  828. {$ifndef CPU64}
  829. Function fpc_Val_qword_WideStr (Const S : WideString; Var Code : ValSInt): qword; [public, alias:'FPC_VAL_QWORD_WIDESTR']; {$ifdef hascompilerproc} compilerproc; {$endif}
  830. Var
  831. SS : ShortString;
  832. begin
  833. fpc_Val_qword_WideStr:=0;
  834. if length(S)>255 then
  835. code:=256
  836. else
  837. begin
  838. SS := S;
  839. Val(SS,fpc_Val_qword_WideStr,Code);
  840. end;
  841. end;
  842. Function fpc_Val_int64_WideStr (Const S : WideString; Var Code : ValSInt): Int64; [public, alias:'FPC_VAL_INT64_WIDESTR']; {$ifdef hascompilerproc} compilerproc; {$endif}
  843. Var
  844. SS : ShortString;
  845. begin
  846. fpc_Val_int64_WideStr:=0;
  847. if length(S)>255 then
  848. code:=256
  849. else
  850. begin
  851. SS := S;
  852. Val(SS,fpc_Val_int64_WideStr,Code);
  853. end;
  854. end;
  855. {$endif CPU64}
  856. procedure fpc_WideStr_Float(d : ValReal;len,fr,rt : SizeInt;var s : WideString);{$ifdef hascompilerproc} compilerproc; {$endif}
  857. var
  858. ss : shortstring;
  859. begin
  860. str_real(len,fr,d,treal_type(rt),ss);
  861. s:=ss;
  862. end;
  863. {$ifdef STR_USES_VALINT}
  864. Procedure fpc_WideStr_SInt(v : ValSint; Len : SizeInt; Var S : WideString);{$ifdef hascompilerproc} compilerproc; {$endif}
  865. {$else}
  866. Procedure fpc_WideStr_Longint(v : Longint; Len : SizeInt; Var S : WideString);{$ifdef hascompilerproc} compilerproc; {$endif}
  867. {$endif}
  868. Var
  869. SS : ShortString;
  870. begin
  871. Str (v:Len,SS);
  872. S:=SS;
  873. end;
  874. {$ifdef STR_USES_VALINT}
  875. Procedure fpc_WideStr_UInt(v : ValUInt;Len : SizeInt; Var S : WideString);{$ifdef hascompilerproc} compilerproc; {$endif}
  876. {$else}
  877. Procedure fpc_WideStr_Longword(v : Longword;Len : SizeInt; Var S : WideString);{$ifdef hascompilerproc} compilerproc; {$endif}
  878. {$endif}
  879. Var
  880. SS : ShortString;
  881. begin
  882. str(v:Len,SS);
  883. S:=SS;
  884. end;
  885. {$ifndef CPU64}
  886. Procedure fpc_WideStr_Int64(v : Int64; Len : SizeInt; Var S : WideString);{$ifdef hascompilerproc} compilerproc; {$endif}
  887. Var
  888. SS : ShortString;
  889. begin
  890. Str (v:Len,SS);
  891. S:=SS;
  892. end;
  893. Procedure fpc_WideStr_Qword(v : Qword;Len : SizeInt; Var S : WideString);{$ifdef hascompilerproc} compilerproc; {$endif}
  894. Var
  895. SS : ShortString;
  896. begin
  897. str(v:Len,SS);
  898. S:=SS;
  899. end;
  900. {$endif CPU64}
  901. function UnicodeToUtf8(Dest: PChar; Source: PWideChar; MaxBytes: SizeInt): SizeInt;{$ifdef SYSTEMINLINE}inline;{$endif}
  902. begin
  903. if assigned(Source) then
  904. Result:=UnicodeToUtf8(Dest,MaxBytes,Source,IndexWord(Source^,-1,0))
  905. else
  906. Result:=0;
  907. end;
  908. function UnicodeToUtf8(Dest: PChar; MaxDestBytes: SizeUInt; Source: PWideChar; SourceChars: SizeUInt): SizeUInt;
  909. var
  910. i,j : SizeUInt;
  911. w : word;
  912. begin
  913. result:=0;
  914. if source=nil then
  915. exit;
  916. i:=0;
  917. j:=0;
  918. if assigned(Dest) then
  919. begin
  920. while (i<SourceChars) and (j<MaxDestBytes) do
  921. begin
  922. w:=word(Source[i]);
  923. case w of
  924. 0..$7f:
  925. begin
  926. Dest[j]:=char(w);
  927. inc(j);
  928. end;
  929. $80..$7ff:
  930. begin
  931. if j+1>=MaxDestBytes then
  932. break;
  933. Dest[j]:=char($c0 or (w shr 6));
  934. Dest[j+1]:=char($80 or (w and $3f));
  935. inc(j,2);
  936. end;
  937. else
  938. begin
  939. if j+2>=MaxDestBytes then
  940. break;
  941. Dest[j]:=char($e0 or (w shr 12));
  942. Dest[j+1]:=char($80 or ((w shr 6)and $3f));
  943. Dest[j+2]:=char($80 or (w and $3f));
  944. inc(j,3);
  945. end;
  946. end;
  947. inc(i);
  948. end;
  949. if j>MaxDestBytes-1 then
  950. j:=MaxDestBytes-1;
  951. Dest[j]:=#0;
  952. end
  953. else
  954. begin
  955. while i<SourceChars do
  956. begin
  957. case word(Source[i]) of
  958. $0..$7f:
  959. inc(j);
  960. $80..$7ff:
  961. inc(j,2);
  962. else
  963. inc(j,3);
  964. end;
  965. end;
  966. end;
  967. result:=j+1;
  968. end;
  969. function Utf8ToUnicode(Dest: PWideChar; Source: PChar; MaxChars: SizeInt): SizeInt;{$ifdef SYSTEMINLINE}inline;{$endif}
  970. begin
  971. if assigned(Source) then
  972. Result:=Utf8ToUnicode(Dest,MaxChars,Source,strlen(Source))
  973. else
  974. Result:=0;
  975. end;
  976. function Utf8ToUnicode(Dest: PWideChar; MaxDestChars: SizeUInt; Source: PChar; SourceBytes: SizeUInt): SizeUInt;
  977. var
  978. i,j : SizeUInt;
  979. w : word;
  980. b : byte;
  981. begin
  982. result:=0;
  983. i:=0;
  984. j:=0;
  985. if assigned(Dest) then
  986. begin
  987. while (j<MaxDestChars) and (i<SourceBytes) do
  988. begin
  989. b:=byte(Source[i]);
  990. inc(i);
  991. // 2 or 3 bytes?
  992. if b>=$80 then
  993. begin
  994. w:=b and $3c;
  995. if i>=SourceBytes then
  996. exit;
  997. // 3 bytes?
  998. if (b and $20)<>0 then
  999. begin
  1000. b:=byte(Source[i]);
  1001. inc(i);
  1002. if i>=SourceBytes then
  1003. exit;
  1004. if (b and $c0)<>$80 then
  1005. exit;
  1006. w:=(w shl 6) or (b and $3c);
  1007. end;
  1008. b:=byte(Source[i]);
  1009. w:=(w shl 6) or (b and $3c);
  1010. if (b and $c0)<>$80 then
  1011. exit;
  1012. inc(i);
  1013. end;
  1014. Dest[j]:=WideChar(w);
  1015. inc(j);
  1016. end;
  1017. end
  1018. else
  1019. begin
  1020. while i<SourceBytes do
  1021. begin
  1022. b:=byte(Source[i]);
  1023. inc(i);
  1024. // 2 or 3 bytes?
  1025. if b>=$80 then
  1026. begin
  1027. if i>=SourceBytes then
  1028. exit;
  1029. // 3 bytes?
  1030. if (b and $20)<>0 then
  1031. begin
  1032. b:=byte(Source[i]);
  1033. inc(i);
  1034. if i>=SourceBytes then
  1035. exit;
  1036. if (b and $c0)<>$80 then
  1037. exit;
  1038. end;
  1039. if (byte(Source[i]) and $c0)<>$80 then
  1040. exit;
  1041. inc(i);
  1042. end;
  1043. inc(j);
  1044. end;
  1045. end;
  1046. result:=j+1;
  1047. end;
  1048. function UTF8Encode(const s : WideString) : UTF8String;
  1049. var
  1050. i : SizeInt;
  1051. hs : UTF8String;
  1052. begin
  1053. result:='';
  1054. if s='' then
  1055. exit;
  1056. SetLength(hs,length(s)*3);
  1057. i:=UnicodeToUtf8(pchar(hs),length(hs)+1,PWideChar(s),length(s));
  1058. if i>0 then
  1059. begin
  1060. SetLength(hs,i-1);
  1061. result:=hs;
  1062. end;
  1063. end;
  1064. function UTF8Decode(const s : UTF8String): WideString;
  1065. var
  1066. i : SizeInt;
  1067. hs : WideString;
  1068. begin
  1069. result:='';
  1070. if s='' then
  1071. exit;
  1072. SetLength(hs,length(s));
  1073. i:=Utf8ToUnicode(PWideChar(hs),length(hs)+1,pchar(s),length(s));
  1074. if i>0 then
  1075. begin
  1076. SetLength(hs,i-1);
  1077. result:=hs;
  1078. end;
  1079. end;
  1080. function AnsiToUtf8(const s : ansistring): UTF8String;{$ifdef SYSTEMINLINE}inline;{$endif}
  1081. begin
  1082. Result:=Utf8Encode(s);
  1083. end;
  1084. function Utf8ToAnsi(const s : UTF8String) : ansistring;{$ifdef SYSTEMINLINE}inline;{$endif}
  1085. begin
  1086. Result:=Utf8Decode(s);
  1087. end;
  1088. {
  1089. $Log$
  1090. Revision 1.46 2004-11-17 22:19:04 peter
  1091. internconst, internproc and some external declarations moved to interface
  1092. Revision 1.45 2004/10/24 20:01:42 peter
  1093. * saveregisters calling convention is obsolete
  1094. Revision 1.44 2004/09/29 14:55:49 mazen
  1095. * widestring conversion routines takes a widechar so no
  1096. information is lost
  1097. Revision 1.43 2004/09/18 10:23:08 jonas
  1098. - removed unused local variable
  1099. * fixed bug in Utf8ToUnicode (use of uninitialised variable)
  1100. Revision 1.42 2004/07/18 20:21:44 florian
  1101. + several unicode (to/from utf-8 conversion) stuff added
  1102. * some longint -> SizeInt changes
  1103. Revision 1.41 2004/07/12 17:58:19 peter
  1104. * remove maxlen field from ansistring/widestrings
  1105. Revision 1.40 2004/07/02 21:21:09 peter
  1106. * decr ref doesn't reset pointer
  1107. * finalize resets pointer for astring,wstring
  1108. Revision 1.39 2004/05/31 14:31:57 peter
  1109. * remove comment warnings
  1110. Revision 1.38 2004/05/29 15:39:08 florian
  1111. * the decr functions set the data now to nil
  1112. Revision 1.37 2004/05/01 23:55:18 peter
  1113. * replace strlenint with sizeint
  1114. Revision 1.36 2004/04/29 18:59:43 peter
  1115. * str() helpers now also use valint/valuint
  1116. * int64/qword helpers disabled for cpu64
  1117. Revision 1.35 2004/01/22 22:09:05 peter
  1118. * finalize needs to reset to nil after decr_ref
  1119. Revision 1.34 2003/11/29 17:27:05 michael
  1120. + Added overloaded version of SetWideStringManager without old parameter
  1121. Revision 1.33 2003/11/28 20:36:13 michael
  1122. + Added WideStringManager
  1123. Revision 1.32 2003/11/05 15:33:51 florian
  1124. * made Index* usage consistent with astrings.inc
  1125. Revision 1.31 2003/06/17 19:24:08 jonas
  1126. * fixed conversion of fpc_*str_unique to compilerproc
  1127. Revision 1.30 2003/06/17 16:38:53 jonas
  1128. * fpc_ansistr|widestr_unique is now a function so it can be used as
  1129. compilerproc
  1130. Revision 1.29 2003/05/01 08:05:23 florian
  1131. * started to make the rtl 64 bit save by introducing SizeInt and SizeUInt (similar to size_t of C)
  1132. Revision 1.28 2002/12/29 16:59:17 peter
  1133. * implemented some more conversions
  1134. Revision 1.27 2002/12/15 22:33:12 peter
  1135. * SetString(WideString,[PChar|PWideChar],Len) added
  1136. Revision 1.26 2002/12/14 19:16:45 sg
  1137. * Ported improvements from the AnsiString equivalents to NewWideString and
  1138. fpc_WideStr_SetLength
  1139. Revision 1.25 2002/12/07 14:35:34 carl
  1140. - avoid warnings (add typecast)
  1141. Revision 1.24 2002/10/10 16:08:50 florian
  1142. + several widestring/pwidechar related helpers added
  1143. Revision 1.23 2002/10/02 18:21:52 peter
  1144. * Copy() changed to internal function calling compilerprocs
  1145. * FPC_SHORTSTR_COPY renamed to FPC_SHORTSTR_ASSIGN because of the
  1146. new copy functions
  1147. Revision 1.22 2002/09/26 21:50:38 florian
  1148. + some WideString<->AnsiString conversion functions added
  1149. Revision 1.21 2002/09/14 11:20:50 carl
  1150. * Delphi compatibility fix (with string routines)
  1151. Revision 1.20 2002/09/07 21:16:45 carl
  1152. * cardinal -> longword
  1153. Revision 1.19 2002/09/07 15:07:46 peter
  1154. * old logs removed and tabs fixed
  1155. Revision 1.18 2002/07/29 21:28:17 florian
  1156. * several fixes to get further with linux/ppc system unit compilation
  1157. Revision 1.17 2002/04/26 15:19:05 peter
  1158. * use saveregisters for incr routines, saves also problems with
  1159. the optimizer
  1160. Revision 1.16 2002/04/25 20:14:57 peter
  1161. * updated compilerprocs
  1162. * incr ref count has now a value argument instead of var
  1163. }