2
0

syssbh.inc 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. {%MainUnit sysutils.pp}
  2. { TGenericStringBuilder }
  3. TGenericStringBuilder = class
  4. private
  5. const
  6. DefaultCapacity = 64;
  7. private
  8. Function GetCapacity: Integer;
  9. Procedure SetCapacity(AValue: Integer);
  10. Function GetC(Index: Integer): SBChar;
  11. Procedure SetC(Index: Integer; AValue: SBChar);
  12. Function GetLength: Integer; inline;
  13. Procedure SetLength(AValue: Integer);
  14. protected
  15. FData: TSBCharArray;
  16. FLength: Integer;
  17. FMaxCapacity: Integer;
  18. // Raise error on range check.
  19. Procedure CheckRange(Idx,Count,MaxLen : Integer);inline;
  20. Procedure CheckNegative(Const AValue : Integer; Const AName: SBString); inline;
  21. // All appends/inserts pass through here.
  22. Procedure DoAppend(Const S : {$IFDEF SBUNICODE}SBString{$ELSE}RawByteString{$ENDIF});virtual;
  23. Procedure DoAppend(const AValue: TSBCharArray; Idx, aCount: Integer); virtual;
  24. Procedure DoInsert(Index: Integer; const AValue: SBString); virtual;
  25. Procedure DoInsert(Index: Integer; const AValue: TSBCharArray; StartIndex, SBCharCount: Integer); virtual;
  26. Procedure DoReplace(Index: Integer; const Old, New: SBString); virtual;
  27. Procedure Grow;
  28. Procedure Shrink;
  29. public
  30. Constructor Create;
  31. Constructor Create(aCapacity: Integer);
  32. Constructor Create(const AValue: SBString);
  33. Constructor Create(aCapacity: Integer; aMaxCapacity: Integer);
  34. Constructor Create(const AValue: SBString; aCapacity: Integer);
  35. Constructor Create(const AValue: SBString; StartIndex: Integer; aLength: Integer; aCapacity: Integer);
  36. Function Append(const AValue: Boolean): TGenericStringBuilder;
  37. Function Append(const AValue: Byte): TGenericStringBuilder;
  38. Function Append(const AValue: SBChar): TGenericStringBuilder;
  39. Function Append(const AValue: Currency): TGenericStringBuilder;
  40. Function Append(const AValue: Double): TGenericStringBuilder;
  41. Function Append(const AValue: Smallint): TGenericStringBuilder;
  42. Function Append(const AValue: LongInt): TGenericStringBuilder;
  43. Function Append(const AValue: Int64): TGenericStringBuilder;
  44. Function Append(const AValue: TObject): TGenericStringBuilder;
  45. Function Append(const AValue: Shortint): TGenericStringBuilder;
  46. Function Append(const AValue: Single): TGenericStringBuilder;
  47. Function Append(const AValue: UInt64): TGenericStringBuilder;
  48. Function Append(const AValue: TSBCharArray): TGenericStringBuilder;
  49. Function Append(const AValue: Word): TGenericStringBuilder;
  50. Function Append(const AValue: Cardinal): TGenericStringBuilder;
  51. Function Append(const AValue: PSBChar): TGenericStringBuilder;
  52. {$IFDEF SBUNICODE}
  53. // Do not use SBRawstring, we need 2 versions in case of unicode
  54. Function Append(const AValue: SBString): TGenericStringBuilder;
  55. Function Append(const AValue: AnsiChar): TGenericStringBuilder;
  56. {$ELSE}
  57. Function Append(const AValue: UnicodeString): TGenericStringBuilder;
  58. Function Append(const AValue: UnicodeChar): TGenericStringBuilder;
  59. {$ENDIF}
  60. Function Append(const AValue: RawByteString): TGenericStringBuilder;
  61. Function Append(const AValue: SBChar; RepeatCount: Integer): TGenericStringBuilder;
  62. Function Append(const AValue: TSBCharArray; StartIndex: Integer; SBCharCount: Integer): TGenericStringBuilder;
  63. Function Append(const AValue: SBString; StartIndex: Integer; Count: Integer): TGenericStringBuilder;
  64. Function Append(const Fmt: SBString; const Args: array of const): TGenericStringBuilder;
  65. Function AppendFormat(const Fmt: SBString; const Args: array of const): TGenericStringBuilder;
  66. Function AppendLine: TGenericStringBuilder;
  67. Function AppendLine(const AValue: RawByteString): TGenericStringBuilder;
  68. Procedure Clear;
  69. Procedure CopyTo(SourceIndex: Integer; Var Destination: TSBCharArray; DestinationIndex: Integer; Count: Integer);
  70. Function EnsureCapacity(aCapacity: Integer): Integer;
  71. Function Equals(StringBuilder: TGenericStringBuilder): Boolean; reintroduce;
  72. Function Insert(Index: Integer; const AValue: Boolean): TGenericStringBuilder;
  73. Function Insert(Index: Integer; const AValue: Byte): TGenericStringBuilder;
  74. Function Insert(Index: Integer; const AValue: SBChar): TGenericStringBuilder;
  75. Function Insert(Index: Integer; const AValue: Currency): TGenericStringBuilder;
  76. Function Insert(Index: Integer; const AValue: Double): TGenericStringBuilder;
  77. Function Insert(Index: Integer; const AValue: Smallint): TGenericStringBuilder;
  78. Function Insert(Index: Integer; const AValue: LongInt): TGenericStringBuilder;
  79. Function Insert(Index: Integer; const AValue: TSBCharArray): TGenericStringBuilder;
  80. Function Insert(Index: Integer; const AValue: Int64): TGenericStringBuilder;
  81. Function Insert(Index: Integer; const AValue: TObject): TGenericStringBuilder;
  82. Function Insert(Index: Integer; const AValue: Shortint): TGenericStringBuilder;
  83. Function Insert(Index: Integer; const AValue: Single): TGenericStringBuilder;
  84. Function Insert(Index: Integer; const AValue: SBString): TGenericStringBuilder;
  85. Function Insert(Index: Integer; const AValue: Word): TGenericStringBuilder;
  86. Function Insert(Index: Integer; const AValue: Cardinal): TGenericStringBuilder;
  87. Function Insert(Index: Integer; const AValue: UInt64): TGenericStringBuilder;
  88. Function Insert(Index: Integer; const AValue: SBString; const aRepeatCount: Integer): TGenericStringBuilder;
  89. Function Insert(Index: Integer; const AValue: TSBCharArray; startIndex: Integer; SBCharCount: Integer): TGenericStringBuilder;
  90. Function Remove(StartIndex: Integer; RemLength: Integer): TGenericStringBuilder;
  91. Function Replace(const OldChar, NewChar: SBChar): TGenericStringBuilder;
  92. Function Replace(const OldChar, NewChar: SBChar; StartIndex: Integer; Count: Integer): TGenericStringBuilder;
  93. Function Replace(const OldValue, NewValue: SBRawString): TGenericStringBuilder;
  94. Function Replace(const OldValue, NewValue: SBRawString; StartIndex: Integer; Count: Integer): TGenericStringBuilder;
  95. {$IFDEF UNICODERTL}
  96. Function ToString: RTLString; override;
  97. {$ELSE}
  98. Function ToString: SBString; {$IFNDEF SBUNICODE} override; {$ELSE} reintroduce; {$ENDIF}
  99. {$ENDIF}
  100. Function ToString(aStartIndex: Integer; aLength: Integer): SBString; reintroduce;
  101. property Chars[index: Integer]: SBChar read GetC write SetC; default;
  102. property Length: Integer read GetLength write SetLength;
  103. property Capacity: Integer read GetCapacity write SetCapacity;
  104. property MaxCapacity: Integer read FMaxCapacity;
  105. end;