astrings.inc 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 1999-2000 by Michael Van Canneyt,
  4. member of the Free Pascal development team.
  5. This file implements AnsiStrings for 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. { This will release some functions for special shortstring support }
  13. { define EXTRAANSISHORT}
  14. {$ifndef FPC_ANSISTRING_TYPE_DEFINED}
  15. {$define FPC_ANSISTRING_TYPE_DEFINED}
  16. {
  17. This file contains the implementation of the AnsiString type,
  18. and all things that are needed for it.
  19. AnsiString is defined as a 'silent' pchar :
  20. a pchar that points to (S= SizeOf(SizeInt)):
  21. @-3*S : Code page indicator.
  22. @-3*S+2 : Character size (2 bytes)
  23. @-2*S : SizeInt for reference count;
  24. @-S : SizeInt for size;
  25. @ : String + Terminating #0;
  26. Pchar(Ansistring) is a valid typecast.
  27. So AS[i] is converted to the address @AS+i-1.
  28. Constants should be assigned a reference count of -1
  29. Meaning that they can't be disposed of.
  30. }
  31. Type
  32. PAnsiRec = ^TAnsiRec;
  33. TAnsiRec = Record
  34. CodePage : TSystemCodePage;
  35. ElementSize : Word;
  36. {$ifdef CPU64}
  37. { align fields }
  38. Dummy : DWord;
  39. {$endif CPU64}
  40. Ref : SizeInt;
  41. Len : SizeInt;
  42. end;
  43. Const
  44. AnsiFirstOff = SizeOf(TAnsiRec);
  45. {$endif FPC_ANSISTRING_TYPE_DEFINED}
  46. {****************************************************************************
  47. Internal functions, not in interface.
  48. ****************************************************************************}
  49. {$ifndef FPC_HAS_TRANSLATEPLACEHOLDERCP}
  50. {$define FPC_HAS_TRANSLATEPLACEHOLDERCP}
  51. function TranslatePlaceholderCP(cp: TSystemCodePage): TSystemCodePage; {$ifdef SYSTEMINLINE}inline;{$endif}
  52. begin
  53. TranslatePlaceholderCP:=cp;
  54. case cp of
  55. CP_OEMCP,
  56. CP_ACP:
  57. TranslatePlaceholderCP:=DefaultSystemCodePage;
  58. end;
  59. end;
  60. {$endif FPC_HAS_TRANSLATEPLACEHOLDERCP}
  61. {$ifndef FPC_HAS_PCHAR_ANSISTR_INTERN_CHARMOVE}
  62. {$define FPC_HAS_PCHAR_ANSISTR_INTERN_CHARMOVE}
  63. procedure fpc_pchar_ansistr_intern_charmove(const src: pchar; const srcindex: sizeint; var dst: rawbytestring; const dstindex, len: sizeint); {$ifdef FPC_HAS_CPSTRING}rtlproc;{$endif} {$ifdef SYSTEMINLINE}inline;{$endif}
  64. begin
  65. move(src[srcindex],pbyte(pointer(dst))[dstindex],len);
  66. end;
  67. {$endif FPC_HAS_PCHAR_ANSISTR_INTERN_CHARMOVE}
  68. {$ifndef FPC_HAS_PCHAR_PCHAR_INTERN_CHARMOVE}
  69. {$define FPC_HAS_PCHAR_PCHAR_INTERN_CHARMOVE}
  70. procedure fpc_pchar_pchar_intern_charmove(const src: pchar; const srcindex: sizeint; const dst: pchar; const dstindex, len: sizeint); {$ifdef FPC_HAS_CPSTRING}rtlproc;{$endif} {$ifdef SYSTEMINLINE}inline;{$endif}
  71. begin
  72. move(src[srcindex],dst[dstindex],len);
  73. end;
  74. {$endif FPC_HAS_PCHAR_PCHAR_INTERN_CHARMOVE}
  75. {$ifndef FPC_HAS_SHORTSTR_ANSISTR_INTERN_CHARMOVE}
  76. {$define FPC_HAS_SHORTSTR_ANSISTR_INTERN_CHARMOVE}
  77. procedure fpc_shortstr_ansistr_intern_charmove(const src: shortstring; const srcindex: sizeint; var dst: rawbytestring; const dstindex, len: sizeint); {$ifdef FPC_HAS_CPSTRING}rtlproc;{$endif} {$ifdef SYSTEMINLINE}inline;{$endif}
  78. begin
  79. move(src[srcindex],pbyte(pointer(dst))[dstindex],len);
  80. end;
  81. {$endif FPC_HAS_SHORTSTR_ANSISTR_INTERN_CHARMOVE}
  82. {$ifndef FPC_HAS_NEWANSISTR}
  83. {$define FPC_HAS_NEWANSISTR}
  84. Function NewAnsiString(Len : SizeInt) : Pointer;
  85. {
  86. Allocate a new AnsiString on the heap.
  87. initialize it to zero length and reference count 1.
  88. }
  89. Var
  90. P : Pointer;
  91. begin
  92. { request a multiple of 16 because the heap manager alloctes anyways chunks of 16 bytes }
  93. GetMem(P,Len+(AnsiFirstOff+sizeof(char)));
  94. If P<>Nil then
  95. begin
  96. PAnsiRec(P)^.Ref:=1; { Set reference count }
  97. PAnsiRec(P)^.Len:=0; { Initial length }
  98. PAnsiRec(P)^.CodePage:=DefaultSystemCodePage;
  99. PAnsiRec(P)^.ElementSize:=SizeOf(AnsiChar);
  100. inc(p,AnsiFirstOff); { Points to string now }
  101. PAnsiChar(P)^:=#0; { Terminating #0 }
  102. end;
  103. NewAnsiString:=P;
  104. end;
  105. {$endif FPC_HAS_NEWANSISTR}
  106. {$ifndef FPC_SYSTEM_HAS_ANSISTR_DECR_REF}
  107. {$define FPC_SYSTEM_HAS_ANSISTR_DECR_REF}
  108. Procedure fpc_ansistr_decr_ref (Var S : Pointer); [Public,Alias:'FPC_ANSISTR_DECR_REF']; compilerproc;
  109. {
  110. Decreases the ReferenceCount of a non constant ansistring;
  111. If the reference count is zero, deallocate the string;
  112. }
  113. Var
  114. p: PAnsiRec;
  115. Begin
  116. { Zero string }
  117. If S=Nil then
  118. exit;
  119. { check for constant strings ...}
  120. p:=PAnsiRec(S-AnsiFirstOff);
  121. s:=nil;
  122. If p^.ref<0 then exit;
  123. { declocked does a MT safe dec and returns true, if the counter is 0 }
  124. If declocked(p^.ref) then
  125. FreeMem(p);
  126. end;
  127. {$endif FPC_SYSTEM_HAS_ANSISTR_DECR_REF}
  128. { also define alias for internal use in the system unit }
  129. Procedure fpc_ansistr_decr_ref (Var S : Pointer); [external name 'FPC_ANSISTR_DECR_REF'];
  130. {$ifndef FPC_SYSTEM_HAS_ANSISTR_INCR_REF}
  131. {$define FPC_SYSTEM_HAS_ANSISTR_INCR_REF}
  132. Procedure fpc_AnsiStr_Incr_Ref (S : Pointer); [Public,Alias:'FPC_ANSISTR_INCR_REF']; compilerproc; inline;
  133. Begin
  134. If S=Nil then
  135. exit;
  136. { Let's be paranoid : Constant string ??}
  137. If PAnsiRec(S-AnsiFirstOff)^.Ref<0 then exit;
  138. inclocked(PAnsiRec(S-AnsiFirstOff)^.Ref);
  139. end;
  140. {$endif FPC_SYSTEM_HAS_ANSISTR_DECR_REF}
  141. { also define alias which can be used inside the system unit }
  142. Procedure fpc_AnsiStr_Incr_Ref (S : Pointer); [external name 'FPC_ANSISTR_INCR_REF'];
  143. {$ifndef FPC_HAS_ANSISTR_ASSIGN}
  144. {$define FPC_HAS_ANSISTR_ASSIGN}
  145. Procedure fpc_AnsiStr_Assign (Var DestS : Pointer;S2 : Pointer);[Public,Alias:'FPC_ANSISTR_ASSIGN']; compilerproc;
  146. {
  147. Assigns S2 to S1 (S1:=S2), taking in account reference counts.
  148. }
  149. begin
  150. if DestS=S2 then
  151. exit;
  152. If S2<>nil then
  153. If PAnsiRec(S2-AnsiFirstOff)^.Ref>0 then
  154. inclocked(PAnsiRec(S2-AnsiFirstOff)^.Ref);
  155. { Decrease the reference count on the old S1 }
  156. fpc_ansistr_decr_ref (DestS);
  157. { And finally, have DestS pointing to S2 (or its copy) }
  158. DestS:=S2;
  159. end;
  160. {$endif FPC_HAS_ANSISTR_ASSIGN}
  161. { alias for internal use }
  162. Procedure fpc_AnsiStr_Assign (Var S1 : Pointer;S2 : Pointer);[external name 'FPC_ANSISTR_ASSIGN'];
  163. {$ifndef FPC_HAS_ANSISTR_CONCAT_COMPLEX}
  164. {$define FPC_HAS_ANSISTR_CONCAT_COMPLEX}
  165. { keeps implicit try..finally block out from primary control flow }
  166. procedure ansistr_concat_complex(var DestS: RawByteString; const S1,S2: RawByteString; cp: TSystemCodePage);
  167. var
  168. U: UnicodeString;
  169. begin
  170. U:=UnicodeString(S1)+UnicodeString(S2);
  171. widestringmanager.Unicode2AnsiMoveProc(PUnicodeChar(Pointer(U)),DestS,cp,Length(U));
  172. end;
  173. {$endif FPC_HAS_ANSISTR_CONCAT_COMPLEX}
  174. {$ifndef FPC_HAS_ANSISTR_CONCAT}
  175. {$define FPC_HAS_ANSISTR_CONCAT}
  176. procedure fpc_AnsiStr_Concat (var DestS:RawByteString;const S1,S2 : RawByteString{$ifdef FPC_HAS_CPSTRING};cp : TSystemCodePage{$endif FPC_HAS_CPSTRING}); compilerproc;
  177. Var
  178. S1Len, S2Len: SizeInt;
  179. same : boolean;
  180. S1CP, S2CP, DestCP: TSystemCodePage;
  181. begin
  182. {$ifdef FPC_HAS_CPSTRING}
  183. DestCP:=cp;
  184. if DestCp=CP_NONE then
  185. DestCP:=DefaultSystemCodePage;
  186. {$else FPC_HAS_CPSTRING}
  187. DestCP:=StringCodePage(DestS);
  188. {$endif FPC_HAS_CPSTRING}
  189. DestCP:=TranslatePlaceholderCP(DestCP);
  190. { if codepages are different then concat using unicodestring,
  191. but avoid conversions if either addend is empty (StringCodePage will return
  192. DefaultSystemCodePage in that case, which may differ from other addend/dest) }
  193. if S1='' then
  194. S1CP:=DestCP
  195. else
  196. S1CP:=StringCodePage(S1);
  197. S1CP:=TranslatePlaceholderCP(S1CP);
  198. if S2='' then
  199. S2CP:=DestCP
  200. else
  201. S2CP:=StringCodePage(S2);
  202. S2CP:=TranslatePlaceholderCP(S2CP);
  203. {$ifdef FPC_HAS_CPSTRING}
  204. { if the result is rawbytestring and both strings have the same code page,
  205. keep that code page or keep the code page if the other string is empty }
  206. if cp=CP_NONE then
  207. begin
  208. if (S1CP=S2CP) or (S2='') then
  209. DestCP:=S1CP
  210. else if S1='' then
  211. DestCP:=S2CP;
  212. end;
  213. {$endif FPC_HAS_CPSTRING}
  214. if ((S1CP<>DestCP) and (s1<>'')) or ((S2CP<>DestCP) and (s2<>'')) then
  215. begin
  216. ansistr_concat_complex(DestS,S1,S2,DestCP);
  217. exit;
  218. end;
  219. { only assign if s1 or s2 is empty }
  220. if (S1='') then
  221. begin
  222. DestS:=s2;
  223. exit;
  224. end;
  225. if (S2='') then
  226. begin
  227. DestS:=s1;
  228. exit;
  229. end;
  230. S1Len:=Length(S1);
  231. S2Len:=length(S2);
  232. { Use Pointer() typecasts to prevent extra conversion code }
  233. if Pointer(DestS)=Pointer(S1) then
  234. begin
  235. same:=Pointer(S1)=Pointer(S2);
  236. SetLength(DestS,S1Len+S2Len);
  237. if same then
  238. fpc_pchar_ansistr_intern_charmove(PAnsiChar(DestS),0,DestS,S1Len,S2Len)
  239. else
  240. fpc_pchar_ansistr_intern_charmove(PAnsiChar(S2),0,DestS,S1Len,S2Len+1)
  241. end
  242. else if Pointer(DestS)=Pointer(S2) then
  243. begin
  244. SetLength(DestS,S1Len+S2Len);
  245. fpc_pchar_ansistr_intern_charmove(PAnsiChar(DestS),0,DestS,S1Len,S2Len+1);
  246. fpc_pchar_ansistr_intern_charmove(PAnsiChar(S1),0,DestS,0,S1Len);
  247. end
  248. else
  249. begin
  250. SetLength(DestS,S1Len+S2Len);
  251. fpc_pchar_ansistr_intern_charmove(PAnsiChar(S1),0,DestS,0,S1Len);
  252. fpc_pchar_ansistr_intern_charmove(PAnsiChar(S2),0,DestS,S1Len,S2Len+1);
  253. end;
  254. SetCodePage(DestS,DestCP,false);
  255. end;
  256. {$endif FPC_HAS_ANSISTR_CONCAT}
  257. {$ifndef FPC_HAS_ANSISTR_CONCAT_MULTI}
  258. {$define FPC_HAS_ANSISTR_CONCAT_MULTI}
  259. procedure fpc_AnsiStr_Concat_multi (var DestS:RawByteString;const sarr:array of RawByteString{$ifdef FPC_HAS_CPSTRING};cp : TSystemCodePage{$endif FPC_HAS_CPSTRING}); compilerproc;
  260. Var
  261. lowstart,
  262. nonemptystart,
  263. i : ObjpasInt;
  264. p,pc : pointer;
  265. Size,NewLen,
  266. OldDestLen : SizeInt;
  267. destcopy : pointer;
  268. U : UnicodeString;
  269. DestCP,
  270. tmpCP : TSystemCodePage;
  271. sameCP : Boolean;
  272. begin
  273. if high(sarr)=0 then
  274. begin
  275. DestS:='';
  276. exit;
  277. end;
  278. {$ifdef FPC_HAS_CPSTRING}
  279. DestCP:=cp;
  280. if DestCp=CP_NONE then
  281. DestCP:=DefaultSystemCodePage;
  282. {$else FPC_HAS_CPSTRING}
  283. DestCP:=StringCodePage(DestS);
  284. {$endif FPC_HAS_CPSTRING}
  285. lowstart:=low(sarr);
  286. { skip empty strings }
  287. while (lowstart<=high(sarr)) and
  288. (sarr[lowstart]='') do
  289. inc(lowstart);
  290. if lowstart>high(sarr) then
  291. begin
  292. DestS:=''; { All source strings empty }
  293. exit;
  294. end;
  295. DestCP:=TranslatePlaceholderCP(DestCP);
  296. sameCP:=true;
  297. tmpCP:=TranslatePlaceholderCP(StringCodePage(sarr[lowstart]));
  298. for i:=lowstart+1 to high(sarr) do
  299. begin
  300. { ignore the code page of empty strings, it will always be
  301. DefaultSystemCodePage but it doesn't matter for the outcome }
  302. if (sarr[i]<>'') and
  303. (tmpCP<>TranslatePlaceholderCP(StringCodePage(sarr[i]))) then
  304. begin
  305. sameCP:=false;
  306. break;
  307. end;
  308. end;
  309. if not sameCP then
  310. begin
  311. U:='';
  312. for i:=lowstart to high(sarr) do
  313. if sarr[i]<>'' then
  314. U:=U+UnicodeString(sarr[i]);
  315. DestS:='';
  316. widestringmanager.Unicode2AnsiMoveProc(PUnicodeChar(Pointer(U)),DestS,DestCP,Length(U));
  317. exit;
  318. end;
  319. {$ifdef FPC_HAS_CPSTRING}
  320. { if the result is rawbytestring and all strings have the same code page,
  321. keep that code page }
  322. if cp=CP_NONE then
  323. DestCP:=tmpCP;
  324. {$endif FPC_HAS_CPSTRING}
  325. destcopy:=nil;
  326. nonemptystart:=lowstart;
  327. { Check for another reuse, then we can't use
  328. the append optimization }
  329. if DestS<>'' then
  330. begin
  331. if Pointer(DestS)=Pointer(sarr[lowstart]) then
  332. inc(lowstart);
  333. for i:=lowstart to high(sarr) do
  334. begin
  335. if Pointer(DestS)=Pointer(sarr[i]) then
  336. begin
  337. { if DestS is used somewhere in the middle of the expression,
  338. we need to make sure the original string still exists after
  339. we empty/modify DestS }
  340. destcopy:=pointer(dests);
  341. fpc_AnsiStr_Incr_Ref(destcopy);
  342. lowstart:=nonemptystart;
  343. break;
  344. end;
  345. end;
  346. end;
  347. { Start with empty DestS if we start with concatting
  348. the first (non-empty) array element }
  349. if lowstart=nonemptystart then
  350. DestS:='';
  351. OldDestLen:=length(DestS);
  352. { Calculate size of the result so we can do
  353. a single call to SetLength() }
  354. NewLen:=0;
  355. for i:=nonemptystart to high(sarr) do
  356. inc(NewLen,length(sarr[i]));
  357. SetLength(DestS,NewLen);
  358. { Concat all strings, except the string we already
  359. copied in DestS }
  360. pc:=Pointer(DestS)+OldDestLen;
  361. for i:=lowstart to high(sarr) do
  362. begin
  363. p:=pointer(sarr[i]);
  364. if assigned(p) then
  365. begin
  366. Size:=length(ansistring(p));
  367. Move(p^,pc^,Size+1);
  368. inc(pc,size);
  369. end;
  370. end;
  371. SetCodePage(DestS,tmpCP,False);
  372. SetCodePage(DestS,DestCP,True);
  373. fpc_AnsiStr_Decr_Ref(destcopy);
  374. end;
  375. {$endif FPC_HAS_ANSISTR_CONCAT_MULTI}
  376. {$ifdef EXTRAANSISHORT}
  377. Procedure AnsiStr_ShortStr_Concat (Var S1: AnsiString; Var S2 : ShortString);
  378. {
  379. Concatenates a Ansi with a short string; : S2 + S2
  380. }
  381. Var
  382. Size,Location : SizeInt;
  383. begin
  384. Size:=Length(S2);
  385. Location:=Length(S1);
  386. If Size=0 then
  387. exit;
  388. { Setlength takes case of uniqueness
  389. and alllocated memory. We need to use length,
  390. to take into account possibility of S1=Nil }
  391. SetLength (S1,Size+Length(S1));
  392. Move (S2[1],Pointer(Pointer(S1)+Location)^,Size);
  393. PByte( Pointer(S1)+length(S1) )^:=0; { Terminating Zero }
  394. end;
  395. {$endif EXTRAANSISHORT}
  396. {$ifdef FPC_HAS_CPSTRING}
  397. {$ifndef FPC_HAS_ANSISTR_TO_ANSISTR}
  398. {$define FPC_HAS_ANSISTR_TO_ANSISTR}
  399. Function fpc_AnsiStr_To_AnsiStr (const S : RawByteString;cp : TSystemCodePage): RawByteString; [Public, alias: 'FPC_ANSISTR_TO_ANSISTR']; compilerproc;
  400. {
  401. Converts an AnsiString to an AnsiString taking code pages into care
  402. }
  403. Var
  404. Size : SizeInt;
  405. temp : UnicodeString;
  406. orgcp: TSystemCodePage;
  407. begin
  408. result:='';
  409. Size:=Length(S);
  410. if Size>0 then
  411. begin
  412. cp:=TranslatePlaceholderCP(cp);
  413. orgcp:=TranslatePlaceholderCP(StringCodePage(S));
  414. if (orgcp=cp) or (orgcp=CP_NONE) then
  415. begin
  416. SetLength(result,Size);
  417. Move(S[1],result[1],Size);
  418. PAnsiRec(Pointer(result)-AnsiFirstOff)^.CodePage:=cp;
  419. end
  420. else
  421. begin
  422. temp:=UnicodeString(S);
  423. Size:=Length(temp);
  424. widestringmanager.Unicode2AnsiMoveProc(PUnicodeChar(Pointer(temp)),result,cp,Size);
  425. end;
  426. end;
  427. end;
  428. Function fpc_AnsiStr_To_AnsiStr (const S : RawByteString;cp : TSystemCodePage): RawByteString; [external name 'FPC_ANSISTR_TO_ANSISTR'];
  429. {$endif FPC_HAS_CPSTRING}
  430. {$endif FPC_HAS_ANSISTR_TO_ANSISTR}
  431. {$ifndef FPC_HAS_ANSISTR_TO_SHORTSTR}
  432. {$define FPC_HAS_ANSISTR_TO_SHORTSTR}
  433. procedure fpc_AnsiStr_To_ShortStr (out res: shortstring; const S2 : RawByteString);[Public, alias: 'FPC_ANSISTR_TO_SHORTSTR']; compilerproc;
  434. {
  435. Converts a AnsiString to a ShortString;
  436. }
  437. Var
  438. Size : SizeInt;
  439. begin
  440. if S2='' then
  441. res:=''
  442. else
  443. begin
  444. Size:=Length(S2);
  445. If Size>high(res) then
  446. Size:=high(res);
  447. Move (S2[1],res[1],Size);
  448. byte(res[0]):=byte(Size);
  449. end;
  450. end;
  451. {$endif FPC_HAS_ANSISTR_TO_SHORTSTR}
  452. {$ifndef FPC_HAS_SHORTSTR_TO_ANSISTR}
  453. {$define FPC_HAS_SHORTSTR_TO_ANSISTR}
  454. Function fpc_ShortStr_To_AnsiStr (Const S2 : ShortString{$ifdef FPC_HAS_CPSTRING};cp : TSystemCodePage{$endif FPC_HAS_CPSTRING}): RawByteString; compilerproc;
  455. {
  456. Converts a ShortString to a AnsiString;
  457. }
  458. Var
  459. Size : SizeInt;
  460. {$ifndef FPC_HAS_CPSTRING}
  461. cp : TSystemCodePage;
  462. {$endif FPC_HAS_CPSTRING}
  463. begin
  464. {$ifdef FPC_HAS_CPSTRING}
  465. cp:=TranslatePlaceholderCP(cp);
  466. {$else FPC_HAS_CPSTRING}
  467. cp:=DefaultSystemCodePage;
  468. {$endif FPC_HAS_CPSTRING}
  469. Size:=Length(S2);
  470. Setlength(fpc_ShortStr_To_AnsiStr,Size);
  471. if Size>0 then
  472. begin
  473. fpc_shortstr_ansistr_intern_charmove(S2,1,fpc_ShortStr_To_AnsiStr,0,Size);
  474. SetCodePage(fpc_ShortStr_To_AnsiStr,cp,False);
  475. end
  476. end;
  477. {$endif FPC_HAS_SHORTSTR_TO_ANSISTR}
  478. {$ifndef FPC_HAS_CHAR_TO_ANSISTR}
  479. {$define FPC_HAS_CHAR_TO_ANSISTR}
  480. Function fpc_Char_To_AnsiStr(const c : AnsiChar{$ifdef FPC_HAS_CPSTRING};cp : TSystemCodePage{$endif FPC_HAS_CPSTRING}): RawByteString; compilerproc;
  481. {
  482. Converts a Char to a AnsiString;
  483. }
  484. {$ifndef FPC_HAS_CPSTRING}
  485. var
  486. cp : TSystemCodePage;
  487. {$endif FPC_HAS_CPSTRING}
  488. begin
  489. {$ifdef FPC_HAS_CPSTRING}
  490. cp:=TranslatePlaceholderCP(cp);
  491. {$else FPC_HAS_CPSTRING}
  492. cp:=DefaultSystemCodePage;
  493. {$endif FPC_HAS_CPSTRING}
  494. Setlength (fpc_Char_To_AnsiStr,1);
  495. PAnsiChar(fpc_Char_To_AnsiStr)^:=c;
  496. { Terminating Zero already set by SetLength above }
  497. SetCodePage(fpc_Char_To_AnsiStr,cp,False);
  498. end;
  499. {$endif FPC_HAS_CHAR_TO_ANSISTR}
  500. {$ifndef FPC_HAS_PCHAR_TO_ANSISTR}
  501. {$define FPC_HAS_PCHAR_TO_ANSISTR}
  502. Function fpc_PChar_To_AnsiStr(const p : PAnsiChar{$ifdef FPC_HAS_CPSTRING};cp : TSystemCodePage{$endif FPC_HAS_CPSTRING}): RawByteString; compilerproc;
  503. Var
  504. L : SizeInt;
  505. {$ifndef FPC_HAS_CPSTRING}
  506. cp : TSystemCodePage;
  507. {$endif FPC_HAS_CPSTRING}
  508. begin
  509. if (not assigned(p)) or (p[0]=#0) Then
  510. L := 0
  511. else
  512. L:=IndexChar(p^,-1,#0);
  513. SetLength(fpc_PChar_To_AnsiStr,L);
  514. if L > 0 then
  515. begin
  516. {$ifdef FPC_HAS_CPSTRING}
  517. cp:=TranslatePlaceholderCP(cp);
  518. {$else FPC_HAS_CPSTRING}
  519. cp:=DefaultSystemCodePage;
  520. {$endif FPC_HAS_CPSTRING}
  521. fpc_pchar_ansistr_intern_charmove(p,0,fpc_PChar_To_AnsiStr,0,L);
  522. SetCodePage(fpc_PChar_To_AnsiStr,cp,False);
  523. end;
  524. end;
  525. {$endif FPC_HAS_PCHAR_TO_ANSISTR}
  526. {$ifndef FPC_HAS_CHARARRAY_TO_ANSISTR}
  527. {$define FPC_HAS_CHARARRAY_TO_ANSISTR}
  528. Function fpc_CharArray_To_AnsiStr(const arr: array of ansichar; {$ifdef FPC_HAS_CPSTRING}cp : TSystemCodePage;{$endif FPC_HAS_CPSTRING}zerobased: boolean = true): RawByteString; compilerproc;
  529. var
  530. i : SizeInt;
  531. {$ifndef FPC_HAS_CPSTRING}
  532. cp : TSystemCodePage;
  533. {$endif FPC_HAS_CPSTRING}
  534. begin
  535. if (zerobased) then
  536. begin
  537. if (arr[0]=#0) Then
  538. i := 0
  539. else
  540. begin
  541. i:=IndexChar(arr,high(arr)+1,#0);
  542. if i = -1 then
  543. i := high(arr)+1;
  544. end;
  545. end
  546. else
  547. i := high(arr)+1;
  548. SetLength(fpc_CharArray_To_AnsiStr,i);
  549. if i > 0 then
  550. begin
  551. {$ifdef FPC_HAS_CPSTRING}
  552. cp:=TranslatePlaceholderCP(cp);
  553. {$else FPC_HAS_CPSTRING}
  554. cp:=DefaultSystemCodePage;
  555. {$endif FPC_HAS_CPSTRING}
  556. fpc_pchar_ansistr_intern_charmove(pansichar(@arr),0,fpc_CharArray_To_AnsiStr,0,i);
  557. SetCodePage(fpc_CharArray_To_AnsiStr,cp,False);
  558. end;
  559. end;
  560. {$endif FPC_HAS_ANSISTR_TO_CHARARRAY}
  561. {$ifndef FPC_HAS_ANSISTR_TO_CHARARRAY}
  562. {$define FPC_HAS_ANSISTR_TO_CHARARRAY}
  563. procedure fpc_ansistr_to_chararray(out res: array of AnsiChar; const src: RawByteString); compilerproc;
  564. var
  565. len: SizeInt;
  566. begin
  567. len := length(src);
  568. if len > length(res) then
  569. len := length(res);
  570. {$push}{$r-}
  571. { make sure we don't try to access element 1 of the ansistring if it's nil }
  572. if len > 0 then
  573. move(src[1],res[0],len);
  574. fillchar(res[len],length(res)-len,0);
  575. {$pop}
  576. end;
  577. {$endif FPC_HAS_ANSISTR_TO_CHARARRAY}
  578. {$ifndef FPC_HAS_ANSISTR_COMPARE}
  579. {$define FPC_HAS_ANSISTR_COMPARE}
  580. Function fpc_utf8_Compare(const S1,S2 : RawByteString): SizeInt;
  581. var
  582. r1,r2 : RawByteString;
  583. begin
  584. r1:=S1;
  585. r2:=S2;
  586. //convert them to utf8 then compare
  587. SetCodePage(r1,65001);
  588. SetCodePage(r2,65001);
  589. Result:=fpc_AnsiStr_Compare(r1,r2);
  590. end;
  591. Function fpc_AnsiStr_Compare(const S1,S2 : RawByteString): SizeInt;[Public,Alias : 'FPC_ANSISTR_COMPARE']; compilerproc;
  592. {
  593. Compares 2 AnsiStrings;
  594. The result is
  595. <0 if S1<S2
  596. 0 if S1=S2
  597. >0 if S1>S2
  598. }
  599. Var
  600. MaxI,Temp : SizeInt;
  601. cp1,cp2 : TSystemCodePage;
  602. r1,r2 : RawByteString;
  603. begin
  604. if pointer(S1)=pointer(S2) then
  605. begin
  606. result:=0;
  607. exit;
  608. end;
  609. if (pointer(S1)=nil) then
  610. begin
  611. result:=-Length(S2);
  612. exit;
  613. end;
  614. if (pointer(S2)=nil) then
  615. begin
  616. result:=Length(S1);
  617. exit;
  618. end;
  619. cp1:=TranslatePlaceholderCP(StringCodePage(S1));
  620. cp2:=TranslatePlaceholderCP(StringCodePage(S2));
  621. if cp1=cp2 then
  622. begin
  623. Maxi:=Length(S1);
  624. temp:=Length(S2);
  625. If MaxI>Temp then
  626. MaxI:=Temp;
  627. if MaxI>0 then
  628. begin
  629. result:=CompareByte(S1[1],S2[1],MaxI);
  630. if result=0 then
  631. result:=Length(S1)-Length(S2);
  632. end
  633. else
  634. result:=Length(S1)-Length(S2);
  635. end
  636. else
  637. Result:=fpc_utf8_compare(s1,s2);
  638. end;
  639. {$endif FPC_HAS_ANSISTR_COMPARE}
  640. {$ifndef FPC_HAS_ANSISTR_COMPARE_EQUAL}
  641. {$define FPC_HAS_ANSISTR_COMPARE_EQUAL}
  642. Function fpc_utf8_Compare_equal(Const S1,S2 : RawByteString): SizeInt;
  643. Var
  644. r1,r2 : RawByteString;
  645. L1,L2 : SizeInt;
  646. begin
  647. r1:=S1;
  648. r2:=S2;
  649. //convert them to utf8 then compare
  650. SetCodePage(r1,65001);
  651. SetCodePage(r2,65001);
  652. L1:=Length(r1);
  653. L2:=Length(r2);
  654. Result:=L1-L2;
  655. if Result = 0 then
  656. if L1>0 then
  657. result:=CompareByte(r1[1],r2[1],L1);
  658. end;
  659. Function fpc_AnsiStr_Compare_equal(const S1,S2 : RawByteString): SizeInt;[Public,Alias : 'FPC_ANSISTR_COMPARE_EQUAL']; compilerproc;
  660. {
  661. Compares 2 AnsiStrings for equality/inequality only;
  662. The result is
  663. 0 if S1=S2
  664. <>0 if S1<>S2
  665. }
  666. Var
  667. MaxI,Temp : SizeInt;
  668. cp1,cp2 : TSystemCodePage;
  669. begin
  670. if pointer(S1)=pointer(S2) then
  671. Exit(0);
  672. { don't compare strings if one of them is empty }
  673. if (pointer(S1)=nil) or (pointer(S2)=Nil) then
  674. Exit(-1);
  675. cp1:=TranslatePlaceholderCP(StringCodePage(S1));
  676. cp2:=TranslatePlaceholderCP(StringCodePage(S2));
  677. if cp1=cp2 then
  678. begin
  679. Maxi:=Length(S1);
  680. temp:=Length(S2);
  681. Result := Maxi - temp;
  682. if Result = 0 then
  683. if MaxI>0 then
  684. result:=CompareByte(S1[1],S2[1],MaxI);
  685. end
  686. else
  687. begin
  688. Result:=fpc_utf8_Compare_equal(S1,S2);
  689. end;
  690. end;
  691. {$endif FPC_HAS_ANSISTR_COMPARE_EQUAL}
  692. {$ifndef FPC_HAS_ANSISTR_RANGECHECK}
  693. {$define FPC_HAS_ANSISTR_RANGECHECK}
  694. Procedure fpc_AnsiStr_RangeCheck(p: Pointer; index: SizeInt);[Public,Alias : 'FPC_ANSISTR_RANGECHECK']; compilerproc;
  695. begin
  696. if (p=nil) or (index>PAnsiRec(p-AnsiFirstOff)^.Len) or (Index<1) then
  697. HandleErrorAddrFrameInd(201,get_pc_addr,get_frame);
  698. end;
  699. {$endif FPC_HAS_ANSISTR_RANGECHECK}
  700. {$ifndef FPC_HAS_ANSISTR_SETLENGTH}
  701. {$define FPC_HAS_ANSISTR_SETLENGTH}
  702. Procedure fpc_AnsiStr_SetLength (Var S : RawByteString; l : SizeInt{$ifdef FPC_HAS_CPSTRING};cp : TSystemCodePage{$endif FPC_HAS_CPSTRING});[Public,Alias : 'FPC_ANSISTR_SETLENGTH']; compilerproc;
  703. {
  704. Sets The length of string S to L.
  705. Makes sure S is unique, and contains enough room.
  706. }
  707. Var
  708. Temp : Pointer;
  709. lens, lena : SizeInt;
  710. begin
  711. if (l>0) then
  712. begin
  713. if Pointer(S)=nil then
  714. begin
  715. Pointer(S):=NewAnsiString(L);
  716. {$ifdef FPC_HAS_CPSTRING}
  717. cp:=TranslatePlaceholderCP(cp);
  718. PAnsiRec(Pointer(S)-AnsiFirstOff)^.CodePage:=cp;
  719. {$else}
  720. PAnsiRec(Pointer(S)-AnsiFirstOff)^.CodePage:=DefaultSystemCodePage;
  721. {$endif FPC_HAS_CPSTRING}
  722. end
  723. else if PAnsiRec(Pointer(S)-AnsiFirstOff)^.Ref=1 then
  724. begin
  725. Temp:=Pointer(s)-AnsiFirstOff;
  726. lens:=MemSize(Temp);
  727. lena:=AnsiFirstOff+L+sizeof(AnsiChar);
  728. { allow shrinking string if that saves at least half of current size }
  729. if (lena>lens) or ((lens>32) and (lena<=(lens div 2))) then
  730. begin
  731. reallocmem(Temp,lena);
  732. Pointer(S):=Temp+AnsiFirstOff;
  733. end;
  734. end
  735. else
  736. begin
  737. { Reallocation is needed... }
  738. Temp:=NewAnsiString(L);
  739. PAnsiRec(Pointer(Temp)-AnsiFirstOff)^.CodePage:=PAnsiRec(Pointer(S)-AnsiFirstOff)^.CodePage;
  740. lens:=length(s);
  741. if l<=lens then
  742. lens:=l
  743. else
  744. { Also copy a trailing implicit #0 of the original string
  745. to the new larger string }
  746. Inc(lens);
  747. Move(Pointer(S)^,Temp^,lens);
  748. fpc_ansistr_decr_ref(Pointer(s));
  749. Pointer(S):=Temp;
  750. end;
  751. { Force nil termination in case it gets shorter }
  752. PByte(Pointer(S)+l)^:=0;
  753. PAnsiRec(Pointer(S)-AnsiFirstOff)^.Len:=l;
  754. end
  755. else { length=0, deallocate the string }
  756. fpc_ansistr_decr_ref (Pointer(S));
  757. end;
  758. {$endif FPC_HAS_ANSISTR_SETLENGTH}
  759. {$ifdef EXTRAANSISHORT}
  760. Function fpc_AnsiStr_ShortStr_Compare (Var S1 : Pointer; Var S2 : ShortString): SizeInt; compilerproc;
  761. {
  762. Compares a AnsiString with a ShortString;
  763. The result is
  764. <0 if S1<S2
  765. 0 if S1=S2
  766. >0 if S1>S2
  767. }
  768. Var
  769. i,MaxI,Temp : SizeInt;
  770. begin
  771. Temp:=0;
  772. i:=0;
  773. MaxI:=Length(AnsiString(S1));
  774. if MaxI>byte(S2[0]) then
  775. MaxI:=Byte(S2[0]);
  776. While (i<MaxI) and (Temp=0) do
  777. begin
  778. Temp:= PByte(S1+I)^ - Byte(S2[i+1]);
  779. inc(i);
  780. end;
  781. AnsiStr_ShortStr_Compare:=Temp;
  782. end;
  783. {$endif EXTRAANSISHORT}
  784. {*****************************************************************************
  785. Public functions, In interface.
  786. *****************************************************************************}
  787. {$ifndef FPC_SYSTEM_HAS_TRUELY_ANSISTR_UNIQUE}
  788. {$define FPC_SYSTEM_HAS_TRUELY_ANSISTR_UNIQUE}
  789. function fpc_truely_ansistr_unique(Var S : Pointer): Pointer;
  790. Var
  791. SNew : Pointer;
  792. L : SizeInt;
  793. begin
  794. L:=PAnsiRec(Pointer(S)-AnsiFirstOff)^.len;
  795. SNew:=NewAnsiString (L);
  796. Move (Pointer(S)^,SNew^,L+1);
  797. PAnsiRec(SNew-AnsiFirstOff)^.len:=L;
  798. PAnsiRec(SNew-AnsiFirstOff)^.CodePage:=PAnsiRec(Pointer(S)-AnsiFirstOff)^.CodePage;
  799. fpc_ansistr_decr_ref (Pointer(S)); { Thread safe }
  800. pointer(S):=SNew;
  801. pointer(result):=SNew;
  802. end;
  803. {$endif FPC_SYSTEM_HAS_TRUELY_ANSISTR_UNIQUE}
  804. {$ifndef FPC_SYSTEM_HAS_ANSISTR_UNIQUE}
  805. {$define FPC_SYSTEM_HAS_ANSISTR_UNIQUE}
  806. // MV: inline the basic checks for case that S is already unique.
  807. // Rest is too complex to inline, so factor that out as a call.
  808. Function fpc_ansistr_Unique(Var S : Pointer): Pointer; [Public,Alias : 'FPC_ANSISTR_UNIQUE']; compilerproc; inline;
  809. {
  810. Make sure reference count of S is 1,
  811. using copy-on-write semantics.
  812. }
  813. begin
  814. pointer(result) := pointer(s);
  815. If Pointer(S)=Nil then
  816. exit;
  817. if PAnsiRec(Pointer(S)-AnsiFirstOff)^.Ref<>1 then
  818. result:=fpc_truely_ansistr_unique(s);
  819. end;
  820. {$endif FPC_SYSTEM_HAS_ANSISTR_UNIQUE}
  821. {$ifndef FPC_HAS_ANSISTR_COPY}
  822. {$define FPC_HAS_ANSISTR_COPY}
  823. Function Fpc_Ansistr_Copy(Const S : RawByteString; Index,Size : SizeInt): RawByteString;compilerproc;
  824. var
  825. ResultAddress : Pointer;
  826. begin
  827. ResultAddress:=Nil;
  828. dec(index);
  829. if Index < 0 then
  830. Index := 0;
  831. { Check Size. Accounts for Zero-length S, the double check is needed because
  832. Size can be maxint and will get <0 when adding index }
  833. if (Size>Length(S)) or
  834. (Index+Size>Length(S)) then
  835. Size:=Length(S)-Index;
  836. If Size>0 then
  837. begin
  838. ResultAddress:=NewAnsiString(Size);
  839. if ResultAddress<>Nil then
  840. begin
  841. Move(Pointer(Pointer(S)+index)^,ResultAddress^,Size);
  842. PByte(ResultAddress+Size)^:=0;
  843. PAnsiRec(ResultAddress-AnsiFirstOff)^.Len:=Size;
  844. PAnsiRec(ResultAddress-AnsiFirstOff)^.CodePage:=PAnsiRec(Pointer(S)-AnsiFirstOff)^.CodePage;
  845. end;
  846. end;
  847. fpc_ansistr_decr_ref(Pointer(fpc_ansistr_copy));
  848. Pointer(fpc_ansistr_Copy):=ResultAddress;
  849. end;
  850. {$endif FPC_HAS_ANSISTR_COPY}
  851. {$ifndef FPC_HAS_POS_SHORTSTR_ANSISTR}
  852. {$define FPC_HAS_POS_SHORTSTR_ANSISTR}
  853. Function Pos(Const Substr : ShortString; Const Source : RawByteString; Offset : Sizeint = 1) : SizeInt;
  854. var
  855. i,MaxLen : SizeInt;
  856. pc : PAnsiChar;
  857. begin
  858. Pos:=0;
  859. if (Length(SubStr)>0) and (Offset>0) and (Offset<=Length(Source)) then
  860. begin
  861. MaxLen:=Length(source)-Length(SubStr);
  862. i:=Offset-1;
  863. pc:=@source[Offset];
  864. while (i<=MaxLen) do
  865. begin
  866. inc(i);
  867. if (SubStr[1]=pc^) and
  868. (CompareByte(Substr[1],pc^,Length(SubStr))=0) then
  869. begin
  870. Pos:=i;
  871. exit;
  872. end;
  873. inc(pc);
  874. end;
  875. end;
  876. end;
  877. {$endif FPC_HAS_POS_SHORTSTR_ANSISTR}
  878. {$ifndef FPC_HAS_POS_ANSISTR_ANSISTR}
  879. {$define FPC_HAS_POS_ANSISTR_ANSISTR}
  880. Function Pos(Const Substr : RawByteString; Const Source : RawByteString; Offset : Sizeint = 1) : SizeInt;
  881. var
  882. i,MaxLen : SizeInt;
  883. pc : PAnsiChar;
  884. begin
  885. Pos:=0;
  886. if (Length(SubStr)>0) and (Offset>0) and (Offset<=Length(Source)) then
  887. begin
  888. MaxLen:=Length(source)-Length(SubStr);
  889. i:=Offset-1;
  890. pc:=@source[Offset];
  891. while (i<=MaxLen) do
  892. begin
  893. inc(i);
  894. if (SubStr[1]=pc^) and
  895. (CompareByte(Substr[1],pc^,Length(SubStr))=0) then
  896. begin
  897. Pos:=i;
  898. exit;
  899. end;
  900. inc(pc);
  901. end;
  902. end;
  903. end;
  904. {$endif FPC_HAS_POS_ANSISTR_ANSISTR}
  905. {$ifndef FPC_HAS_POS_ANSICHAR_ANSISTR}
  906. {$define FPC_HAS_POS_ANSICHAR_ANSISTR}
  907. { Faster version for a char alone. Must be implemented because }
  908. { pos(c: char; const s: shortstring) also exists, so otherwise }
  909. { using pos(char,pchar) will always call the shortstring version }
  910. { (exact match for first argument), also with $h+ (JM) }
  911. Function Pos(c : AnsiChar; Const s : RawByteString; Offset : Sizeint = 1) : SizeInt;
  912. var
  913. i: SizeInt;
  914. pc : PAnsiChar;
  915. begin
  916. Pos:=0;
  917. If (Offset<1) or (Offset>Length(S)) then
  918. exit;
  919. pc:=@s[OffSet];
  920. for i:=Offset to length(s) do
  921. begin
  922. if pc^=c then
  923. begin
  924. pos:=i;
  925. exit;
  926. end;
  927. inc(pc);
  928. end;
  929. pos:=0;
  930. end;
  931. {$endif FPC_HAS_POS_ANSICHAR_ANSISTR}
  932. {$ifndef FPUNONE}
  933. Function fpc_Val_Real_AnsiStr(Const S : RawByteString; out Code : ValSInt): ValReal; [public, alias:'FPC_VAL_REAL_ANSISTR']; compilerproc;
  934. Var
  935. SS : String;
  936. begin
  937. fpc_Val_Real_AnsiStr := 0;
  938. if length(S) > 255 then
  939. code := 256
  940. else
  941. begin
  942. SS := S;
  943. Val(SS,fpc_Val_Real_AnsiStr,code);
  944. end;
  945. end;
  946. {$endif}
  947. Function fpc_Val_Currency_AnsiStr(Const S : RawByteString; out Code : ValSInt): Currency; [public, alias:'FPC_VAL_CURRENCY_ANSISTR']; compilerproc;
  948. Var
  949. SS : String;
  950. begin
  951. if length(S) > 255 then
  952. begin
  953. fpc_Val_Currency_AnsiStr := 0;
  954. code := 256;
  955. end
  956. else
  957. begin
  958. SS := S;
  959. Val(SS,fpc_Val_Currency_AnsiStr,code);
  960. end;
  961. end;
  962. Function fpc_Val_UInt_AnsiStr (Const S : RawByteString; out Code : ValSInt): ValUInt; [public, alias:'FPC_VAL_UINT_ANSISTR']; compilerproc;
  963. Var
  964. SS : ShortString;
  965. begin
  966. fpc_Val_UInt_AnsiStr := 0;
  967. if length(S) > 255 then
  968. code := 256
  969. else
  970. begin
  971. SS := S;
  972. Val(SS,fpc_Val_UInt_AnsiStr,code);
  973. end;
  974. end;
  975. Function fpc_Val_SInt_AnsiStr (DestSize: SizeInt; Const S : RawByteString; out Code : ValSInt): ValSInt; [public, alias:'FPC_VAL_SINT_ANSISTR']; compilerproc;
  976. Var
  977. SS : ShortString;
  978. begin
  979. fpc_Val_SInt_AnsiStr:=0;
  980. if length(S)>255 then
  981. code:=256
  982. else
  983. begin
  984. SS := S;
  985. fpc_Val_SInt_AnsiStr := int_Val_SInt_ShortStr(DestSize,SS,Code);
  986. end;
  987. end;
  988. {$ifndef CPU64}
  989. Function fpc_Val_qword_AnsiStr (Const S : RawByteString; out Code : ValSInt): qword; [public, alias:'FPC_VAL_QWORD_ANSISTR']; compilerproc;
  990. Var
  991. SS : ShortString;
  992. begin
  993. fpc_Val_qword_AnsiStr:=0;
  994. if length(S)>255 then
  995. code:=256
  996. else
  997. begin
  998. SS := S;
  999. Val(SS,fpc_Val_qword_AnsiStr,Code);
  1000. end;
  1001. end;
  1002. Function fpc_Val_int64_AnsiStr (Const S : RawByteString; out Code : ValSInt): Int64; [public, alias:'FPC_VAL_INT64_ANSISTR']; compilerproc;
  1003. Var
  1004. SS : ShortString;
  1005. begin
  1006. fpc_Val_int64_AnsiStr:=0;
  1007. if length(S)>255 then
  1008. code:=256
  1009. else
  1010. begin
  1011. SS := s;
  1012. Val(SS,fpc_Val_int64_AnsiStr,Code);
  1013. end;
  1014. end;
  1015. {$endif CPU64}
  1016. {$if defined(CPU16) or defined(CPU8)}
  1017. Function fpc_Val_longword_AnsiStr (Const S : RawByteString; out Code : ValSInt): longword; [public, alias:'FPC_VAL_LONGWORD_ANSISTR']; compilerproc;
  1018. Var
  1019. SS : ShortString;
  1020. begin
  1021. fpc_Val_longword_AnsiStr:=0;
  1022. if length(S)>255 then
  1023. code:=256
  1024. else
  1025. begin
  1026. SS := S;
  1027. Val(SS,fpc_Val_longword_AnsiStr,Code);
  1028. end;
  1029. end;
  1030. Function fpc_Val_longint_AnsiStr (Const S : RawByteString; out Code : ValSInt): LongInt; [public, alias:'FPC_VAL_LONGINT_ANSISTR']; compilerproc;
  1031. Var
  1032. SS : ShortString;
  1033. begin
  1034. fpc_Val_longint_AnsiStr:=0;
  1035. if length(S)>255 then
  1036. code:=256
  1037. else
  1038. begin
  1039. SS := s;
  1040. Val(SS,fpc_Val_longint_AnsiStr,Code);
  1041. end;
  1042. end;
  1043. Function fpc_Val_word_AnsiStr (Const S : RawByteString; out Code : ValSInt): word; [public, alias:'FPC_VAL_WORD_ANSISTR']; compilerproc;
  1044. Var
  1045. SS : ShortString;
  1046. begin
  1047. fpc_Val_word_AnsiStr:=0;
  1048. if length(S)>255 then
  1049. code:=256
  1050. else
  1051. begin
  1052. SS := S;
  1053. Val(SS,fpc_Val_word_AnsiStr,Code);
  1054. end;
  1055. end;
  1056. Function fpc_Val_smallint_AnsiStr (Const S : RawByteString; out Code : ValSInt): smallint; [public, alias:'FPC_VAL_SMALLINT_ANSISTR']; compilerproc;
  1057. Var
  1058. SS : ShortString;
  1059. begin
  1060. fpc_Val_smallint_AnsiStr:=0;
  1061. if length(S)>255 then
  1062. code:=256
  1063. else
  1064. begin
  1065. SS := s;
  1066. Val(SS,fpc_Val_smallint_AnsiStr,Code);
  1067. end;
  1068. end;
  1069. {$endif CPU16 or CPU8}
  1070. {$if defined(CPU8)}
  1071. Function fpc_Val_word_AnsiStr (Const S : RawByteString; out Code : ValSInt): longword; [public, alias:'FPC_VAL_WORD_ANSISTR']; compilerproc;
  1072. Var
  1073. SS : ShortString;
  1074. begin
  1075. fpc_Val_longword_AnsiStr:=0;
  1076. if length(S)>255 then
  1077. code:=256
  1078. else
  1079. begin
  1080. SS := S;
  1081. Val(SS,fpc_Val_longword_AnsiStr,Code);
  1082. end;
  1083. end;
  1084. Function fpc_Val_smallint_AnsiStr (Const S : RawByteString; out Code : ValSInt): LongInt; [public, alias:'FPC_VAL_SMALLINT_ANSISTR']; compilerproc;
  1085. Var
  1086. SS : ShortString;
  1087. begin
  1088. fpc_Val_longint_AnsiStr:=0;
  1089. if length(S)>255 then
  1090. code:=256
  1091. else
  1092. begin
  1093. SS := s;
  1094. Val(SS,fpc_Val_longint_AnsiStr,Code);
  1095. end;
  1096. end;
  1097. {$endif CPU8}
  1098. {$ifndef FPUNONE}
  1099. procedure fpc_AnsiStr_Float(d : ValReal;len,fr,rt : SizeInt;out s : RawByteString{$ifdef FPC_HAS_CPSTRING};cp : TSystemCodePage{$endif FPC_HAS_CPSTRING});[public,alias:'FPC_ANSISTR_FLOAT']; compilerproc; inline;
  1100. var
  1101. ss: ShortString;
  1102. begin
  1103. str_real(len,fr,d,treal_type(rt),ss);
  1104. s:=ss;
  1105. {$ifdef FPC_HAS_CPSTRING}
  1106. SetCodePage(s,cp,false);
  1107. {$endif FPC_HAS_CPSTRING}
  1108. end;
  1109. {$endif}
  1110. {$ifndef FPC_STR_ENUM_INTERN}
  1111. procedure fpc_ansistr_enum(ordinal,len:sizeint;typinfo,ord2strindex:pointer;out s:RawByteString{$ifdef FPC_HAS_CPSTRING};cp : TSystemCodePage{$endif FPC_HAS_CPSTRING});[public,alias:'FPC_ANSISTR_ENUM'];compilerproc; inline;
  1112. var ss:shortstring;
  1113. begin
  1114. fpc_shortstr_enum(ordinal,len,typinfo,ord2strindex,ss);
  1115. s:=ss;
  1116. {$ifdef FPC_HAS_CPSTRING}
  1117. SetCodePage(s,cp,false);
  1118. {$endif FPC_HAS_CPSTRING}
  1119. end;
  1120. {$endif FPC_STR_ENUM_INTERN}
  1121. procedure fpc_ansistr_bool(b : boolean;len:sizeint;out s:RawByteString{$ifdef FPC_HAS_CPSTRING};cp : TSystemCodePage{$endif FPC_HAS_CPSTRING});[public,alias:'FPC_ANSISTR_BOOL'];compilerproc; inline;
  1122. var
  1123. ss:shortstring;
  1124. begin
  1125. fpc_shortstr_bool(b,len,ss);
  1126. s:=ss;
  1127. {$ifdef FPC_HAS_CPSTRING}
  1128. SetCodePage(s,cp,false);
  1129. {$endif FPC_HAS_CPSTRING}
  1130. end;
  1131. {$ifndef FPC_STR_ENUM_INTERN}
  1132. function fpc_val_enum_ansistr(str2ordindex:pointer;const s:RawByteString;out code:valsint):longint; [public, alias:'FPC_VAL_ENUM_ANSISTR']; compilerproc;
  1133. begin
  1134. fpc_val_enum_ansistr:=fpc_val_enum_shortstr(str2ordindex,s,code);
  1135. end;
  1136. {$endif FPC_STR_ENUM_INTERN}
  1137. procedure fpc_AnsiStr_Currency(c : currency;len,fr : SizeInt;out s : RawByteString{$ifdef FPC_HAS_CPSTRING};cp : TSystemCodePage{$endif FPC_HAS_CPSTRING});[public,alias:'FPC_ANSISTR_CURRENCY']; compilerproc; inline;
  1138. var
  1139. ss: ShortString;
  1140. begin
  1141. str(c:len:fr,ss);
  1142. s:=ss;
  1143. {$ifdef FPC_HAS_CPSTRING}
  1144. SetCodePage(s,cp,false);
  1145. {$endif FPC_HAS_CPSTRING}
  1146. end;
  1147. Procedure fpc_AnsiStr_UInt(v : ValUInt;Len : SizeInt; out S : RawByteString{$ifdef FPC_HAS_CPSTRING};cp : TSystemCodePage{$endif FPC_HAS_CPSTRING});[Public,Alias : 'FPC_ANSISTR_VALUINT']; compilerproc; inline;
  1148. Var
  1149. SS : ShortString;
  1150. begin
  1151. str(v:Len,SS);
  1152. S:=SS;
  1153. {$ifdef FPC_HAS_CPSTRING}
  1154. SetCodePage(s,cp,false);
  1155. {$endif FPC_HAS_CPSTRING}
  1156. end;
  1157. Procedure fpc_AnsiStr_SInt(v : ValSInt;Len : SizeInt; out S : RawByteString{$ifdef FPC_HAS_CPSTRING};cp : TSystemCodePage{$endif FPC_HAS_CPSTRING});[Public,Alias : 'FPC_ANSISTR_VALSINT']; compilerproc; inline;
  1158. Var
  1159. SS : ShortString;
  1160. begin
  1161. str (v:Len,SS);
  1162. S:=SS;
  1163. {$ifdef FPC_HAS_CPSTRING}
  1164. SetCodePage(s,cp,false);
  1165. {$endif FPC_HAS_CPSTRING}
  1166. end;
  1167. {$ifndef CPU64}
  1168. Procedure fpc_AnsiStr_QWord(v : QWord;Len : SizeInt; out S : RawByteString{$ifdef FPC_HAS_CPSTRING};cp : TSystemCodePage{$endif FPC_HAS_CPSTRING});[Public,Alias : 'FPC_ANSISTR_QWORD']; compilerproc; inline;
  1169. Var
  1170. SS : ShortString;
  1171. begin
  1172. str(v:Len,SS);
  1173. S:=SS;
  1174. {$ifdef FPC_HAS_CPSTRING}
  1175. SetCodePage(s,cp,false);
  1176. {$endif FPC_HAS_CPSTRING}
  1177. end;
  1178. Procedure fpc_AnsiStr_Int64(v : Int64; Len : SizeInt; out S : RawByteString{$ifdef FPC_HAS_CPSTRING};cp : TSystemCodePage{$endif FPC_HAS_CPSTRING});[Public,Alias : 'FPC_ANSISTR_INT64']; compilerproc; inline;
  1179. Var
  1180. SS : ShortString;
  1181. begin
  1182. str (v:Len,SS);
  1183. S:=SS;
  1184. {$ifdef FPC_HAS_CPSTRING}
  1185. SetCodePage(s,cp,false);
  1186. {$endif FPC_HAS_CPSTRING}
  1187. end;
  1188. {$endif CPU64}
  1189. {$if defined(CPU16) or defined(CPU8)}
  1190. Procedure fpc_AnsiStr_LongWord(v : LongWord;Len : SizeInt; out S : RawByteString{$ifdef FPC_HAS_CPSTRING};cp : TSystemCodePage{$endif FPC_HAS_CPSTRING});[Public,Alias : 'FPC_ANSISTR_LONGWORD']; compilerproc; inline;
  1191. Var
  1192. SS : ShortString;
  1193. begin
  1194. str(v:Len,SS);
  1195. S:=SS;
  1196. {$ifdef FPC_HAS_CPSTRING}
  1197. SetCodePage(s,cp,false);
  1198. {$endif FPC_HAS_CPSTRING}
  1199. end;
  1200. Procedure fpc_AnsiStr_LongInt(v : LongInt; Len : SizeInt; out S : RawByteString{$ifdef FPC_HAS_CPSTRING};cp : TSystemCodePage{$endif FPC_HAS_CPSTRING});[Public,Alias : 'FPC_ANSISTR_LONGINT']; compilerproc; inline;
  1201. Var
  1202. SS : ShortString;
  1203. begin
  1204. str (v:Len,SS);
  1205. S:=SS;
  1206. {$ifdef FPC_HAS_CPSTRING}
  1207. SetCodePage(s,cp,false);
  1208. {$endif FPC_HAS_CPSTRING}
  1209. end;
  1210. Procedure fpc_AnsiStr_Word(v : Word;Len : SizeInt; out S : RawByteString{$ifdef FPC_HAS_CPSTRING};cp : TSystemCodePage{$endif FPC_HAS_CPSTRING});[Public,Alias : 'FPC_ANSISTR_WORD']; compilerproc; inline;
  1211. Var
  1212. SS : ShortString;
  1213. begin
  1214. str(v:Len,SS);
  1215. S:=SS;
  1216. {$ifdef FPC_HAS_CPSTRING}
  1217. SetCodePage(s,cp,false);
  1218. {$endif FPC_HAS_CPSTRING}
  1219. end;
  1220. Procedure fpc_AnsiStr_SmallInt(v : SmallInt; Len : SizeInt; out S : RawByteString{$ifdef FPC_HAS_CPSTRING};cp : TSystemCodePage{$endif FPC_HAS_CPSTRING});[Public,Alias : 'FPC_ANSISTR_SMALLINT']; compilerproc; inline;
  1221. Var
  1222. SS : ShortString;
  1223. begin
  1224. str (v:Len,SS);
  1225. S:=SS;
  1226. {$ifdef FPC_HAS_CPSTRING}
  1227. SetCodePage(s,cp,false);
  1228. {$endif FPC_HAS_CPSTRING}
  1229. end;
  1230. {$endif CPU16 or CPU8}
  1231. Procedure {$ifdef VER3_0}Delete{$else}fpc_ansistr_delete{$endif}(Var S : RawByteString; Index,Size: SizeInt);
  1232. Var
  1233. LS : SizeInt;
  1234. begin
  1235. ls:=Length(S);
  1236. If (Index>LS) or (Index<=0) or (Size<=0) then
  1237. exit;
  1238. UniqueString(S);
  1239. If (Size>LS-Index) then // Size+Index gives overflow ??
  1240. Size:=LS-Index+1;
  1241. If (Size<=LS-Index) then
  1242. begin
  1243. Dec(Index);
  1244. fpc_pchar_ansistr_intern_charmove(pchar(S),Index+Size,S,Index,LS-Index-Size+1);
  1245. end;
  1246. Setlength(S,LS-Size);
  1247. end;
  1248. Procedure {$ifdef VER3_0}Insert{$else}fpc_ansistr_insert{$endif}(Const Source : RawByteString; Var S : RawByteString; Index : SizeInt);
  1249. var
  1250. Temp : RawByteString;
  1251. LS : SizeInt;
  1252. cp : TSystemCodePage;
  1253. begin
  1254. If Length(Source)=0 then
  1255. exit;
  1256. if index <= 0 then
  1257. index := 1;
  1258. Ls:=Length(S);
  1259. if index > LS then
  1260. index := LS+1;
  1261. Dec(Index);
  1262. SetLength(Temp,Length(Source)+LS);
  1263. if length(S)<>0 then
  1264. cp:=TranslatePlaceholderCP(StringCodePage(S))
  1265. else
  1266. cp:=TranslatePlaceholderCP(StringCodePage(Source));
  1267. SetCodePage(Temp,cp,false);
  1268. If Index>0 then
  1269. fpc_pchar_ansistr_intern_charmove(pchar(S),0,Temp,0,Index);
  1270. fpc_pchar_ansistr_intern_charmove(pchar(Source),0,Temp,Index,Length(Source));
  1271. If (LS-Index)>0 then
  1272. fpc_pchar_ansistr_intern_charmove(pchar(S),Index,Temp,Length(Source)+Index,LS-Index);
  1273. S:=Temp;
  1274. end;
  1275. {$ifndef FPC_HAS_ANSISTR_OF_CHAR}
  1276. {$define FPC_HAS_ANSISTR_OF_CHAR}
  1277. Function StringOfChar(c : Ansichar;l : SizeInt) : AnsiString;
  1278. begin
  1279. SetLength(StringOfChar,l);
  1280. FillChar(Pointer(StringOfChar)^,Length(StringOfChar),c);
  1281. end;
  1282. {$endif FPC_HAS_ANSISTR_OF_CHAR}
  1283. {$ifdef FPC_HAS_CPSTRING}
  1284. Procedure fpc_setstring_ansistr_pansichar(out S : RawByteString; Buf : PAnsiChar; Len : SizeInt; cp: TSystemCodePage); rtlproc; compilerproc;
  1285. {$else}
  1286. Procedure SetString(out S : AnsiString; Buf : PAnsiChar; Len : SizeInt);
  1287. {$endif}
  1288. begin
  1289. SetLength(S,Len);
  1290. {$ifdef FPC_HAS_CPSTRING}
  1291. SetCodePage(S,cp,false);
  1292. {$endif}
  1293. If (Buf<>Nil) then
  1294. fpc_pchar_ansistr_intern_charmove(Buf,0,S,0,Len);
  1295. end;
  1296. {$ifdef FPC_HAS_CPSTRING}
  1297. Procedure fpc_setstring_ansistr_pwidechar(out S : RawByteString; Buf : PWideChar; Len : SizeInt; cp: TSystemCodePage); rtlproc; compilerproc;
  1298. {$else}
  1299. Procedure SetString(out S : AnsiString; Buf : PWideChar; Len : SizeInt);
  1300. {$endif}
  1301. begin
  1302. if (Buf<>nil) and (Len>0) then
  1303. widestringmanager.Wide2AnsiMoveProc(Buf,S,{$ifdef FPC_HAS_CPSTRING}cp{$else}DefaultSystemCodePage{$endif},Len)
  1304. else
  1305. begin
  1306. SetLength(S, Len);
  1307. {$ifdef FPC_HAS_CPSTRING}
  1308. SetCodePage(S,cp,false);
  1309. {$endif}
  1310. end;
  1311. end;
  1312. {$ifndef FPC_HAS_UPCASE_ANSISTR}
  1313. {$define FPC_HAS_UPCASE_ANSISTR}
  1314. function upcase(const s : ansistring) : ansistring;
  1315. var
  1316. i : SizeInt;
  1317. begin
  1318. Setlength(result,length(s));
  1319. for i := 1 to length (s) do
  1320. result[i] := upcase(s[i]);
  1321. end;
  1322. {$endif FPC_HAS_UPCASE_ANSISTR}
  1323. {$ifndef FPC_HAS_LOWERCASE_ANSISTR}
  1324. {$define FPC_HAS_LOWERCASE_ANSISTR}
  1325. function lowercase(const s : ansistring) : ansistring;
  1326. var
  1327. i : SizeInt;
  1328. begin
  1329. Setlength(result,length(s));
  1330. for i := 1 to length (s) do
  1331. result[i] := lowercase(s[i]);
  1332. end;
  1333. {$endif FPC_HAS_LOWERCASE_ANSISTR}
  1334. {$ifndef FPC_HAS_ANSISTR_STRINGCODEPAGE}
  1335. {$define FPC_HAS_ANSISTR_STRINGCODEPAGE}
  1336. function StringCodePage(const S: RawByteString): TSystemCodePage; overload;
  1337. begin
  1338. {$ifdef FPC_HAS_CPSTRING}
  1339. if assigned(Pointer(S)) then
  1340. Result:=PAnsiRec(pointer(S)-AnsiFirstOff)^.CodePage
  1341. else
  1342. {$endif FPC_HAS_CPSTRING}
  1343. Result:=DefaultSystemCodePage;
  1344. end;
  1345. {$endif FPC_HAS_ANSISTR_STRINGCODEPAGE}
  1346. {$ifndef FPC_HAS_ANSISTR_STRINGELEMENTSIZE}
  1347. {$define FPC_HAS_ANSISTR_STRINGELEMENTSIZE}
  1348. function StringElementSize(const S: RawByteString): Word; overload;
  1349. begin
  1350. if assigned(Pointer(S)) then
  1351. Result:=PAnsiRec(pointer(S)-AnsiFirstOff)^.ElementSize
  1352. else
  1353. Result:=SizeOf(AnsiChar);
  1354. end;
  1355. {$endif FPC_HAS_ANSISTR_STRINGELEMENTSIZE}
  1356. {$ifndef FPC_HAS_ANSISTR_STRINGREFCOUNT}
  1357. {$define FPC_HAS_ANSISTR_STRINGREFCOUNT}
  1358. function StringRefCount(const S: RawByteString): SizeInt; overload;
  1359. begin
  1360. if assigned(Pointer(S)) then
  1361. Result:=PAnsiRec(pointer(S)-AnsiFirstOff)^.Ref
  1362. else
  1363. Result:=0;
  1364. end;
  1365. {$endif FPC_HAS_ANSISTR_STRINGREFCOUNT}
  1366. {$ifndef FPC_HAS_ANSISTR_SETCODEPAGE}
  1367. {$define FPC_HAS_ANSISTR_SETCODEPAGE}
  1368. procedure InternalSetCodePage(var s : RawByteString; CodePage : TSystemCodePage; Convert : Boolean = True);
  1369. begin
  1370. if Convert then
  1371. begin
  1372. {$ifdef FPC_HAS_CPSTRING}
  1373. s:=fpc_AnsiStr_To_AnsiStr(s,CodePage);
  1374. {$else FPC_HAS_CPSTRING}
  1375. UniqueString(s);
  1376. PAnsiRec(pointer(s)-AnsiFirstOff)^.CodePage:=CodePage;
  1377. {$endif FPC_HAS_CPSTRING}
  1378. end
  1379. else
  1380. begin
  1381. UniqueString(s);
  1382. PAnsiRec(pointer(s)-AnsiFirstOff)^.CodePage:=CodePage;
  1383. end;
  1384. end;
  1385. { use this wrapper for the simple case to avoid the generation of a temp. ansistring which causes
  1386. extra exception frames }
  1387. procedure SetCodePage(var s : RawByteString; CodePage : TSystemCodePage; Convert : Boolean = True);
  1388. var
  1389. OrgCodePage,
  1390. TranslatedCodePage,
  1391. TranslatedCurrentCodePage: TSystemCodePage;
  1392. begin
  1393. if (S='') then
  1394. exit;
  1395. { if the codepage are identical, we don't have to do anything (even if the
  1396. string has multiple references) }
  1397. OrgCodePage:=PAnsiRec(pointer(S)-AnsiFirstOff)^.CodePage;
  1398. if OrgCodePage=CodePage then
  1399. exit;
  1400. { if we're just replacing a placeholder code page with its actual value or
  1401. vice versa, we don't have to perform any conversion }
  1402. TranslatedCurrentCodePage:=TranslatePlaceholderCP(OrgCodePage);
  1403. TranslatedCodePage:=TranslatePlaceholderCP(CodePage);
  1404. Convert:=Convert and
  1405. (TranslatedCurrentCodePage<>TranslatedCodePage);
  1406. if not Convert and (PAnsiRec(pointer(S)-AnsiFirstOff)^.Ref=1) then
  1407. PAnsiRec(pointer(S)-AnsiFirstOff)^.CodePage:=CodePage
  1408. else
  1409. InternalSetCodePage(S,CodePage,Convert);
  1410. end;
  1411. {$endif FPC_HAS_ANSISTR_SETCODEPAGE}
  1412. procedure SetMultiByteConversionCodePage(CodePage: TSystemCodePage);
  1413. begin
  1414. DefaultSystemCodePage:=CodePage;
  1415. end;
  1416. procedure SetMultiByteFileSystemCodePage(CodePage: TSystemCodePage);
  1417. begin
  1418. DefaultFileSystemCodePage:=CodePage;
  1419. end;
  1420. procedure SetMultiByteRTLFileSystemCodePage(CodePage: TSystemCodePage);
  1421. begin
  1422. DefaultRTLFileSystemCodePage:=CodePage;
  1423. end;