justrings.inc 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 1999-2005 by Florian Klaempfl,
  4. Copyright (c) 2011 by Jonas Maebe,
  5. members of the Free Pascal development team.
  6. This file implements support routines for UTF-8 strings 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. { unicodestring is a plain java.lang.String }
  14. {$define FPC_UNICODESTRING_TYPE_DEFINED}
  15. { helpers for converting between Windows and Java code page identifiers }
  16. {$i jwin2javacharset.inc}
  17. {$define FPC_HAS_DEFAULT_UNICODE_2_ANSI_MOVE}
  18. procedure DefaultUnicode2AnsiMove(source:punicodechar;var dest:RawByteString;cp : TSystemCodePage;len:SizeInt);
  19. var
  20. localencoder: JNCCharsetEncoder;
  21. inbuf: JNCharBuffer;
  22. outbuf: JNByteBuffer;
  23. begin
  24. localencoder:=widestringmanager.encoder.getForCodePage(cp);
  25. localencoder.reset;
  26. localencoder.onMalformedInput(JNCCodingErrorAction.fREPLACE);
  27. localencoder.onUnmappableCharacter(JNCCodingErrorAction.fREPLACE);
  28. inbuf:=JNCharBuffer.wrap(TJCharArray(source),0,len);
  29. outbuf:=localencoder.encode(inbuf);
  30. setlength(dest,outbuf.limit);
  31. { "The buffer's position will be zero and its limit will *follow* the last
  32. byte written" -> we already have a terminating zero }
  33. outbuf.get(TJByteArray(AnsiStringClass(dest).fdata),0,outbuf.limit);
  34. { already null-terminated because of setlength }
  35. SetCodePage(dest,cp,false);
  36. end;
  37. {$define FPC_HAS_DEFAULT_ANSI_2_UNICODE}
  38. procedure DefaultAnsi2UnicodeMove(source:pchar;cp : TSystemCodePage;var dest:unicodestring;len:SizeInt);
  39. var
  40. localdecoder: JNCCharsetDecoder;
  41. inbuf: JNByteBuffer;
  42. outbuf: JNCharBuffer;
  43. begin
  44. localdecoder:=widestringmanager.decoder.getForCodePage(cp);
  45. localdecoder.reset;
  46. localdecoder.onMalformedInput(JNCCodingErrorAction.fREPLACE);
  47. localdecoder.onUnmappableCharacter(JNCCodingErrorAction.fREPLACE);
  48. inbuf:=JNByteBuffer.wrap(TJByteArray(source),0,len);
  49. outbuf:=localdecoder.decode(inbuf);
  50. dest:=outbuf.toString;
  51. end;
  52. {
  53. This file contains the implementation of the UnicodeString type,
  54. which on the Java platforms is an alias for java.lang.String
  55. }
  56. {$define FPC_HAS_NEW_UNICODESTRING}
  57. Function NewUnicodeString(Len : SizeInt) : JLString;
  58. {
  59. Allocate a new UnicodeString on the heap.
  60. initialize it to zero length and reference count 1.
  61. }
  62. var
  63. data: array of jchar;
  64. begin
  65. setlength(data,len);
  66. result:=JLString.create(data);
  67. end;
  68. { lie, not required }
  69. {$define FPC_HAS_UNICODESTR_DECR_REF}
  70. {$define FPC_HAS_UNICODESTR_INCR_REF}
  71. {$define FPC_HAS_UNICODESTR_TO_SHORTSTR}
  72. procedure fpc_UnicodeStr_To_ShortStr (out res: ShortString;const S2 : UnicodeString); [Public, alias: 'FPC_UNICODESTR_TO_SHORTSTR'];compilerproc;
  73. {
  74. Converts a UnicodeString to a ShortString;
  75. }
  76. Var
  77. Size : SizeInt;
  78. temp : ansistring;
  79. begin
  80. res:='';
  81. Size:=Length(S2);
  82. if Size>0 then
  83. begin
  84. temp:=s2;
  85. res:=temp;
  86. end;
  87. end;
  88. {$define FPC_HAS_SHORTSTR_TO_UNICODESTR}
  89. Function fpc_ShortStr_To_UnicodeStr (Const S2 : ShortString): UnicodeString;compilerproc;
  90. {
  91. Converts a ShortString to a UnicodeString;
  92. }
  93. Var
  94. Size : SizeInt;
  95. begin
  96. result:='';
  97. Size:=Length(S2);
  98. if Size>0 then
  99. widestringmanager.Ansi2UnicodeMoveProc(PChar(ShortstringClass(@S2).fdata),DefaultSystemCodePage,result,Size);
  100. end;
  101. {$define FPC_HAS_UNICODESTR_TO_ANSISTR}
  102. Function fpc_UnicodeStr_To_AnsiStr (const S2 : UnicodeString{$ifdef FPC_HAS_CPSTRING};cp : TSystemCodePage{$endif FPC_HAS_CPSTRING}): AnsiString; compilerproc;
  103. {
  104. Converts a UnicodeString to an AnsiString
  105. }
  106. Var
  107. Size : SizeInt;
  108. begin
  109. cp:=TranslatePlaceholderCP(cp);
  110. { avoid codepage conversion -- why isn't the result rawbytestring? }
  111. pointer(result):=pointer(AnsistringClass.Create(s2,cp));
  112. end;
  113. {$define FPC_HAS_ANSISTR_TO_UNICODESTR}
  114. Function fpc_AnsiStr_To_UnicodeStr (Const S2 : RawByteString): UnicodeString; compilerproc;
  115. {
  116. Converts an AnsiString to a UnicodeString;
  117. }
  118. Var
  119. Size : SizeInt;
  120. begin
  121. if length(s2)=0 then
  122. result:=''
  123. else
  124. result:=AnsistringClass(S2).toString;
  125. end;
  126. {$define FPC_HAS_UNICODESTR_TO_WIDESTR}
  127. Function fpc_UnicodeStr_To_WideStr (const S2 : UnicodeString): WideString; compilerproc;
  128. begin
  129. result:=s2;
  130. end;
  131. {$define FPC_HAS_WIDESTR_TO_UNICODESTR}
  132. Function fpc_WideStr_To_UnicodeStr (Const S2 : WideString): UnicodeString; compilerproc;
  133. begin
  134. result:=s2;
  135. end;
  136. {$define FPC_HAS_PWIDECHAR_TO_UNICODESTR}
  137. Function fpc_PWideChar_To_UnicodeStr(const p : pwidechar): unicodestring; compilerproc;
  138. var
  139. Size : SizeInt;
  140. begin
  141. result:='';
  142. if p=nil then
  143. exit;
  144. size:=0;
  145. while p[size]<>#0 do
  146. inc(size);
  147. Setlength(result,Size);
  148. if Size>0 then
  149. result:=JLString.Create(TJCharArray(p),0,Size);
  150. end;
  151. { lie, not used by compiler }
  152. {$define FPC_HAS_PUNICODECHAR_TO_SHORTSTR}
  153. {$define FPC_HAS_PWIDECHAR_TO_ANSISTR}
  154. Function fpc_PWideChar_To_AnsiStr(const p : pwidechar{$ifdef FPC_HAS_CPSTRING};cp : TSystemCodePage{$endif FPC_HAS_CPSTRING}): ansistring; compilerproc;
  155. begin
  156. result:='';
  157. if (p=nil) or
  158. (p^=#0) then
  159. exit;
  160. cp:=TranslatePlaceholderCP(cp);
  161. pointer(result):=pointer(AnsistringClass.Create(unicodestring(p),cp));
  162. end;
  163. {$define FPC_HAS_PWIDECHAR_TO_SHORTSTR}
  164. procedure fpc_PWideChar_To_ShortStr(out res : shortstring;const p : pwidechar); compilerproc;
  165. begin
  166. res:='';
  167. if (p=nil) or
  168. (p^=#0) then
  169. exit;
  170. res:=unicodestring(p);
  171. end;
  172. { lie, not required for JVM target }
  173. {$define FPC_HAS_UNICODESTR_ASSIGN}
  174. {$define FPC_HAS_UNICODESTR_CONCAT}
  175. procedure fpc_UnicodeStr_Concat (var DestS:Unicodestring;const S1,S2 : UnicodeString); compilerproc;
  176. Var
  177. sb: JLStringBuilder;
  178. begin
  179. { only assign if s1 or s2 is empty }
  180. if (length(S1)=0) then
  181. begin
  182. DestS:=s2;
  183. exit;
  184. end;
  185. if (length(S2)=0) then
  186. begin
  187. DestS:=s1;
  188. exit;
  189. end;
  190. sb:=JLStringBuilder.create(S1);
  191. sb.append(s2);
  192. DestS:=sb.toString;
  193. end;
  194. {$define FPC_HAS_UNICODESTR_CONCAT_MULTI}
  195. procedure fpc_UnicodeStr_Concat_multi (var DestS:Unicodestring;const sarr:array of Unicodestring); compilerproc;
  196. Var
  197. i : Longint;
  198. Size,NewSize : SizeInt;
  199. sb: JLStringBuilder;
  200. begin
  201. { First calculate size of the result so we can allocate a StringBuilder of
  202. the right size }
  203. NewSize:=0;
  204. for i:=low(sarr) to high(sarr) do
  205. inc(Newsize,length(sarr[i]));
  206. sb:=JLStringBuilder.create(NewSize);
  207. for i:=low(sarr) to high(sarr) do
  208. begin
  209. if length(sarr[i])>0 then
  210. sb.append(sarr[i]);
  211. end;
  212. dests:=sb.toString;
  213. end;
  214. {$define FPC_HAS_CHAR_TO_UCHAR}
  215. Function fpc_Char_To_UChar(const c : AnsiChar): UnicodeChar; compilerproc;
  216. var
  217. arr: array[0..0] of ansichar;
  218. w: unicodestring;
  219. begin
  220. arr[0]:=c;
  221. widestringmanager.Ansi2UnicodeMoveProc(pansichar(@arr),DefaultSystemCodePage,w,1);
  222. fpc_Char_To_UChar:=w[1];
  223. end;
  224. {$define FPC_HAS_CHAR_TO_UNICODESTR}
  225. Function fpc_Char_To_UnicodeStr(const c : AnsiChar): UnicodeString; compilerproc;
  226. {
  227. Converts a AnsiChar to a UnicodeString;
  228. }
  229. var
  230. arr: array[0..0] of ansichar;
  231. begin
  232. arr[0]:=c;
  233. widestringmanager.Ansi2UnicodeMoveProc(pansichar(@arr),DefaultSystemCodePage,result,1);
  234. end;
  235. {$define FPC_HAS_UCHAR_TO_CHAR}
  236. Function fpc_UChar_To_Char(const c : UnicodeChar): Char; compilerproc;
  237. {
  238. Converts a UnicodeChar to a Char;
  239. }
  240. var
  241. u: unicodestring;
  242. s: RawByteString;
  243. arr: array[0..0] of unicodechar;
  244. begin
  245. arr[0]:=c;
  246. widestringmanager.Unicode2AnsiMoveProc(punicodechar(@arr), s, DefaultSystemCodePage, 1);
  247. if length(s)=1 then
  248. fpc_UChar_To_Char:= s[1]
  249. else
  250. fpc_UChar_To_Char:='?';
  251. end;
  252. { lie, unused for this target since widechar = unicodechar }
  253. {$define FPC_HAS_UCHAR_TO_UNICODESTR}
  254. Function fpc_UChar_To_UnicodeStr(const c : UnicodeChar): UnicodeString; compilerproc;
  255. {
  256. Converts a UnicodeChar to a UnicodeString;
  257. }
  258. var
  259. arr: array[0..0] of UnicodeChar;
  260. begin
  261. arr[0]:=c;
  262. result:=JLString.create(arr);
  263. end;
  264. {$define FPC_HAS_UCHAR_TO_ANSISTR}
  265. Function fpc_UChar_To_AnsiStr(const c : UnicodeChar{$ifdef FPC_HAS_CPSTRING};cp : TSystemCodePage{$endif FPC_HAS_CPSTRING}): AnsiString; compilerproc;
  266. {
  267. Converts a UnicodeChar to a AnsiString;
  268. }
  269. var
  270. u: unicodestring;
  271. arr: array[0..0] of unicodechar;
  272. begin
  273. arr[0]:=c;
  274. cp:=TranslatePlaceholderCP(cp);
  275. widestringmanager.Unicode2AnsiMoveProc(punicodechar(@arr), RawByteString(fpc_UChar_To_AnsiStr), cp, 1);
  276. end;
  277. {$define FPC_HAS_UCHAR_TO_SHORTSTR}
  278. function fpc_UChar_To_ShortStr(const c : UnicodeChar): shortstring; compilerproc;
  279. {
  280. Converts a UnicodeChar to a AnsiString;
  281. }
  282. var
  283. u: unicodestring;
  284. begin
  285. u:=c;
  286. result:=u;
  287. end;
  288. {$ifndef FPC_HAS_UCHAR_TO_ANSISTR}
  289. {$define FPC_HAS_UCHAR_TO_ANSISTR}
  290. Function fpc_UChar_To_AnsiStr(const c : UnicodeChar{$ifdef FPC_HAS_CPSTRING};cp : TSystemCodePage{$endif FPC_HAS_CPSTRING}): AnsiString; compilerproc;
  291. {
  292. Converts a UnicodeChar to a AnsiString;
  293. }
  294. var
  295. arr: array[0..0] of unicodechar;
  296. {$ifndef FPC_HAS_CPSTRING}
  297. cp : TSystemCodePage;
  298. {$endif FPC_HAS_CPSTRING}
  299. begin
  300. {$ifndef FPC_HAS_CPSTRING}
  301. cp:=DefaultSystemCodePage;
  302. {$endif FPC_HAS_CPSTRING}
  303. cp:=TranslatePlaceholderCP(cp);
  304. arr[0]:=c;
  305. widestringmanager.Unicode2AnsiMoveProc(punicodechar(@arr[0]), fpc_UChar_To_AnsiStr, cp, 1);
  306. end;
  307. {$endif FPC_HAS_UCHAR_TO_ANSISTR}
  308. {$define FPC_HAS_PCHAR_TO_UNICODESTR}
  309. Function fpc_PChar_To_UnicodeStr(const p : pchar): UnicodeString; compilerproc;
  310. var
  311. i, len: longint;
  312. arr: TAnsiCharArray;
  313. begin
  314. arr:=TAnsiCharArray(p);
  315. i:=0;
  316. while arr[i]<>#0 do
  317. inc(i);
  318. if i<>0 then
  319. widestringmanager.Ansi2UnicodeMoveProc(P,DefaultSystemCodePage,fpc_PChar_To_UnicodeStr,i)
  320. else
  321. result:=''
  322. end;
  323. Function real_widechararray_to_unicodestr(const arr: array of widechar; zerobased: boolean): Unicodestring;
  324. var
  325. i : SizeInt;
  326. foundnull : boolean;
  327. begin
  328. if (zerobased) then
  329. begin
  330. foundnull:=false;
  331. i:=0;
  332. for i:=low(arr) to high(arr) do
  333. if arr[i]=#0 then
  334. begin
  335. foundnull:=true;
  336. break;
  337. end;
  338. if not foundnull then
  339. i := high(arr)+1;
  340. end
  341. else
  342. i := high(arr)+1;
  343. result:=JLString.create(arr,0,i);
  344. end;
  345. {$define FPC_HAS_WIDECHARARRAY_TO_UNICODESTR}
  346. Function fpc_WideCharArray_To_UnicodeStr(const arr: array of widechar; zerobased: boolean = true): UnicodeString; compilerproc;
  347. begin
  348. result:=real_widechararray_to_unicodestr(arr,zerobased);
  349. end;
  350. { due to their names, the following procedures should be in wstrings.inc,
  351. however, the compiler generates code using this functions on all platforms }
  352. {$define FPC_HAS_WIDECHARARRAY_TO_SHORTSTR}
  353. procedure fpc_WideCharArray_To_ShortStr(out res : shortstring;const arr: array of widechar; zerobased: boolean = true);[public,alias:'FPC_WIDECHARARRAY_TO_SHORTSTR']; compilerproc;
  354. begin
  355. res:=real_widechararray_to_unicodestr(arr,zerobased);
  356. end;
  357. {$define FPC_HAS_WIDECHARARRAY_TO_WIDESTR}
  358. Function fpc_WideCharArray_To_WideStr(const arr: array of widechar; zerobased: boolean = true): WideString; compilerproc;
  359. begin
  360. result:=real_widechararray_to_unicodestr(arr,zerobased);
  361. end;
  362. {$define FPC_HAS_UNICODESTR_TO_CHARARRAY}
  363. procedure fpc_unicodestr_to_chararray(out res: array of AnsiChar; const src: UnicodeString); compilerproc;
  364. var
  365. len: longint;
  366. temp: array of jbyte;
  367. csname: unicodestring;
  368. begin
  369. len:=length(src);
  370. { make sure we don't dereference src if it can be nil (JM) }
  371. if len>0 then
  372. begin
  373. csname:=win2javacs(DefaultSystemCodePage);
  374. if csname='<unsupported>' then
  375. csname:='US-ASCII';
  376. temp:=JLString(src).getBytes(csname);
  377. len:=length(temp);
  378. if len>length(res) then
  379. len:=length(res);
  380. JLSystem.ArrayCopy(JLObject(temp),0,JLObject(@res),0,len);
  381. end;
  382. if len<=high(res) then
  383. JUArrays.fill(TJByteArray(@res),len,high(res),0);
  384. end;
  385. function fpc_unicodestr_setchar(const s: UnicodeString; const index: longint; const ch: unicodechar): UnicodeString; compilerproc;
  386. var
  387. sb: JLStringBuilder;
  388. begin
  389. sb:=JLStringBuilder.create(s);
  390. { string indexes are 1-based in Pascal, 0-based in Java }
  391. sb.setCharAt(index-1,ch);
  392. result:=sb.toString();
  393. end;
  394. {$define FPC_HAS_ANSISTR_TO_WIDECHARARRAY}
  395. procedure fpc_ansistr_to_widechararray(out res: array of widechar; const src: RawByteString); compilerproc;
  396. var
  397. len: SizeInt;
  398. temp: widestring;
  399. begin
  400. len := length(src);
  401. { make sure we don't dereference src if it can be nil (JM) }
  402. if len > 0 then
  403. temp:=src;
  404. len := length(temp);
  405. if len > high(res)+1 then
  406. len := high(res)+1;
  407. JLString(temp).getChars(0,len,res,0);
  408. JUArrays.fill(res,len,high(res),#0);
  409. end;
  410. {$define FPC_HAS_SHORTSTR_TO_WIDECHARARRAY}
  411. procedure fpc_shortstr_to_widechararray(out res: array of widechar; const src: ShortString); compilerproc;
  412. var
  413. len: longint;
  414. temp : unicodestring;
  415. begin
  416. len := length(src);
  417. { temp is initialized with an empty string, so no need to convert src in case
  418. it's also empty}
  419. if len > 0 then
  420. temp:=src;
  421. len := length(temp);
  422. if len > high(res)+1 then
  423. len := high(res)+1;
  424. JLString(temp).getChars(0,len,res,0);
  425. JUArrays.fill(res,len,high(res),#0);
  426. end;
  427. {$define FPC_HAS_UNICODESTR_TO_WIDECHARARRAY}
  428. procedure fpc_unicodestr_to_widechararray(out res: array of widechar; const src: UnicodeString); compilerproc;
  429. var
  430. i, len: SizeInt;
  431. begin
  432. len := length(src);
  433. if len > length(res) then
  434. len := length(res);
  435. JLString(src).getChars(0,len,res,0);
  436. end;
  437. {$define FPC_HAS_UNICODESTR_COMPARE}
  438. Function fpc_UnicodeStr_Compare(const S1,S2 : UnicodeString): SizeInt; compilerproc;
  439. {
  440. Compares 2 UnicodeStrings;
  441. The result is
  442. <0 if S1<S2
  443. 0 if S1=S2
  444. >0 if S1>S2
  445. }
  446. Var
  447. MaxI,Temp : SizeInt;
  448. begin
  449. if JLObject(S1)=JLObject(S2) then
  450. begin
  451. result:=0;
  452. exit;
  453. end;
  454. result:=JLString(S1).compareTo(S2);
  455. end;
  456. {$define FPC_HAS_UNICODESTR_COMPARE_EQUAL}
  457. Function fpc_UnicodeStr_Compare_Equal(const S1,S2 : UnicodeString): SizeInt; compilerproc;
  458. {
  459. Compares 2 UnicodeStrings for equality only;
  460. The result is
  461. 0 if S1=S2
  462. <>0 if S1<>S2
  463. }
  464. Var
  465. MaxI : SizeInt;
  466. begin
  467. result:=ord(not JLString(S1).equals(JLString(S2)));
  468. end;
  469. { lie, not required for this target }
  470. {$define FPC_HAS_UNICODESTR_RANGECHECK}
  471. {$define FPC_HAS_UNICODESTR_SETLENGTH}
  472. Procedure fpc_UnicodeStr_SetLength(Var S : UnicodeString; l : SizeInt);[Public,Alias : 'FPC_UNICODESTR_SETLENGTH']; compilerproc;
  473. {
  474. Sets The length of string S to L.
  475. Makes sure S is unique, and contains enough room.
  476. Returns new val
  477. }
  478. Var
  479. result: UnicodeString;
  480. movelen: SizeInt;
  481. chars: array of widechar;
  482. strlen: SizeInt;
  483. begin
  484. if (l>0) then
  485. begin
  486. if JLObject(S)=nil then
  487. begin
  488. { Need a completely new string...}
  489. result:=NewUnicodeString(l);
  490. end
  491. { no need to create a new string, since Java strings are immutable }
  492. else
  493. begin
  494. strlen:=length(s);
  495. if l=strlen then
  496. result:=s
  497. else if (l<strlen) then
  498. result:=JLString(s).substring(0,l)
  499. else
  500. begin
  501. setlength(chars,l);
  502. JLString(s).getChars(0,strlen,chars,0);
  503. result:=JLString.create(chars,0,l)
  504. end;
  505. end
  506. end
  507. else
  508. begin
  509. result:='';
  510. end;
  511. S:=Result;
  512. end;
  513. {*****************************************************************************
  514. Public functions, In interface.
  515. *****************************************************************************}
  516. {$define FPC_HAS_STRING_LEN_TO_WIDECHAR}
  517. function StringToWideChar(const Src : RawByteString;Dest : PWideChar;DestSize : SizeInt) : PWideChar;
  518. var
  519. temp: widestring;
  520. Len: SizeInt;
  521. begin
  522. temp:=src;
  523. Len:=Length(temp);
  524. if DestSize<=Len then
  525. Len:=Destsize-1;
  526. JLString(temp).getChars(0,Len,TJCharArray(Dest),0);
  527. Dest[Len]:=#0;
  528. result:=Dest;
  529. end;
  530. {$define FPC_HAS_UNICODECHAR_LEN_TO_STRING}
  531. function UnicodeCharLenToString(S : PUnicodeChar;Len : SizeInt) : UnicodeString;
  532. begin
  533. result:=JLString.Create(TJCharArray(S),0,len);
  534. end;
  535. {$define FPC_HAS_WIDECHAR_LEN_TO_STRING}
  536. function WideCharLenToString(S : PWideChar;Len : SizeInt) : UnicodeString;
  537. begin
  538. result:=JLString.Create(TJCharArray(S),0,len);
  539. end;
  540. {$define FPC_HAS_UNICODESTR_UNIQUE}
  541. Function fpc_unicodestr_Unique(var S : JLObject): JLObject; compilerproc;
  542. begin
  543. result:=s;
  544. end;
  545. { the publicly accessible uniquestring function is declared as
  546. "external name 'FPC_UNICODESTR_UNIQUE'", which is normally an alias for
  547. the fpc_unicodestr_Unique compiler proc; since one is a function and the
  548. other a procedure that sort of hackery doesn't work for the JVM -> create
  549. a separate procedure for that (since Java strings are immutable, they are
  550. always unique though) }
  551. procedure FPC_UNICODESTR_UNIQUE(var S : UnicodeString);
  552. begin
  553. { do nothing }
  554. end;
  555. {$define FPC_HAS_UNICODESTR_COPY}
  556. Function Fpc_UnicodeStr_Copy (Const S : UnicodeString; Index,Size : SizeInt) : UnicodeString;compilerproc;
  557. begin
  558. dec(index);
  559. if Index < 0 then
  560. Index := 0;
  561. { Check Size. Accounts for Zero-length S, the double check is needed because
  562. Size can be maxint and will get <0 when adding index }
  563. if (Size>Length(S)) or
  564. (Index+Size>Length(S)) then
  565. Size:=Length(S)-Index;
  566. If Size>0 then
  567. result:=JLString(s).subString(Index,Index+Size)
  568. else
  569. result:='';
  570. end;
  571. {$define FPC_HAS_POS_UNICODESTR_UNICODESTR}
  572. Function Pos (Const Substr : UnicodeString; Const Source : UnicodeString; Offset: Sizeint = 1) : SizeInt;
  573. begin
  574. Pos:=0;
  575. if (Length(SubStr)>0) and (Offset>0) and (Offset<=Length(Source)) then
  576. Pos:=JLString(Source).indexOf(SubStr,Offset-1)+1
  577. end;
  578. { Faster version for a unicodechar alone }
  579. {$define FPC_HAS_POS_UNICODECHAR_UNICODESTR}
  580. Function Pos (c : UnicodeChar; Const s : UnicodeString; Offset: Sizeint = 1) : SizeInt;
  581. begin
  582. Pos:=0;
  583. if (Offset>0) and (Offset<=Length(s)) then
  584. Pos:=JLString(s).indexOf(ord(c),Offset-1)+1;
  585. end;
  586. { Faster version for a char alone. Must be implemented because }
  587. { pos(c: char; const s: shortstring) also exists, so otherwise }
  588. { using pos(char,pchar) will always call the shortstring version }
  589. { (exact match for first argument), also with $h+ (JM) }
  590. {$define FPC_HAS_POS_CHAR_UNICODESTR}
  591. Function Pos (c : AnsiChar; Const s : UnicodeString; Offset: Sizeint = 1) : SizeInt;
  592. var
  593. i: SizeInt;
  594. wc : unicodechar;
  595. begin
  596. wc:=c;
  597. result:=Pos(wc,s,Offset);
  598. end;
  599. {$define FPC_HAS_DELETE_UNICODESTR}
  600. Procedure {$ifdef VER3_0}Delete{$else}fpc_unicodestr_delete{$endif} (Var S : UnicodeString; Index,Size: SizeInt);
  601. Var
  602. LS : SizeInt;
  603. sb: JLStringBuilder;
  604. begin
  605. LS:=Length(S);
  606. if (Index>LS) or (Index<=0) or (Size<=0) then
  607. exit;
  608. { (Size+Index) will overflow if Size=MaxInt. }
  609. if Size>LS-Index then
  610. Size:=LS-Index+1;
  611. if Size<=LS-Index then
  612. begin
  613. Dec(Index);
  614. sb:=JLStringBuilder.Create(s);
  615. sb.delete(index,size);
  616. s:=sb.toString;
  617. end
  618. else
  619. s:=JLString(s).substring(0,index-1);
  620. end;
  621. {$define FPC_HAS_INSERT_UNICODESTR}
  622. Procedure {$ifdef VER3_0}Insert{$else}fpc_unicodestr_insert{$endif} (Const Source : UnicodeString; Var S : UnicodeString; Index : SizeInt);
  623. var
  624. Temp : UnicodeString;
  625. LS : SizeInt;
  626. sb : JLStringBuilder;
  627. begin
  628. If Length(Source)=0 then
  629. exit;
  630. if index <= 0 then
  631. index := 1;
  632. Ls:=Length(S);
  633. if index > LS then
  634. index := LS+1;
  635. Dec(Index);
  636. sb:=JLStringBuilder.Create(S);
  637. sb.insert(Index,Source);
  638. S:=sb.toString;
  639. end;
  640. {$define FPC_HAS_UPCASE_UNICODECHAR}
  641. Function UpCase(c:UnicodeChar):UnicodeChar;
  642. begin
  643. result:=JLCharacter.toUpperCase(c);
  644. end;
  645. {$define FPC_HAS_UPCASE_UNICODESTR}
  646. function UpCase(const s : UnicodeString) : UnicodeString;
  647. begin
  648. result:=JLString(s).toUpperCase;
  649. end;
  650. {$define FPC_HAS_LOWERCASE_UNICODECHAR}
  651. Function LowerCase(c:UnicodeChar):UnicodeChar;
  652. begin
  653. result:=JLCharacter.toLowerCase(c);
  654. end;
  655. {$define FPC_HAS_LOWERCASE_UNICODESTR}
  656. function LowerCase(const s : UnicodeString) : UnicodeString;
  657. begin
  658. result:=JLString(s).toLowerCase;
  659. end;
  660. {$define FPC_HAS_SETSTRING_UNICODESTR_PUNICODECHAR}
  661. Procedure fpc_setstring_unicodestr_pwidechar(Out S : UnicodeString; Buf : PUnicodeChar; Len : SizeInt); compilerproc;
  662. begin
  663. if assigned(buf) and (Len>0) then
  664. s:=JLString.Create(TJCharArray(Buf),0,Len)
  665. else
  666. s:='';
  667. end;
  668. {$define FPC_HAS_UTF8ENCODE_UNICODESTRING}
  669. function UTF8Encode(const s : UnicodeString) : RawByteString;
  670. var
  671. i : SizeInt;
  672. hs : UTF8String;
  673. chars: array of widechar;
  674. begin
  675. result:='';
  676. if s='' then
  677. exit;
  678. SetLength(hs,length(s)*3);
  679. chars:=JLString(s).toCharArray;
  680. i:=UnicodeToUtf8(pchar(hs),length(hs)+1,pwidechar(chars),length(s));
  681. if i>0 then
  682. begin
  683. SetLength(hs,i-1);
  684. result:=hs;
  685. end;
  686. end;
  687. {$define FPC_HAS_UTF8DECODE_UNICODESTRING}
  688. function UTF8Decode(const s : RawByteString): UnicodeString;
  689. var
  690. i : SizeInt;
  691. chars: array of widechar;
  692. begin
  693. result:='';
  694. if s='' then
  695. exit;
  696. SetLength(chars,length(s)+1);
  697. i:=Utf8ToUnicode(pwidechar(chars),length(s)+1,pchar(s),length(s));
  698. if i>0 then
  699. result:=JLString.Create(chars,0,i-1);
  700. end;
  701. {$define FPC_HAS_UCS4STRING_TO_UNICODESTR}
  702. { concatenates an utf-32 char to a unicodestring. S *must* be unique when entering. }
  703. procedure ConcatUTF32ToUnicodeStr(const nc: UCS4Char; var S: JLStringBuilder; var index: SizeInt);
  704. begin
  705. { if nc > $ffff, we need two places }
  706. if (index+ord(nc > $ffff)>s.length) then
  707. if (s.length < 10*256) then
  708. s.setLength(s.length+10)
  709. else
  710. s.setlength(s.length+s.length shr 8);
  711. if (nc<$ffff) then
  712. begin
  713. s.setCharAt(index-1,unicodechar(nc));
  714. inc(index);
  715. end
  716. else if (dword(nc)<=$10ffff) then
  717. begin
  718. s.setCharAt(index-1,unicodechar((nc - $10000) shr 10 + $d800));
  719. s.setCharAt(index,unicodechar((nc - $10000) and $3ff + $dc00));
  720. inc(index,2);
  721. end
  722. else
  723. { invalid code point }
  724. begin
  725. s.setCharAt(index-1,'?');
  726. inc(index);
  727. end;
  728. end;
  729. function UCS4StringToUnicodeString(const s : UCS4String) : UnicodeString;
  730. var
  731. i : SizeInt;
  732. resindex : SizeInt;
  733. tmpres: JLStringBuilder;
  734. begin
  735. { skip terminating #0 }
  736. tmpres:=JLStringBuilder.Create(length(s)-1);
  737. resindex:=1;
  738. for i:=0 to high(s)-1 do
  739. ConcatUTF32ToUnicodeStr(s[i],tmpres,resindex);
  740. { adjust result length (may be too big due to growing }
  741. { for surrogate pairs) }
  742. tmpres.setLength(resindex-1);
  743. result:=tmpres.toString;
  744. end;
  745. procedure UCS4Encode(p: PWideChar; len: sizeint; out res: UCS4String); forward;
  746. {$define FPC_HAS_UCS4STRING_TO_UNICODESTR}
  747. function UnicodeStringToUCS4String(const s : UnicodeString) : UCS4String;
  748. begin
  749. UCS4Encode(PWideChar(JLString(s).toCharArray),Length(s),result);
  750. end;
  751. {$define FPC_HAS_WIDESTR_TO_UCS4STRING}
  752. function WideStringToUCS4String(const s : WideString) : UCS4String;
  753. begin
  754. UCS4Encode(PWideChar(JLString(s).toCharArray),Length(s),result);
  755. end;
  756. {$define FPC_HAS_UCS4STRING_TO_WIDESTR}
  757. function UCS4StringToWideString(const s : UCS4String) : WideString;
  758. begin
  759. result:=UCS4StringToUnicodeString(s);
  760. end;
  761. function StringElementSize(const S : UnicodeString): Word;
  762. begin
  763. result:=sizeof(unicodechar);
  764. end;
  765. function StringRefCount(const S : UnicodeString): SizeInt;
  766. begin
  767. if assigned(pointer(s)) then
  768. result:=1
  769. else
  770. result:=0;
  771. end;
  772. function StringCodePage(const S : UnicodeString): TSystemCodePage;
  773. begin
  774. if assigned(pointer(s)) then
  775. result:=CP_UTF16BE
  776. else
  777. result:=DefaultUnicodeCodePage;
  778. end;
  779. {$define FPC_HAS_TOSINGLEBYTEFILESYSTEMENCODEDFILENAME_UNICODESTRING}
  780. Function ToSingleByteFileSystemEncodedFileName(const Str: UnicodeString): RawByteString;
  781. Begin
  782. result:=AnsiString(AnsistringClass.Create(Str,DefaultFileSystemCodePage));
  783. End;
  784. {$define FPC_HAS_TOSINGLEBYTEFILESYSTEMENCODEDFILENAME_UNICODECHARARRAY}
  785. Function ToSingleByteFileSystemEncodedFileName(const arr: array of widechar): RawByteString;
  786. Begin
  787. result:=AnsiString(AnsistringClass.Create(arr,DefaultFileSystemCodePage));
  788. End;
  789. { *************************************************************************** }
  790. { ************************* Collator threadvar ****************************** }
  791. { *************************************************************************** }
  792. function TCollatorThreadVar.InitialValue: JLObject;
  793. begin
  794. { get a copy, since we modify the collator (e.g. setting the strength) }
  795. result:=JTCollator.getInstance.clone
  796. end;
  797. { *************************************************************************** }
  798. { ************************ Helpers for en/decode **************************** }
  799. { *************************************************************************** }
  800. function GetOrInsertNewEnDecoder(hm: JUWeakHashMap; cp: TSystemCodePage; decoder: boolean): JLObject;
  801. var
  802. cs: JNCCharSet;
  803. replacement: array[0..0] of jbyte;
  804. begin
  805. result:=hm.get(JLInteger.valueOf(cp));
  806. if not assigned(result) then
  807. begin
  808. try
  809. cs:=JNCCharSet.forName(win2javacs(cp));
  810. except
  811. { does not exist or not supported, fall back to ASCII like on other
  812. platforms}
  813. cs:=JNCCharset.forName('US-ASCII')
  814. end;
  815. if decoder then
  816. begin
  817. result:=cs.newDecoder;
  818. JNCCharsetDecoder(result).replaceWith('?');
  819. end
  820. else
  821. begin
  822. result:=cs.newEncoder;
  823. replacement[0]:=ord('?');
  824. JNCCharsetEncoder(result).replaceWith(replacement);
  825. end;
  826. { store in weak hashmap for future (possible) reuse }
  827. hm.put(JLInteger.Create(cp),result);
  828. end;
  829. end;
  830. { *************************************************************************** }
  831. { ************************** Decoder threadvar ****************************** }
  832. { *************************************************************************** }
  833. function TCharsetDecoderThreadvar.InitialValue: JLObject;
  834. begin
  835. result:=JUWeakHashMap.Create;
  836. end;
  837. function TCharsetDecoderThreadvar.getForCodePage(cp: TSystemCodePage): JNCCharsetDecoder;
  838. var
  839. hm: JUWeakHashMap;
  840. begin
  841. hm:=JUWeakHashMap(get);
  842. result:=JNCCharsetDecoder(GetOrInsertNewEnDecoder(hm,cp,true));
  843. end;
  844. { *************************************************************************** }
  845. { ************************** Encoder threadvar ****************************** }
  846. { *************************************************************************** }
  847. function TCharsetEncoderThreadvar.InitialValue: JLObject;
  848. begin
  849. result:=JUWeakHashMap.Create;
  850. end;
  851. function TCharsetEncoderThreadvar.getForCodePage(cp: TSystemCodePage): JNCCharsetEncoder;
  852. var
  853. hm: JUWeakHashMap;
  854. begin
  855. hm:=JUWeakHashMap(get);
  856. result:=JNCCharsetEncoder(GetOrInsertNewEnDecoder(hm,cp,false));
  857. end;
  858. { *************************************************************************** }
  859. { ************************ TUnicodeStringManager **************************** }
  860. { *************************************************************************** }
  861. class constructor TUnicodeStringManager.ClassCreate;
  862. begin
  863. collator:=TCollatorThreadVar.Create;
  864. decoder:=TCharsetDecoderThreadVar.Create;
  865. encoder:=TCharsetEncoderThreadVar.Create;
  866. DefaultSystemCodePage:=javacs2win(JNCCharset.defaultCharset.name);
  867. { unknown/unsupported -> default to ASCII (this will be used to parse
  868. stdin etc, so setting this to utf-8 or so won't help) }
  869. if DefaultSystemCodePage=65535 then
  870. DefaultSystemCodePage:=20127;
  871. DefaultFileSystemCodePage:=DefaultSystemCodePage;
  872. DefaultRTLFileSystemCodePage:=DefaultFileSystemCodePage;
  873. DefaultUnicodeCodePage:=CP_UTF16BE;
  874. end;
  875. procedure TUnicodeStringManager.Wide2AnsiMoveProc(source:pwidechar;var dest:RawByteString;cp : TSystemCodePage;len:SizeInt);
  876. begin
  877. DefaultUnicode2AnsiMove(source,dest,cp,len);
  878. end;
  879. procedure TUnicodeStringManager.Ansi2WideMoveProc(source:pchar;cp : TSystemCodePage;var dest:widestring;len:SizeInt);
  880. begin
  881. DefaultAnsi2UnicodeMove(source,cp,dest,len);
  882. end;
  883. function TUnicodeStringManager.UpperWideStringProc(const S: WideString): WideString;
  884. begin
  885. result:=upcase(s);
  886. end;
  887. function TUnicodeStringManager.LowerWideStringProc(const S: WideString): WideString;
  888. begin
  889. result:=lowercase(s);
  890. end;
  891. function TUnicodeStringManager.CompareWideStringProc(const s1, s2 : WideString) : PtrInt;
  892. var
  893. localcollator: JTCollator;
  894. begin
  895. localcollator:=JTCollator(collator.get);
  896. localcollator.setStrength(JTCollator.IDENTICAL);
  897. result:=localcollator.compare(s1,s2);
  898. end;
  899. function TUnicodeStringManager.CompareTextWideStringProc(const s1, s2 : WideString): PtrInt;
  900. var
  901. localcollator: JTCollator;
  902. begin
  903. localcollator:=JTCollator(collator.get);
  904. localcollator.setStrength(JTCollator.TERTIARY);
  905. result:=localcollator.compare(s1,s2);
  906. end;
  907. function TUnicodeStringManager.CharLengthPCharProc(const Str: PChar; Index: PtrInt): PtrInt;
  908. var
  909. localdecoder: JNCCharsetDecoder;
  910. begin
  911. localdecoder:=JNCCharsetDecoder(decoder.get);
  912. localdecoder.reset;
  913. localdecoder.onMalformedInput(JNCCodingErrorAction.fREPLACE);
  914. localdecoder.onUnmappableCharacter(JNCCodingErrorAction.fREPLACE);
  915. result:=localdecoder.decode(JNByteBuffer.wrap(TJByteArray(Str),Index,length(Str)-Index)).length;
  916. end;
  917. function TUnicodeStringManager.CodePointLengthProc(const Str: PChar; Index, MaxLookAhead: PtrInt): Ptrint;
  918. var
  919. localdecoder: JNCCharsetDecoder;
  920. inbuf: JNByteBuffer;
  921. outbuf: JNCharBuffer;
  922. coderres: JNCCoderResult;
  923. limit, maxlimit: longint;
  924. begin
  925. localdecoder:=JNCCharsetDecoder(decoder.get);
  926. localdecoder.reset;
  927. localdecoder.onMalformedInput(JNCCodingErrorAction.fREPORT);
  928. localdecoder.onUnmappableCharacter(JNCCodingErrorAction.fREPORT);
  929. localdecoder.reset;
  930. limit:=0;
  931. maxlimit:=min(length(Str)-Index,MaxLookAhead);
  932. { end of pchar? }
  933. if maxlimit=0 then
  934. begin
  935. result:=0;
  936. exit;
  937. end;
  938. inbuf:=JNByteBuffer.wrap(TJByteArray(Str),Index,Index+maxlimit);
  939. { we will get at most 2 output characters (when decoding from UTF-32 to
  940. UTF-16) }
  941. outbuf:=JNCharBuffer.allocate(2);
  942. { keep trying to decode until we managed to decode one character or
  943. reached the limit }
  944. repeat
  945. inc(limit);
  946. inbuf.limit(limit);
  947. coderres:=localdecoder.decode(inbuf,outbuf,true);
  948. until not coderres.isError or
  949. (limit=MaxLookAhead);
  950. if not coderres.isError then
  951. result:=inbuf.limit
  952. else
  953. result:=-1;
  954. end;
  955. function TUnicodeStringManager.UpperAnsiStringProc(const s : ansistring) : ansistring;
  956. begin
  957. result:=UpperWideStringProc(s);
  958. end;
  959. function TUnicodeStringManager.LowerAnsiStringProc(const s : ansistring) : ansistring;
  960. begin
  961. result:=LowerWideStringProc(s);
  962. end;
  963. function TUnicodeStringManager.CompareStrAnsiStringProc(const S1, S2: ansistring): PtrInt;
  964. begin
  965. result:=CompareUnicodeStringProc(S1,S2);
  966. end;
  967. function TUnicodeStringManager.CompareTextAnsiStringProc(const S1, S2: ansistring): PtrInt;
  968. begin
  969. result:=CompareTextUnicodeStringProc(S1,S2);
  970. end;
  971. function TUnicodeStringManager.StrCompAnsiStringProc(S1, S2: PChar): PtrInt;
  972. var
  973. str1,str2: unicodestring;
  974. begin
  975. str1:=JLString.Create(TJCharArray(S1),0,length(S1));
  976. str2:=JLString.Create(TJCharArray(S2),0,length(S2));
  977. result:=CompareUnicodeStringProc(str1,str2);
  978. end;
  979. function TUnicodeStringManager.StrICompAnsiStringProc(S1, S2: PChar): PtrInt;
  980. var
  981. str1,str2: unicodestring;
  982. begin
  983. str1:=JLString.Create(TJCharArray(S1),0,length(S1));
  984. str2:=JLString.Create(TJCharArray(S2),0,length(S2));
  985. result:=CompareTextUnicodeStringProc(str1,str2);
  986. end;
  987. function TUnicodeStringManager.StrLCompAnsiStringProc(S1, S2: PChar; MaxLen: PtrUInt): PtrInt;
  988. var
  989. str1,str2: unicodestring;
  990. begin
  991. str1:=JLString.Create(TJCharArray(S1),0,min(length(S1),MaxLen));
  992. str2:=JLString.Create(TJCharArray(S2),0,min(length(S2),MaxLen));
  993. result:=CompareUnicodeStringProc(str1,str2);
  994. end;
  995. function TUnicodeStringManager.StrLICompAnsiStringProc(S1, S2: PChar; MaxLen: PtrUInt): PtrInt;
  996. var
  997. str1,str2: unicodestring;
  998. begin
  999. str1:=JLString.Create(TJCharArray(S1),0,min(length(S1),MaxLen));
  1000. str2:=JLString.Create(TJCharArray(S2),0,min(length(S2),MaxLen));
  1001. result:=CompareTextUnicodeStringProc(str1,str2);
  1002. end;
  1003. function TUnicodeStringManager.StrLowerAnsiStringProc(Str: PChar): PChar;
  1004. var
  1005. ustr: unicodestring;
  1006. begin
  1007. ustr:=JLString.Create(TJCharArray(Str),0,length(Str));
  1008. result:=PChar(AnsiStringClass(ansistring(LowerWideStringProc(ustr))).fdata);
  1009. end;
  1010. function TUnicodeStringManager.StrUpperAnsiStringProc(Str: PChar): PChar;
  1011. var
  1012. ustr: unicodestring;
  1013. begin
  1014. ustr:=JLString.Create(TJCharArray(Str),0,length(Str));
  1015. result:=PChar(AnsiStringClass(ansistring(UpperWideStringProc(ustr))).fdata);
  1016. end;
  1017. procedure TUnicodeStringManager.Unicode2AnsiMoveProc(source:punicodechar;var dest:RawByteString;cp : TSystemCodePage;len:SizeInt);
  1018. begin
  1019. DefaultUnicode2AnsiMove(source,dest,cp,len);
  1020. end;
  1021. procedure TUnicodeStringManager.Ansi2UnicodeMoveProc(source:pchar;cp : TSystemCodePage;var dest:unicodestring;len:SizeInt);
  1022. begin
  1023. DefaultAnsi2UnicodeMove(source,cp,dest,len);
  1024. end;
  1025. function TUnicodeStringManager.UpperUnicodeStringProc(const S: UnicodeString): UnicodeString;
  1026. begin
  1027. result:=UpperWideStringProc(S);
  1028. end;
  1029. function TUnicodeStringManager.LowerUnicodeStringProc(const S: UnicodeString): UnicodeString;
  1030. begin
  1031. result:=LowerWideStringProc(S);
  1032. end;
  1033. function TUnicodeStringManager.CompareUnicodeStringProc(const s1, s2 : UnicodeString) : PtrInt;
  1034. begin
  1035. result:=CompareWideStringProc(s1,s2);
  1036. end;
  1037. function TUnicodeStringManager.CompareTextUnicodeStringProc(const s1, s2 : UnicodeString): PtrInt;
  1038. begin
  1039. result:=CompareTextWideStringProc(s1,s2);
  1040. end;
  1041. procedure initunicodestringmanager;
  1042. begin
  1043. widestringmanager:=TUnicodeStringManager.Create;
  1044. end;