wstrings.inc 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1999-2001 by Florian Klaempfl,
  5. member of the Free Pascal development team.
  6. This file implements support routines for WideStrings with FPC
  7. See the file COPYING.FPC, included in this distribution,
  8. for details about the copyright.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  12. **********************************************************************}
  13. {
  14. This file contains the implementation of the WideString type,
  15. and all things that are needed for it.
  16. WideString is defined as a 'silent' pwidechar :
  17. a pwidechar that points to :
  18. @-12 : Longint for maximum size;
  19. @-8 : Longint for size;
  20. @-4 : Longint for reference count;
  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. Maxlen,
  31. len,
  32. ref : Longint;
  33. First : WideChar;
  34. end;
  35. Const
  36. WideRecLen = SizeOf(TWideRec);
  37. WideFirstOff = SizeOf(TWideRec)-sizeof(WideChar);
  38. {
  39. Default WideChar <-> Char conversion is to only convert the
  40. lower 127 chars, all others are translated to spaces.
  41. These routines can be overwritten for the Current Locale
  42. }
  43. procedure Wide2AnsiMove(source:pwidechar;dest:pchar;len:longint);
  44. var
  45. i : longint;
  46. begin
  47. for i:=1to len do
  48. begin
  49. if word(source^)<128 then
  50. dest^:=char(word(source^))
  51. else
  52. dest^:=' ';
  53. inc(dest);
  54. inc(source);
  55. end;
  56. end;
  57. procedure Ansi2WideMove(source:pchar;dest:pwidechar;len:longint);
  58. var
  59. i : longint;
  60. begin
  61. for i:=1to len do
  62. begin
  63. if byte(source^)<128 then
  64. dest^:=widechar(byte(source^))
  65. else
  66. dest^:=' ';
  67. inc(dest);
  68. inc(source);
  69. end;
  70. end;
  71. Type
  72. TWide2AnsiMove=procedure(source:pwidechar;dest:pchar;len:longint);
  73. TAnsi2WideMove=procedure(source:pchar;dest:pwidechar;len:longint);
  74. Const
  75. Wide2AnsiMoveProc:TWide2AnsiMove=@Wide2AnsiMove;
  76. Ansi2WideMoveProc:TAnsi2WideMove=@Ansi2WideMove;
  77. (*
  78. Procedure UniqueWideString(Var S : WideString); [Public,Alias : 'FPC_WIDESTR_UNIQUE'];
  79. {
  80. Make sure reference count of S is 1,
  81. using copy-on-write semantics.
  82. }
  83. begin
  84. end;
  85. *)
  86. {****************************************************************************
  87. Internal functions, not in interface.
  88. ****************************************************************************}
  89. {$ifdef WideStrDebug}
  90. Procedure DumpWideRec(S : Pointer);
  91. begin
  92. If S=Nil then
  93. Writeln ('String is nil')
  94. Else
  95. Begin
  96. With PWideRec(S-WideFirstOff)^ do
  97. begin
  98. Write ('(Maxlen: ',maxlen);
  99. Write (' Len:',len);
  100. Writeln (' Ref: ',ref,')');
  101. end;
  102. end;
  103. end;
  104. {$endif}
  105. Function NewWideString(Len : Longint) : Pointer;
  106. {
  107. Allocate a new WideString on the heap.
  108. initialize it to zero length and reference count 1.
  109. }
  110. Var
  111. P : Pointer;
  112. begin
  113. { Also add +1 for a terminating zero }
  114. GetMem(P,Len+Len+WideRecLen);
  115. If P<>Nil then
  116. begin
  117. PWideRec(P)^.Maxlen:=Len; { Maximal length }
  118. PWideRec(P)^.Len:=0; { Initial length }
  119. PWideRec(P)^.Ref:=1; { Set reference count }
  120. PWideRec(P)^.First:=#0; { Terminating #0 }
  121. inc(p,WideFirstOff); { Points to string now }
  122. end;
  123. NewWideString:=P;
  124. end;
  125. Procedure DisposeWideString(Var S : Pointer);
  126. {
  127. Deallocates a WideString From the heap.
  128. }
  129. begin
  130. If S=Nil then
  131. exit;
  132. Dec (Longint(S),WideFirstOff);
  133. FreeMem (S);
  134. S:=Nil;
  135. end;
  136. Procedure WideStr_Decr_Ref (Var S : Pointer);[Public,Alias:'FPC_WIDESTR_DECR_REF'];
  137. {
  138. Decreases the ReferenceCount of a non constant widestring;
  139. If the reference count is zero, deallocate the string;
  140. }
  141. Type
  142. plongint = ^longint;
  143. Var
  144. l : plongint;
  145. Begin
  146. { Zero string }
  147. If S=Nil then exit;
  148. { check for constant strings ...}
  149. l:=@PWIDEREC(S-WideFirstOff)^.Ref;
  150. If l^<0 then exit;
  151. { declocked does a MT safe dec and returns true, if the counter is 0 }
  152. If declocked(l^) then
  153. { Ref count dropped to zero }
  154. DisposeWideString (S); { Remove...}
  155. { this pointer is not valid anymore, so set it to zero }
  156. S:=nil;
  157. end;
  158. Procedure WideStr_Incr_Ref (Var S : Pointer);[Public,Alias:'FPC_WIDESTR_INCR_REF'];
  159. Begin
  160. If S=Nil then
  161. exit;
  162. { Let's be paranoid : Constant string ??}
  163. If PWideRec(S-WideFirstOff)^.Ref<0 then exit;
  164. inclocked(PWideRec(S-WideFirstOff)^.Ref);
  165. end;
  166. Procedure WideStr_To_ShortStr (Var S1 : ShortString;S2 : Pointer);[Public, alias: 'FPC_WIDESTR_TO_SHORTSTR'];
  167. {
  168. Converts a WideString to a ShortString;
  169. }
  170. Var
  171. Size : Longint;
  172. begin
  173. if S2=nil then
  174. S1:=''
  175. else
  176. begin
  177. Size:=PAnsiRec(S2-FirstOff)^.Len;
  178. If Size>high(S1) then
  179. Size:=high(S1);
  180. Wide2AnsiMoveProc(PWideChar(S2),PChar(@S1[1]),Size);
  181. byte(S1[0]):=Size;
  182. end;
  183. end;
  184. Procedure ShortStr_To_WideStr (Var S1 : Pointer; Const S2 : ShortString);[Public, alias: 'FPC_SHORTSTR_TO_WIDESTR'];
  185. {
  186. Converts a ShortString to a WideString;
  187. }
  188. Var
  189. Size : Longint;
  190. begin
  191. Size:=Length(S2);
  192. Setlength (WideString(S1),Size);
  193. if Size>0 then
  194. Ansi2WideMoveProc(PChar(@S2[1]),PWideChar(S1),Size);
  195. end;
  196. Procedure WideStr_To_AnsiStr (Var S1 : Pointer;S2 : Pointer);[Public, alias: 'FPC_WIDESTR_TO_ANSISTR'];
  197. {
  198. Converts a WideString to an AnsiString
  199. }
  200. Var
  201. Size : Longint;
  202. begin
  203. if s2=nil then
  204. s1:=nil
  205. else
  206. begin
  207. Size:=Length(WideString(S2));
  208. Setlength (AnsiString(S1),Size);
  209. if Size>0 then
  210. begin
  211. Wide2AnsiMoveProc(PWideChar(S2),PChar(S1),Size);
  212. { Terminating Zero }
  213. PChar(S1+Size)^:=#0;
  214. end;
  215. end;
  216. end;
  217. Procedure AnsiStr_To_WideStr (Var S1 : Pointer; Const S2 : Pointer);[Public, alias: 'FPC_ANSISTR_TO_WIDESTR'];
  218. {
  219. Converts an AnsiString to a WideString;
  220. }
  221. Var
  222. Size : Longint;
  223. begin
  224. if s2=nil then
  225. s1:=nil
  226. else
  227. begin
  228. Size:=Length(AnsiString(S2));
  229. Setlength (WideString(S1),Size);
  230. if Size>0 then
  231. begin
  232. Ansi2WideMoveProc(PChar(S2),PWideChar(S1),Size);
  233. { Terminating Zero }
  234. PWideChar(S1+Size*sizeof(WideChar))^:=#0;
  235. end;
  236. end;
  237. end;
  238. { checked against the ansistring routine, 2001-05-27 (FK) }
  239. Procedure WideStr_Assign (Var S1 : Pointer;S2 : Pointer);[Public,Alias:'FPC_WIDESTR_ASSIGN'];
  240. {
  241. Assigns S2 to S1 (S1:=S2), taking in account reference counts.
  242. }
  243. begin
  244. If S2<>nil then
  245. If PWideRec(S2-WideFirstOff)^.Ref>0 then
  246. Inc(PWideRec(S2-WideFirstOff)^.ref);
  247. { Decrease the reference count on the old S1 }
  248. widestr_decr_ref (S1);
  249. { And finally, have S1 pointing to S2 (or its copy) }
  250. S1:=S2;
  251. end;
  252. { checked against the ansistring routine, 2001-05-27 (FK) }
  253. Procedure WideStr_Concat (S1,S2 : Pointer;var S3 : Pointer);[Public, alias: 'FPC_WIDESTR_CONCAT'];
  254. {
  255. Concatenates 2 WideStrings : S1+S2.
  256. Result Goes to S3;
  257. }
  258. Var
  259. Size,Location : Longint;
  260. begin
  261. { create new result }
  262. if S3<>nil then
  263. WideStr_Decr_Ref(S3);
  264. { only assign if s1 or s2 is empty }
  265. if (S1=Nil) then
  266. WideStr_Assign(S3,S2)
  267. else
  268. if (S2=Nil) then
  269. WideStr_Assign(S3,S1)
  270. else
  271. begin
  272. Size:=PWideRec(S2-WideFirstOff)^.Len;
  273. Location:=Length(WideString(S1));
  274. SetLength (WideString(S3),Size+Location);
  275. Move (S1^,S3^,Location*sizeof(WideChar));
  276. Move (S2^,(S3+location*sizeof(WideChar))^,(Size+1)*sizeof(WideChar));
  277. end;
  278. end;
  279. Procedure Char_To_WideStr(var S1 : Pointer; c : Char);[Public, alias: 'FPC_CHAR_TO_WIDESTR'];
  280. {
  281. Converts a Char to a WideString;
  282. }
  283. begin
  284. Setlength (WideString(S1),1);
  285. PWideChar(S1)^:=c;
  286. { Terminating Zero }
  287. PWideChar(S1+sizeof(WideChar))^:=#0;
  288. end;
  289. Procedure PChar_To_WideStr(var a : widestring;p : pchar);[Public,Alias : 'FPC_PCHAR_TO_WIDESTR'];
  290. Var
  291. L : Longint;
  292. begin
  293. if pointer(a)<>nil then
  294. begin
  295. WideStr_Decr_Ref(Pointer(a));
  296. pointer(a):=nil;
  297. end;
  298. if (not assigned(p)) or (p[0]=#0) Then
  299. Pointer(a):=nil
  300. else
  301. begin
  302. l:=IndexChar(p^,-1,#0);
  303. Pointer(a):=NewWidestring(L);
  304. SetLength(A,L);
  305. Ansi2WideMoveProc(P,PWideChar(A),L);
  306. end;
  307. end;
  308. Procedure CharArray_To_WideStr(var a : widestring;p : pchar;l:longint);[Public,Alias : 'FPC_CHARARRAY_TO_WIDESTR'];
  309. var
  310. i : longint;
  311. begin
  312. if p[0]=#0 Then
  313. Pointer(a):=nil
  314. else
  315. begin
  316. i:=IndexChar(p^,L,#0);
  317. Pointer(a):=NewWidestring(i);
  318. SetLength(a,i);
  319. Ansi2WideMoveProc(P,PWideChar(A),i);
  320. end;
  321. end;
  322. Function WideStr_Compare(S1,S2 : Pointer): Longint;[Public,Alias : 'FPC_WIDESTR_COMPARE'];
  323. {
  324. Compares 2 WideStrings;
  325. The result is
  326. <0 if S1<S2
  327. 0 if S1=S2
  328. >0 if S1>S2
  329. }
  330. Var
  331. MaxI,Temp : Longint;
  332. begin
  333. if S1=S2 then
  334. begin
  335. WideStr_Compare:=0;
  336. exit;
  337. end;
  338. Maxi:=Length(WideString(S1));
  339. temp:=Length(WideString(S2));
  340. If MaxI>Temp then
  341. MaxI:=Temp;
  342. Temp:=CompareWord(S1^,S2^,MaxI);
  343. if temp=0 then
  344. temp:=Length(WideString(S1))-Length(WideString(S2));
  345. WideStr_Compare:=Temp;
  346. end;
  347. Procedure WideStr_CheckZero(p : pointer);[Public,Alias : 'FPC_WIDESTR_CHECKZERO'];
  348. begin
  349. if p=nil then
  350. HandleErrorFrame(201,get_frame);
  351. end;
  352. Procedure WideStr_CheckRange(len,index : longint);[Public,Alias : 'FPC_WIDESTR_RANGECHECK'];
  353. begin
  354. if (index>len) or (Index<1) then
  355. HandleErrorFrame(201,get_frame);
  356. end;
  357. {$ifndef INTERNSETLENGTH}
  358. Procedure SetLength (Var S : WideString; l : Longint);
  359. {$else INTERNSETLENGTH}
  360. Procedure WideStr_SetLength (Var S : WideString; l : Longint);[Public,Alias : 'FPC_WIDESTR_SETLENGTH'];
  361. {$endif INTERNSETLENGTH}
  362. {
  363. Sets The length of string S to L.
  364. Makes sure S is unique, and contains enough room.
  365. }
  366. Var
  367. Temp : Pointer;
  368. begin
  369. if (l>0) then
  370. begin
  371. if Pointer(S)=nil then
  372. begin
  373. { Need a complete new string...}
  374. Pointer(s):=NewWideString(l);
  375. end
  376. else
  377. If (PWideRec(Pointer(S)-WideFirstOff)^.Maxlen < L) or
  378. (PWideRec(Pointer(S)-WideFirstOff)^.Ref <> 1) then
  379. begin
  380. { Reallocation is needed... }
  381. Temp:=Pointer(NewWideString(L));
  382. if Length(S)>0 then
  383. Move(Pointer(S)^,Temp^,L*sizeof(WideChar));
  384. WideStr_decr_ref(Pointer(S));
  385. Pointer(S):=Temp;
  386. end;
  387. { Force nil termination in case it gets shorter }
  388. PWideChar(Pointer(S)+l*sizeof(WideChar))^:=#0;
  389. PWideRec(Pointer(S)-WideFirstOff)^.Len:=l;
  390. end
  391. else
  392. begin
  393. { Length=0 }
  394. if Pointer(S)<>nil then
  395. WideStr_decr_ref (Pointer(S));
  396. Pointer(S):=Nil;
  397. end;
  398. end;
  399. {*****************************************************************************
  400. Public functions, In interface.
  401. *****************************************************************************}
  402. {$ifndef INTERNLENGTH}
  403. Function Length (Const S : WideString) : Longint;
  404. {
  405. Returns the length of an WideString.
  406. Takes in acount that zero strings are NIL;
  407. }
  408. begin
  409. If Pointer(S)=Nil then
  410. Length:=0
  411. else
  412. Length:=PWideRec(Pointer(S)-WideFirstOff)^.Len;
  413. end;
  414. {$endif INTERNLENGTH}
  415. Procedure UniqueString(Var S : WideString); [Public,Alias : 'FPC_WIDESTR_UNIQUE'];
  416. {
  417. Make sure reference count of S is 1,
  418. using copy-on-write semantics.
  419. }
  420. Var
  421. SNew : Pointer;
  422. L : Longint;
  423. begin
  424. If Pointer(S)=Nil then
  425. exit;
  426. if PWideRec(Pointer(S)-WideFirstOff)^.Ref<>1 then
  427. begin
  428. L:=PWideRec(Pointer(S)-WideFirstOff)^.len;
  429. SNew:=NewWideString (L);
  430. Move (PWideChar(S)^,SNew^,(L+1)*sizeof(WideChar));
  431. PWideRec(SNew-WideFirstOff)^.len:=L;
  432. widestr_decr_ref (Pointer(S)); { Thread safe }
  433. Pointer(S):=SNew;
  434. end;
  435. end;
  436. Function Copy (Const S : WideString; Index,Size : Longint) : WideString;
  437. var
  438. ResultAddress : Pointer;
  439. begin
  440. ResultAddress:=Nil;
  441. dec(index);
  442. if Index < 0 then
  443. Index := 0;
  444. { Check Size. Accounts for Zero-length S, the double check is needed because
  445. Size can be maxint and will get <0 when adding index }
  446. if (Size>Length(S)) or
  447. (Index+Size>Length(S)) then
  448. Size:=Length(S)-Index;
  449. If Size>0 then
  450. begin
  451. If Index<0 Then
  452. Index:=0;
  453. ResultAddress:=Pointer(NewWideString (Size));
  454. if ResultAddress<>Nil then
  455. begin
  456. Move (PWideChar(S)[Index],ResultAddress^,Size*sizeof(WideChar));
  457. PWideRec(ResultAddress-WideFirstOff)^.Len:=Size;
  458. PWideChar(ResultAddress+Size*sizeof(WideChar))^:=#0;
  459. end;
  460. end;
  461. Pointer(Copy):=ResultAddress;
  462. end;
  463. Function Pos (Const Substr : WideString; Const Source : WideString) : Longint;
  464. var
  465. i,MaxLen : StrLenInt;
  466. pc : pwidechar;
  467. begin
  468. Pos:=0;
  469. if Length(SubStr)>0 then
  470. begin
  471. MaxLen:=Length(source)-Length(SubStr);
  472. i:=0;
  473. pc:=@source[1];
  474. while (i<=MaxLen) do
  475. begin
  476. inc(i);
  477. if (SubStr[1]=pc^) and
  478. (CompareWord(Substr[1],pc^,Length(SubStr))=0) then
  479. begin
  480. Pos:=i;
  481. exit;
  482. end;
  483. inc(pc);
  484. end;
  485. end;
  486. end;
  487. { Faster version for a widechar alone }
  488. Function Pos (c : WideChar; Const s : WideString) : Longint;
  489. var
  490. i: longint;
  491. pc : pwidechar;
  492. begin
  493. pc:=@s[1];
  494. for i:=1 to length(s) do
  495. begin
  496. if pc^=c then
  497. begin
  498. pos:=i;
  499. exit;
  500. end;
  501. inc(pc);
  502. end;
  503. pos:=0;
  504. end;
  505. { Faster version for a char alone. Must be implemented because }
  506. { pos(c: char; const s: shortstring) also exists, so otherwise }
  507. { using pos(char,pchar) will always call the shortstring version }
  508. { (exact match for first argument), also with $h+ (JM) }
  509. Function Pos (c : Char; Const s : WideString) : Longint;
  510. var
  511. i: longint;
  512. wc : widechar;
  513. pc : pwidechar;
  514. begin
  515. wc:=c;
  516. pc:=@s[1];
  517. for i:=1 to length(s) do
  518. begin
  519. if pc^=wc then
  520. begin
  521. pos:=i;
  522. exit;
  523. end;
  524. inc(pc);
  525. end;
  526. pos:=0;
  527. end;
  528. Procedure Delete (Var S : WideString; Index,Size: Longint);
  529. Var
  530. LS : Longint;
  531. begin
  532. If Length(S)=0 then
  533. exit;
  534. if index<=0 then
  535. begin
  536. inc(Size,index-1);
  537. index:=1;
  538. end;
  539. LS:=PWideRec(Pointer(S)-WideFirstOff)^.Len;
  540. if (Index<=LS) and (Size>0) then
  541. begin
  542. UniqueString (S);
  543. if Size+Index>LS then
  544. Size:=LS-Index+1;
  545. if Index+Size<=LS then
  546. begin
  547. Dec(Index);
  548. Move(PWideChar(S)[Index+Size],PWideChar(S)[Index],(LS-Index+1)*sizeof(WideChar));
  549. end;
  550. Setlength(s,LS-Size);
  551. end;
  552. end;
  553. Procedure Insert (Const Source : WideString; Var S : WideString; Index : Longint);
  554. var
  555. Temp : WideString;
  556. LS : Longint;
  557. begin
  558. If Length(Source)=0 then
  559. exit;
  560. if index <= 0 then
  561. index := 1;
  562. Ls:=Length(S);
  563. if index > LS then
  564. index := LS+1;
  565. Dec(Index);
  566. Pointer(Temp) := NewWideString(Length(Source)+LS);
  567. SetLength(Temp,Length(Source)+LS);
  568. If Index>0 then
  569. move (PWideChar(S)^,PWideChar(Temp)^,Index*sizeof(WideChar));
  570. Move (PWideChar(Source)^,PWideChar(Temp)[Index],Length(Source)*sizeof(WideChar));
  571. If (LS-Index)>0 then
  572. Move(PWideChar(S)[Index],PWideChar(temp)[Length(Source)+index],(LS-Index)*sizeof(WideChar));
  573. S:=Temp;
  574. end;
  575. {!!!:Procedure SetString (Var S : WideString; Buf : PWideChar; Len : Longint);
  576. begin
  577. SetLength(S,Len);
  578. Move (Buf[0],S[1],Len*2);
  579. end;}
  580. Function ValWideFloat(Const S : WideString; Var Code : ValSInt): ValReal; [public, alias:'FPC_VAL_REAL_ANSISTR'];
  581. Var
  582. SS : String;
  583. begin
  584. WideStr_To_ShortStr(SS,Pointer(S));
  585. ValWideFloat := ValFloat(SS,Code);
  586. end;
  587. Function ValWideUnsignedInt (Const S : WideString; Var Code : ValSInt): ValUInt; [public, alias:'FPC_VAL_UINT_ANSISTR'];
  588. Var
  589. SS : ShortString;
  590. begin
  591. WideStr_To_ShortStr(SS,Pointer(S));
  592. ValWideUnsignedInt := ValUnsignedInt(SS,Code);
  593. end;
  594. Function ValWideSignedInt (DestSize: longint; Const S : WideString; Var Code : ValSInt): ValSInt; [public, alias:'FPC_VAL_SINT_ANSISTR'];
  595. Var
  596. SS : ShortString;
  597. begin
  598. ValWideSignedInt:=0;
  599. if length(S)>255 then
  600. code:=256
  601. else
  602. begin
  603. WideStr_To_ShortStr (SS,Pointer(S));
  604. ValWideSignedInt := ValSignedInt(DestSize,SS,Code);
  605. end;
  606. end;
  607. Function ValWideUnsignedint64 (Const S : WideString; Var Code : ValSInt): qword; [public, alias:'FPC_VAL_QWORD_ANSISTR'];
  608. Var
  609. SS : ShortString;
  610. begin
  611. ValWideUnsignedInt64:=0;
  612. if length(S)>255 then
  613. code:=256
  614. else
  615. begin
  616. WideStr_To_ShortStr(SS,Pointer(S));
  617. ValWideUnsignedInt64 := ValQWord(SS,Code);
  618. end;
  619. end;
  620. Function ValWideSignedInt64 (Const S : WideString; Var Code : ValSInt): Int64; [public, alias:'FPC_VAL_INT64_ANSISTR'];
  621. Var
  622. SS : ShortString;
  623. begin
  624. ValWideSignedInt64:=0;
  625. if length(S)>255 then
  626. code:=256
  627. else
  628. begin
  629. WideStr_To_ShortStr (SS,Pointer(S));
  630. ValWideSignedInt64 := valInt64(SS,Code);
  631. end;
  632. end;
  633. procedure WideStr_Float(d : ValReal;len,fr,rt : longint;var s : WideString);[public,alias:'FPC_WIDESTR_FLOAT'];
  634. var
  635. ss : shortstring;
  636. begin
  637. str_real(len,fr,d,treal_type(rt),ss);
  638. s:=ss;
  639. end;
  640. Procedure WideStr_Cardinal(C : Cardinal;Len : Longint; Var S : WideString);[Public,Alias : 'FPC_WIDESTR_CARDINAL'];
  641. Var
  642. SS : ShortString;
  643. begin
  644. int_str_cardinal(C,Len,SS);
  645. S:=SS;
  646. end;
  647. Procedure WideStr_Longint(L : Longint; Len : Longint; Var S : WideString);[Public,Alias : 'FPC_WIDESTR_LONGINT'];
  648. Var
  649. SS : ShortString;
  650. begin
  651. int_Str_Longint (L,Len,SS);
  652. S:=SS;
  653. end;
  654. {
  655. $Log$
  656. Revision 1.9 2001-07-09 21:15:41 peter
  657. * Length made internal
  658. * Add array support for Length
  659. Revision 1.8 2001/07/08 21:00:18 peter
  660. * various widestring updates, it works now mostly without charset
  661. mapping supported
  662. Revision 1.7 2001/05/27 14:28:03 florian
  663. + some procedures added
  664. Revision 1.6 2000/11/06 23:17:15 peter
  665. * removed some warnings
  666. Revision 1.5 2000/11/06 20:34:24 peter
  667. * changed ver1_0 defines to temporary defs
  668. Revision 1.4 2000/10/21 18:20:17 florian
  669. * a lot of small changes:
  670. - setlength is internal
  671. - win32 graph unit extended
  672. ....
  673. Revision 1.3 2000/08/08 22:12:36 sg
  674. * Implemented WideString helper functions (but they are not tested yet
  675. due to the lack of full compiler support for WideString/WideChar!)
  676. Revision 1.2 2000/07/13 11:33:46 michael
  677. + removed logs
  678. }