wstrings.inc 33 KB

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