2
0

syssb.inc 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703
  1. {%MainUnit sysutils.pp}
  2. { TGenericStringBuilder }
  3. constructor TGenericStringBuilder.Create;
  4. begin
  5. Create(DefaultCapacity,Maxint);
  6. end;
  7. constructor TGenericStringBuilder.Create(const AValue: SBString; aCapacity: Integer);
  8. begin
  9. Create(aCapacity,Maxint);
  10. if (system.Length(AValue)>0) then
  11. Append(AValue);
  12. end;
  13. constructor TGenericStringBuilder.Create(const AValue: SBString; StartIndex, Alength,
  14. aCapacity: Integer);
  15. begin
  16. Create(Copy(AValue,StartIndex+1,Alength), aCapacity);
  17. end;
  18. constructor TGenericStringBuilder.Create(aCapacity, aMaxCapacity: Integer);
  19. begin
  20. FMaxCapacity:=aMaxCapacity;
  21. Capacity:=aCapacity;
  22. FLength:=0;
  23. end;
  24. constructor TGenericStringBuilder.Create(aCapacity: Integer);
  25. begin
  26. Create(aCapacity,MaxInt);
  27. end;
  28. constructor TGenericStringBuilder.Create(const AValue: SBString);
  29. begin
  30. Create(aValue,DefaultCapacity);
  31. end;
  32. { Property getter/setter }
  33. function TGenericStringBuilder.GetLength: Integer;
  34. begin
  35. Result:=FLength;
  36. end;
  37. function TGenericStringBuilder.GetCapacity: Integer;
  38. begin
  39. Result:=System.Length(FData);
  40. end;
  41. function TGenericStringBuilder.GetC(Index: Integer): SBChar;
  42. begin
  43. CheckNegative(Index,'Index');
  44. CheckRange(Index,0,Length);
  45. Result:=FData[Index];
  46. end;
  47. procedure TGenericStringBuilder.SetC(Index: Integer; AValue: SBChar);
  48. begin
  49. CheckNegative(Index,'Index');
  50. CheckRange(Index,0,Length-1);
  51. FData[Index]:=AValue;
  52. end;
  53. procedure TGenericStringBuilder.SetLength(AValue: Integer);
  54. begin
  55. CheckNegative(AValue,'AValue');
  56. CheckRange(AValue,0,MaxCapacity);
  57. While AValue>Capacity do
  58. Grow;
  59. Flength:=AValue;
  60. end;
  61. { Check functions }
  62. procedure TGenericStringBuilder.CheckRange(Idx, Count, MaxLen: Integer);
  63. begin
  64. if (Idx<0) or (Idx+Count>MaxLen) then
  65. Raise ERangeError.CreateFmt(SListIndexError,[Idx]);
  66. end;
  67. procedure TGenericStringBuilder.CheckNegative(const AValue: Integer;
  68. const AName: SBString);
  69. begin
  70. if (AValue<0) then
  71. Raise ERangeError.CreateFmt(SParamIsNegative,[AName])
  72. end;
  73. { These do the actual Appending/Inserting }
  74. procedure TGenericStringBuilder.DoAppend(const S: {$IFDEF SBUNICODE}SBString{$ELSE}RawByteString{$ENDIF});
  75. Var
  76. L,SL : Integer;
  77. begin
  78. SL:=System.Length(S);
  79. if SL>0 then
  80. begin
  81. L:=Length;
  82. Length:=L+SL;
  83. Move(S[1], FData[L],SL*SizeOf(SBChar));
  84. end;
  85. end;
  86. procedure TGenericStringBuilder.DoAppend(const AValue: TSBCharArray; Idx, aCount: Integer
  87. );
  88. Var
  89. L : integer;
  90. begin
  91. L:=Length;
  92. CheckRange(Idx,aCount,System.Length(AValue));
  93. Length:=L+aCount;
  94. Move(AValue[Idx],FData[L],aCount*SizeOf(SBChar));
  95. end;
  96. procedure TGenericStringBuilder.DoInsert(Index: Integer; const AValue: SBString);
  97. Var
  98. ShiftLen,LV : Integer;
  99. begin
  100. CheckRange(Index,0,Length-1);
  101. LV:=System.Length(AValue);
  102. ShiftLen:=Length-Index;
  103. Length:=Length+LV;
  104. Move(FData[Index],FData[Index+LV],ShiftLen*SizeOf(SBChar));
  105. Move(AValue[1],FData[Index],LV*SizeOf(SBChar));
  106. end;
  107. procedure TGenericStringBuilder.DoInsert(Index: Integer; const AValue: TSBCharArray;
  108. StartIndex, SBCharCount: Integer);
  109. Var
  110. ShiftLen : Integer;
  111. begin
  112. CheckRange(Index,0,Length-1);
  113. CheckNegative(StartIndex,'StartIndex');
  114. CheckNegative(SBCharCount,'SBCharCount');
  115. CheckRange(StartIndex,SBCharCount,System.Length(AValue));
  116. Length:=Length+SBCharCount;
  117. ShiftLen:=Length-Index;
  118. if ShiftLen> 0 then
  119. Move(FData[Index], FData[Index+SBCharCount],ShiftLen*SizeOf(SBChar));
  120. Move(AValue[StartIndex],FData[Index],SBCharCount*SizeOf(SBChar));
  121. end;
  122. { Public routines for appending }
  123. function TGenericStringBuilder.Append(const AValue: UInt64): TGenericStringBuilder;
  124. begin
  125. DoAppend(IntToStr(AValue));
  126. Result:=self;
  127. end;
  128. function TGenericStringBuilder.Append(const AValue: TSBCharArray): TGenericStringBuilder;
  129. var
  130. I,L: Integer;
  131. begin
  132. I:=-1;
  133. L:=System.Length(AValue);
  134. If L=0 then
  135. Exit(Self);
  136. Repeat
  137. Inc(I);
  138. Until (I>=L) or (AValue[I]=#0);
  139. DoAppend(AValue,0,I);
  140. Result:=Self;
  141. end;
  142. function TGenericStringBuilder.Append(const AValue: Single): TGenericStringBuilder;
  143. begin
  144. DoAppend(FloatToStr(AValue));
  145. Result:=self;
  146. end;
  147. function TGenericStringBuilder.Append(const AValue: Word): TGenericStringBuilder;
  148. begin
  149. Append(IntToStr(AValue));
  150. Result:=self;
  151. end;
  152. function TGenericStringBuilder.Append(const AValue: Cardinal): TGenericStringBuilder;
  153. begin
  154. DoAppend(IntToStr(AValue));
  155. Result:=self;
  156. end;
  157. function TGenericStringBuilder.Append(const AValue: SBChar; RepeatCount: Integer
  158. ): TGenericStringBuilder;
  159. begin
  160. DoAppend(StringOfChar(AValue,RepeatCount));
  161. Result:=Self;
  162. end;
  163. function TGenericStringBuilder.Append(const AValue: Shortint): TGenericStringBuilder;
  164. begin
  165. DoAppend(IntToStr(AValue));
  166. Result:=Self;
  167. end;
  168. function TGenericStringBuilder.Append(const AValue: SBChar): TGenericStringBuilder;
  169. begin
  170. DoAppend(AValue);
  171. Result:=Self;
  172. end;
  173. {$IFDEF SBUNICODE}
  174. function TGenericStringBuilder.Append(const AValue: AnsiChar): TGenericStringBuilder;
  175. begin
  176. DoAppend(WideChar(AValue));
  177. Result:=Self;
  178. end;
  179. {$ELSE}
  180. function TGenericStringBuilder.Append(const AValue: WideChar): TGenericStringBuilder;
  181. begin
  182. // We don't know what the target encoding is ?
  183. DoAppend(AnsiChar(AValue));
  184. Result:=Self;
  185. end;
  186. function TGenericStringBuilder.Append(const AValue: UnicodeString): TGenericStringBuilder;
  187. begin
  188. // We don't know what the target encoding is ?
  189. DoAppend(AnsiString(AValue));
  190. Result:=Self;
  191. end;
  192. {$ENDIF}
  193. function TGenericStringBuilder.Append(const AValue: Currency): TGenericStringBuilder;
  194. begin
  195. DoAppend(CurrToStr(AValue));
  196. Result:=Self;
  197. end;
  198. function TGenericStringBuilder.Append(const AValue: Boolean): TGenericStringBuilder;
  199. begin
  200. DoAppend(BoolToStr(AValue, True));
  201. Result:=Self;
  202. end;
  203. function TGenericStringBuilder.Append(const AValue: Byte): TGenericStringBuilder;
  204. begin
  205. DoAppend(IntToStr(AValue));
  206. Result:=Self;
  207. end;
  208. function TGenericStringBuilder.Append(const AValue: Double): TGenericStringBuilder;
  209. begin
  210. DoAppend(FloatToStr(AValue));
  211. Result:=Self;
  212. end;
  213. function TGenericStringBuilder.Append(const AValue: Int64): TGenericStringBuilder;
  214. begin
  215. DoAppend(IntToStr(AValue));
  216. Result:=Self;
  217. end;
  218. function TGenericStringBuilder.Append(const AValue: TObject): TGenericStringBuilder;
  219. begin
  220. DoAppend(AValue.ToString);
  221. Result:=Self;
  222. end;
  223. function TGenericStringBuilder.Append(const AValue: Smallint): TGenericStringBuilder;
  224. begin
  225. DoAppend(IntToStr(AValue));
  226. Result:=Self;
  227. end;
  228. function TGenericStringBuilder.Append(const AValue: LongInt): TGenericStringBuilder;
  229. begin
  230. DoAppend(IntToStr(AValue));
  231. Result:=Self;
  232. end;
  233. Function TGenericStringBuilder.Append(const AValue: TSBCharArray; StartIndex, SBCharCount: Integer): TGenericStringBuilder;
  234. begin
  235. DoAppend(AValue,StartIndex,SBCharCount);
  236. Result:=Self;
  237. end;
  238. Function TGenericStringBuilder.Append(const AValue: SBString; StartIndex, Count: Integer): TGenericStringBuilder;
  239. begin
  240. CheckRange(StartIndex,Count,System.Length(AValue));
  241. DoAppend(Copy(AValue,StartIndex+1,Count));
  242. Result:=Self;
  243. end;
  244. function TGenericStringBuilder.Append(const AValue: PSBChar): TGenericStringBuilder;
  245. begin
  246. DoAppend(AnsiString(AValue));
  247. Result:=Self;
  248. end;
  249. {$IFDEF SBUNICODE}
  250. function TGenericStringBuilder.Append(const AValue: SBString): TGenericStringBuilder;
  251. begin
  252. DoAppend(AValue);
  253. Result:=Self;
  254. end;
  255. {$ENDIF}
  256. function TGenericStringBuilder.Append(const AValue: RawByteString): TGenericStringBuilder;
  257. begin
  258. {$IFDEF SBUNICODE}
  259. DoAppend(SBString(AValue));
  260. {$ELSE}
  261. DoAppend(AValue);
  262. {$ENDIF}
  263. Result:=Self;
  264. end;
  265. function TGenericStringBuilder.AppendFormat(const Fmt: SBString;
  266. const Args: array of const): TGenericStringBuilder;
  267. begin
  268. DoAppend(Format(Fmt,Args));
  269. Result:=Self;
  270. end;
  271. function TGenericStringBuilder.Append(const Fmt: SBString;
  272. const Args: array of const): TGenericStringBuilder;
  273. begin
  274. DoAppend(Format(Fmt,Args));
  275. Result:=Self;
  276. end;
  277. function TGenericStringBuilder.AppendLine: TGenericStringBuilder;
  278. begin
  279. DoAppend(sLineBreak);
  280. Result:=Self;
  281. end;
  282. function TGenericStringBuilder.AppendLine(const AValue: RawByteString): TGenericStringBuilder;
  283. begin
  284. DoAppend(AValue);
  285. Result:=AppendLine();
  286. end;
  287. procedure TGenericStringBuilder.Clear;
  288. begin
  289. Length:=0;
  290. Capacity:=DefaultCapacity;
  291. end;
  292. procedure TGenericStringBuilder.CopyTo(SourceIndex: Integer;
  293. Var Destination: TSBCharArray; DestinationIndex: Integer; Count: Integer);
  294. begin
  295. CheckNegative(Count,'Count');
  296. CheckNegative(DestinationIndex,'DestinationIndex');
  297. CheckRange(DestinationIndex,Count,System.Length(Destination));
  298. if Count>0 then
  299. begin
  300. CheckRange(SourceIndex,Count,Length);
  301. Move(FData[SourceIndex],Destination[DestinationIndex],Count * SizeOf(SBChar));
  302. end;
  303. end;
  304. function TGenericStringBuilder.EnsureCapacity(aCapacity: Integer): Integer;
  305. begin
  306. CheckRange(aCapacity,0,MaxCapacity);
  307. if Capacity<aCapacity then
  308. Capacity:=aCapacity;
  309. Result:=Capacity;
  310. end;
  311. function TGenericStringBuilder.Equals(StringBuilder: TGenericStringBuilder): Boolean;
  312. begin
  313. Result:=(StringBuilder<>nil);
  314. if Result then
  315. Result:=(Length=StringBuilder.Length)
  316. and (MaxCapacity=StringBuilder.MaxCapacity)
  317. and CompareMem(@FData[0],@StringBuilder.FData[0],Length*SizeOf(SBChar));
  318. end;
  319. procedure TGenericStringBuilder.Grow;
  320. var
  321. NewCapacity: SizeInt;
  322. begin
  323. NewCapacity:=Capacity*2;
  324. if NewCapacity>MaxCapacity then
  325. NewCapacity:=MaxCapacity;
  326. Capacity:=NewCapacity;
  327. end;
  328. function TGenericStringBuilder.Insert(Index: Integer; const AValue: TObject
  329. ): TGenericStringBuilder;
  330. begin
  331. DoInsert(Index,AValue.ToString());
  332. Result:=Self;
  333. end;
  334. function TGenericStringBuilder.Insert(Index: Integer; const AValue: Int64
  335. ): TGenericStringBuilder;
  336. begin
  337. DoInsert(Index,IntToStr(AValue));
  338. Result:=Self;
  339. end;
  340. function TGenericStringBuilder.Insert(Index: Integer; const AValue: Single
  341. ): TGenericStringBuilder;
  342. begin
  343. DoInsert(Index,FloatToStr(AValue));
  344. Result:=Self;
  345. end;
  346. function TGenericStringBuilder.Insert(Index: Integer; const AValue: SBString
  347. ): TGenericStringBuilder;
  348. begin
  349. DoInsert(Index,AValue);
  350. Result:=Self;
  351. end;
  352. function TGenericStringBuilder.Insert(Index: Integer; const AValue: Word
  353. ): TGenericStringBuilder;
  354. begin
  355. DoInsert(Index,IntToStr(AValue));
  356. Result:=Self;
  357. end;
  358. function TGenericStringBuilder.Insert(Index: Integer; const AValue: Shortint
  359. ): TGenericStringBuilder;
  360. begin
  361. DoInsert(Index, IntToStr(AValue));
  362. Result:=Self;
  363. end;
  364. function TGenericStringBuilder.Insert(Index: Integer; const AValue: Currency
  365. ): TGenericStringBuilder;
  366. begin
  367. DoInsert(Index,CurrToStr(AValue));
  368. Result:=Self;
  369. end;
  370. function TGenericStringBuilder.Insert(Index: Integer; const AValue: SBChar
  371. ): TGenericStringBuilder;
  372. begin
  373. DoInsert(Index,AValue);
  374. Result:=Self;
  375. end;
  376. function TGenericStringBuilder.Insert(Index: Integer; const AValue: Byte
  377. ): TGenericStringBuilder;
  378. begin
  379. DoInsert(Index,IntToStr(AValue));
  380. Result:=Self;
  381. end;
  382. function TGenericStringBuilder.Insert(Index: Integer; const AValue: Double
  383. ): TGenericStringBuilder;
  384. begin
  385. DoInsert(Index,FloatToStr(AValue));
  386. Result:=Self;
  387. end;
  388. function TGenericStringBuilder.Insert(Index: Integer; const AValue: LongInt
  389. ): TGenericStringBuilder;
  390. begin
  391. DoInsert(Index,IntToStr(AValue));
  392. Result:=Self;
  393. end;
  394. function TGenericStringBuilder.Insert(Index: Integer; const AValue: Smallint
  395. ): TGenericStringBuilder;
  396. begin
  397. DoInsert(Index,IntToStr(AValue));
  398. Result:=Self;
  399. end;
  400. function TGenericStringBuilder.Insert(Index: Integer; const AValue: Boolean
  401. ): TGenericStringBuilder;
  402. begin
  403. DoInsert(Index,BoolToStr(AValue,True));
  404. Result:=Self;
  405. end;
  406. function TGenericStringBuilder.Insert(Index: Integer; const AValue: SBString;
  407. const aRepeatCount: Integer): TGenericStringBuilder;
  408. var
  409. I: Integer;
  410. begin
  411. for I:=0 to aRepeatCount-1 do
  412. DoInsert(Index,AValue);
  413. Result:=Self;
  414. end;
  415. function TGenericStringBuilder.Insert(Index: Integer; const AValue: TSBCharArray
  416. ): TGenericStringBuilder;
  417. begin
  418. DoInsert(Index,AValue,0,System.Length(AValue));
  419. Result:=Self;
  420. end;
  421. function TGenericStringBuilder.Insert(Index: Integer; const AValue: TSBCharArray;
  422. startIndex: Integer; SBCharCount: Integer): TGenericStringBuilder;
  423. begin
  424. DoInsert(Index,AValue,StartIndex,SBCharCount);
  425. Result:=Self;
  426. end;
  427. function TGenericStringBuilder.Insert(Index: Integer; const AValue: Cardinal
  428. ): TGenericStringBuilder;
  429. begin
  430. DoInsert(Index,IntToStr(AValue));
  431. Result:=self;
  432. end;
  433. function TGenericStringBuilder.Insert(Index: Integer; const AValue: UInt64
  434. ): TGenericStringBuilder;
  435. begin
  436. DoInsert(Index,IntToStr(AValue));
  437. Result:=self;
  438. end;
  439. procedure TGenericStringBuilder.Shrink;
  440. begin
  441. if (Capacity div 4)>=Length then
  442. Capacity:=Capacity div 2;
  443. end;
  444. function TGenericStringBuilder.Remove(StartIndex: Integer; RemLength: Integer
  445. ): TGenericStringBuilder;
  446. Var
  447. MoveIndex : Integer;
  448. begin
  449. if (RemLength=0) then
  450. exit(Self);
  451. CheckNegative(RemLength,'RemLength');
  452. CheckRange(StartIndex,0,Length);
  453. MoveIndex:=StartIndex+RemLength;
  454. CheckRange(MoveIndex,0,Length);
  455. if (Length-Moveindex)>0 then
  456. Move(FData[MoveIndex],FData[StartIndex],(Length-MoveIndex)*SizeOf(SBChar));
  457. Length:=Length-RemLength;
  458. Shrink;
  459. Result:=Self;
  460. end;
  461. Function TGenericStringBuilder.Replace(const OldValue, NewValue: SBRawString; StartIndex, Count: Integer): TGenericStringBuilder;
  462. var
  463. Cur : PSBChar;
  464. CurIndex,MaxIndex : Integer;
  465. OldLen, NewLen, Delta : Integer;
  466. BC : SBChar;
  467. begin
  468. if Count=0 then
  469. Exit(Self);
  470. // Some checks.
  471. CheckNegative(StartIndex,'StartIndex');
  472. CheckNegative(Count,'Count');
  473. CheckRange(Startindex,Count,Length);
  474. // Init
  475. OldLen:=System.Length(OldValue);
  476. NewLen:=System.Length(NewValue);
  477. Delta:=NewLen-OldLen;
  478. MaxIndex:=StartIndex+Count;
  479. CurIndex:=StartIndex;
  480. BC:=OldValue[1];
  481. Cur:=@FData[StartIndex];
  482. // Loop
  483. while (CurIndex<Length-OldLen+1) and (CurIndex<MaxIndex) do
  484. begin
  485. if (Cur^=BC) then
  486. begin
  487. if 0=StrLComp(@FData[CurIndex],PSBChar(OldValue),OldLen) then
  488. begin
  489. // Do actual replace.
  490. DoReplace(CurIndex,OldValue,NewValue);
  491. Inc(CurIndex,NewLen-1);
  492. // DoReplace may have reallocated memory, so changed pointers, reset pointer
  493. Cur:=@FData[CurIndex];
  494. // The max index must be increased/decreased with Delta
  495. // 0123456789012
  496. // 'zzbczzedeafzz' replace('e','qqqq',6,3) -> zzbczzqqqqdqqqqafzz
  497. Inc(MaxIndex,Delta);
  498. end;
  499. end;
  500. Inc(CurIndex);
  501. Inc(Cur);
  502. end;
  503. Result:=Self;
  504. end;
  505. Function TGenericStringBuilder.Replace(const OldChar, NewChar: SBChar; StartIndex,
  506. Count: Integer): TGenericStringBuilder;
  507. var
  508. I : Integer;
  509. Cur : PSBChar;
  510. begin
  511. if Count=0 then
  512. Exit(Self);
  513. CheckNegative(StartIndex,'StartIndex');
  514. CheckNegative(Count,'Count');
  515. CheckRange(StartIndex,Count-1,Length);
  516. Cur:=@FData[StartIndex];
  517. For I:=1 to Count do
  518. begin
  519. if Cur^=OldChar then
  520. Cur^:=NewChar;
  521. Inc(Cur);
  522. end;
  523. Result:=Self;
  524. end;
  525. Function TGenericStringBuilder.Replace(const OldChar, NewChar: SBChar): TGenericStringBuilder;
  526. begin
  527. Result:=Replace(OldChar,NewChar,0,Length);
  528. end;
  529. Function TGenericStringBuilder.Replace(const OldValue, NewValue: SBRawString): TGenericStringBuilder;
  530. begin
  531. Result:=Replace(OldValue,NewValue,0,Length);
  532. end;
  533. procedure TGenericStringBuilder.SetCapacity(AValue: Integer);
  534. begin
  535. if (AValue>FMaxCapacity) then
  536. Raise ERangeError.CreateFmt(SListCapacityError,[AValue]);
  537. if (AValue<Length) then
  538. Raise ERangeError.CreateFmt(SListCapacityError,[AValue]);
  539. System.SetLength(FData,AValue);
  540. end;
  541. {$IFDEF UNICODERTL}
  542. function TGenericStringBuilder.ToString: RTLString;
  543. {$ELSE}
  544. function TGenericStringBuilder.ToString: SBString;
  545. {$ENDIF}
  546. begin
  547. Result:=ToString(0,Length);
  548. end;
  549. function TGenericStringBuilder.ToString(aStartIndex: Integer; aLength: Integer
  550. ): SBString;
  551. begin
  552. if (aLength=0) then
  553. Result:=''
  554. else
  555. begin
  556. CheckNegative(aStartIndex,'aStartIndex');
  557. CheckNegative(aLength,'aLength');
  558. CheckRange(aStartIndex,aLength,Length);
  559. System.SetLength(Result,aLength);
  560. Move(FData[aStartIndex],Result[1],aLength*SizeOf(SBChar));
  561. end;
  562. end;
  563. procedure TGenericStringBuilder.DoReplace(Index: Integer; const Old, New: SBString);
  564. var
  565. NVLen,OVLen,OLen,Delta,TailStart: Integer;
  566. begin
  567. NVLen:=System.Length(New);
  568. OVLen:=System.Length(Old);
  569. Delta:=NVLen-OVLen;
  570. if (Delta<>0) then
  571. begin
  572. OLen:=Length;
  573. if (Delta>0) then
  574. Length:=OLen+Delta;
  575. TailStart:=Index+OVlen;
  576. Move(FData[TailStart],FData[Index+NVLen],(OLen-TailStart)*SizeOf(SBChar));
  577. if (Delta<0) then
  578. Length:=OLen+Delta;
  579. end;
  580. Move(New[1],FData[Index],NVLen*SizeOf(SBChar));
  581. end;