[delphi]
unit DxStringBuilder;
interface
uses RTLConsts,Classes,SysUtils;
type
EExternal = class(Exception)
public
{$IFDEF MSWINDOWS}
ExceptionRecord: PExceptionRecord platform;
{$ENDIF}
{$IF defined(LINUX) or defined(MACOSX)}
ExceptionAddress: LongWord platform;
AccessAddress: LongWord platform;
SignalNumber: Integer platform;
{$IFEND LINUX or MACOSX}
end;
EIntError = class(EExternal);
ERangeError = class(EIntError);
TCharArray = array of Char;
TStringBuilder = class
private
const DefaultCapacity = $10;
function GetCapacity: Integer;
procedure SetCapacity(const Value: Integer);
function GetLength: Integer;
procedure Set_Length(const Value: Integer);
function GetMaxCapacity: Integer;
procedure ReduceCapacity;
procedure ExpandCapacity;
procedure CheckBounds(Index: Integer);
function _WordStr(Index: Integer; const Old, New: string): Boolean;
function GetChars(index: Integer): Char;
procedure SetChars(index: Integer; const Value: Char);
protected
FData: TCharArray;
FLength: Integer;
FMaxCapacity: Integer;
public
constructor Create; overload;
constructor Create(aCapacity: Integer); overload;
constructor Create(const Value: string); overload;
function Append(const Value: Boolean): TStringBuilder; overload;
function Append(const Value: Byte): TStringBuilder; overload;
function Append(const Value: Char): TStringBuilder; overload;
function Append(const Value: Currency): TStringBuilder; overload;
function Append(const Value: Double): TStringBuilder; overload;
function Append(const Value: Smallint): TStringBuilder; overload;
function Append(const Value: Integer): TStringBuilder; overload;
function Append(const Value: Int64): TStringBuilder; overload;
function Append(const Value: TObject): TStringBuilder; overload;
function Append(const Value: Shortint): TStringBuilder; overload;
function Append(const Value: Single): TStringBuilder; overload;
function Append(const Value: string): TStringBuilder; overload;
function Append(const Value: UInt64): TStringBuilder; overload;
function Append(const Value: TCharArray): TStringBuilder; overload;
function Append(const Value: Word): TStringBuilder; overload;
function Append(const Value: Cardinal): TStringBuilder; overload;
function Append(const Value: Char; RepeatCount: Integer): TStringBuilder; overload;