syssbh.inc 5.8 KB

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