2
0

syssbh.inc 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. { TGenericStringBuilder }
  2. TGenericStringBuilder = 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): TGenericStringBuilder;
  36. Function Append(const AValue: Byte): TGenericStringBuilder;
  37. Function Append(const AValue: SBChar): TGenericStringBuilder;
  38. Function Append(const AValue: Currency): TGenericStringBuilder;
  39. Function Append(const AValue: Double): TGenericStringBuilder;
  40. Function Append(const AValue: Smallint): TGenericStringBuilder;
  41. Function Append(const AValue: LongInt): TGenericStringBuilder;
  42. Function Append(const AValue: Int64): TGenericStringBuilder;
  43. Function Append(const AValue: TObject): TGenericStringBuilder;
  44. Function Append(const AValue: Shortint): TGenericStringBuilder;
  45. Function Append(const AValue: Single): TGenericStringBuilder;
  46. Function Append(const AValue: UInt64): TGenericStringBuilder;
  47. Function Append(const AValue: TSBCharArray): TGenericStringBuilder;
  48. Function Append(const AValue: Word): TGenericStringBuilder;
  49. Function Append(const AValue: Cardinal): TGenericStringBuilder;
  50. Function Append(const AValue: PSBChar): TGenericStringBuilder;
  51. {$IFDEF SBUNICODE}
  52. // Do not use SBRawstring, we need 2 versions in case of unicode
  53. Function Append(const AValue: SBString): TGenericStringBuilder;
  54. {$ENDIF}
  55. Function Append(const AValue: RawByteString): TGenericStringBuilder;
  56. Function Append(const AValue: SBChar; RepeatCount: Integer): TGenericStringBuilder;
  57. Function Append(const AValue: TSBCharArray; StartIndex: Integer; SBCharCount: Integer): TGenericStringBuilder;
  58. Function Append(const AValue: SBString; StartIndex: Integer; Count: Integer): TGenericStringBuilder;
  59. Function Append(const Fmt: SBString; const Args: array of const): TGenericStringBuilder;
  60. Function AppendFormat(const Fmt: SBString; const Args: array of const): TGenericStringBuilder;
  61. Function AppendLine: TGenericStringBuilder;
  62. Function AppendLine(const AValue: RawByteString): TGenericStringBuilder;
  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: TGenericStringBuilder): Boolean; reintroduce;
  67. Function Insert(Index: Integer; const AValue: Boolean): TGenericStringBuilder;
  68. Function Insert(Index: Integer; const AValue: Byte): TGenericStringBuilder;
  69. Function Insert(Index: Integer; const AValue: SBChar): TGenericStringBuilder;
  70. Function Insert(Index: Integer; const AValue: Currency): TGenericStringBuilder;
  71. Function Insert(Index: Integer; const AValue: Double): TGenericStringBuilder;
  72. Function Insert(Index: Integer; const AValue: Smallint): TGenericStringBuilder;
  73. Function Insert(Index: Integer; const AValue: LongInt): TGenericStringBuilder;
  74. Function Insert(Index: Integer; const AValue: TSBCharArray): TGenericStringBuilder;
  75. Function Insert(Index: Integer; const AValue: Int64): TGenericStringBuilder;
  76. Function Insert(Index: Integer; const AValue: TObject): TGenericStringBuilder;
  77. Function Insert(Index: Integer; const AValue: Shortint): TGenericStringBuilder;
  78. Function Insert(Index: Integer; const AValue: Single): TGenericStringBuilder;
  79. Function Insert(Index: Integer; const AValue: SBString): TGenericStringBuilder;
  80. Function Insert(Index: Integer; const AValue: Word): TGenericStringBuilder;
  81. Function Insert(Index: Integer; const AValue: Cardinal): TGenericStringBuilder;
  82. Function Insert(Index: Integer; const AValue: UInt64): TGenericStringBuilder;
  83. Function Insert(Index: Integer; const AValue: SBString; const aRepeatCount: Integer): TGenericStringBuilder;
  84. Function Insert(Index: Integer; const AValue: TSBCharArray; startIndex: Integer; SBCharCount: Integer): TGenericStringBuilder;
  85. Function Remove(StartIndex: Integer; RemLength: Integer): TGenericStringBuilder;
  86. Function Replace(const OldChar, NewChar: SBChar): TGenericStringBuilder;
  87. Function Replace(const OldChar, NewChar: SBChar; StartIndex: Integer; Count: Integer): TGenericStringBuilder;
  88. Function Replace(const OldValue, NewValue: SBRawString): TGenericStringBuilder;
  89. Function Replace(const OldValue, NewValue: SBRawString; StartIndex: Integer; Count: Integer): TGenericStringBuilder;
  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;