| 1 | unit UObjectString;
|
|---|
| 2 |
|
|---|
| 3 | interface
|
|---|
| 4 |
|
|---|
| 5 | uses
|
|---|
| 6 | SysUtils, UObjectTypeBase, UObjectBoolean, UObjectInteger, StrUtils;
|
|---|
| 7 |
|
|---|
| 8 | type
|
|---|
| 9 | TString = class(TInterfacedObject, IAssignable, IComparable)
|
|---|
| 10 | Value: string;
|
|---|
| 11 | procedure Assign(Source: TInterfacedObject);
|
|---|
| 12 | function EqualTo(Operand: IComparable): TBoolean;
|
|---|
| 13 | function HigherThen(Operand: TInterfacedObject): TBoolean;
|
|---|
| 14 | function LowerThan(Operand: TInterfacedObject): TBoolean;
|
|---|
| 15 | function Length: TInteger;
|
|---|
| 16 | procedure UpperCase;
|
|---|
| 17 | procedure LowerCase;
|
|---|
| 18 | procedure Delete(Index: TInteger; Count: TInteger);
|
|---|
| 19 | procedure Insert(Index: TInteger; SubString: TString);
|
|---|
| 20 | function Pos(SubString: TString): TInteger;
|
|---|
| 21 | procedure Reverse;
|
|---|
| 22 | function LeftString(Count: TInteger): TString;
|
|---|
| 23 | function RightString(Count: TInteger): TString;
|
|---|
| 24 | end;
|
|---|
| 25 |
|
|---|
| 26 | implementation
|
|---|
| 27 |
|
|---|
| 28 | { TString }
|
|---|
| 29 |
|
|---|
| 30 | procedure TString.Assign(Source: TInterfacedObject);
|
|---|
| 31 | begin
|
|---|
| 32 |
|
|---|
| 33 | end;
|
|---|
| 34 |
|
|---|
| 35 | procedure TString.Delete(Index, Count: TInteger);
|
|---|
| 36 | begin
|
|---|
| 37 | System.Delete(Value, Index.Value, Count.Value);
|
|---|
| 38 | end;
|
|---|
| 39 |
|
|---|
| 40 | function TString.EqualTo(Operand: IComparable): TBoolean;
|
|---|
| 41 | begin
|
|---|
| 42 | if TInterfacedObject(Operand) is TString then begin
|
|---|
| 43 | Result := TBoolean.Create;
|
|---|
| 44 | Result.Value := Value = TString(Operand).Value;
|
|---|
| 45 | end else raise EInvalidCast.Create('Typecast error.');
|
|---|
| 46 | end;
|
|---|
| 47 |
|
|---|
| 48 | function TString.HigherThen(Operand: TInterfacedObject): TBoolean;
|
|---|
| 49 | begin
|
|---|
| 50 |
|
|---|
| 51 | end;
|
|---|
| 52 |
|
|---|
| 53 | procedure TString.Insert(Index: TInteger; SubString: TString);
|
|---|
| 54 | begin
|
|---|
| 55 | System.Insert(SubString.Value, Value, Index.Value);
|
|---|
| 56 | end;
|
|---|
| 57 |
|
|---|
| 58 | function TString.LeftString(Count: TInteger): TString;
|
|---|
| 59 | begin
|
|---|
| 60 | Result := TString.Create;
|
|---|
| 61 | Result.Value := StrUtils.LeftStr(Value, Count.Value);
|
|---|
| 62 | end;
|
|---|
| 63 |
|
|---|
| 64 | function TString.Length: TInteger;
|
|---|
| 65 | begin
|
|---|
| 66 | Result.Value := System.Length(Value);
|
|---|
| 67 | end;
|
|---|
| 68 |
|
|---|
| 69 | procedure TString.LowerCase;
|
|---|
| 70 | begin
|
|---|
| 71 | Value := SysUtils.LowerCase(Value);
|
|---|
| 72 | end;
|
|---|
| 73 |
|
|---|
| 74 | function TString.LowerThan(Operand: TInterfacedObject): TBoolean;
|
|---|
| 75 | begin
|
|---|
| 76 |
|
|---|
| 77 | end;
|
|---|
| 78 |
|
|---|
| 79 | function TString.Pos(SubString: TString): TInteger;
|
|---|
| 80 | begin
|
|---|
| 81 | Result := TInteger.Create;
|
|---|
| 82 | Result.Value := System.Pos(SubString.Value, Value);
|
|---|
| 83 | end;
|
|---|
| 84 |
|
|---|
| 85 | procedure TString.Reverse;
|
|---|
| 86 | begin
|
|---|
| 87 | Value := StrUtils.ReverseString(Value);
|
|---|
| 88 | end;
|
|---|
| 89 |
|
|---|
| 90 | function TString.RightString(Count: TInteger): TString;
|
|---|
| 91 | begin
|
|---|
| 92 | Result := TString.Create;
|
|---|
| 93 | Result.Value := StrUtils.RightStr(Value, Count.Value);
|
|---|
| 94 | end;
|
|---|
| 95 |
|
|---|
| 96 | procedure TString.UpperCase;
|
|---|
| 97 | begin
|
|---|
| 98 | Value := SysUtils.UpperCase(Value);
|
|---|
| 99 | end;
|
|---|
| 100 |
|
|---|
| 101 |
|
|---|
| 102 | end.
|
|---|