wstrings.inc 33 KB

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