Ignore:
Timestamp:
Apr 30, 2007, 9:00:32 PM (18 years ago)
Author:
RBRi
Message:

more refactoring

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/NewView/StringUtilsUnit.pas

    r123 r139  
    1818  StrLF = CharLF;
    1919  StrCRLF = StrCR + StrLF;
    20   StrSingleQuote = '''';
    21   StrDoubleQuote = '"';
     20  StrSingleQuote = CharSingleQuote;
     21  StrDoubleQuote = CharDoubleQuote;
    2222
    2323
     
    3737  end;
    3838
    39   // prefices all occurences of one of the chars in aStringWithChars with anEscape char
     39  // prefixes all occurences of one of the chars in aStringWithChars with anEscape char
    4040  // if the escapeChar itself is found, then it is doubled
    4141  Function StrEscapeAllCharsBy(const aReceiver: String; const aSetOfChars: TSetOfChars; const anEscapeChar: char): String;
     
    9494  Function StrEndsWithIgnoringCase(const aReceiver: String; const anEndString: String): Boolean;
    9595
     96  // Returns true if aReceiver is only spaces (or empty)
     97  Function StrIsEmptyOrSpaces(const aReceiver: String) : Boolean;
     98
    9699  // returns true if the Strings are the same
    97100  // this is case INsensitive
     
    105108  Function BoolToStr(const aBoolean : boolean ): string;
    106109
     110  // Returns aString enclosed in single quotes
     111  Function StrInSingleQuotes(const aString : String) : String;
     112
    107113  // Returns aString enclosed in double quotes
    108114  Function StrInDoubleQuotes(const aString : String) : String;
     
    117123  Function CaseInsensitivePos(const aPart: String; const aString: String ): longint;
    118124
     125  // Finds the last position of aChar within aString. Returns zero if no match
     126  Function LastPosOfChar(const aChar: char; const aString: String): longint;
     127
    119128
    120129  // --------------------
     
    122131  // --------------------
    123132
    124  
     133
    125134  // removes all occurences of char from aSetOfChars from the beginning
    126135  // of a String.
     
    139148
    140149
     150  // --------------------
     151  // ---- Misc TODO  ----
     152  // --------------------
     153
     154  Procedure GetMemString(const aPointer : pointer; var aString: string; const aSize: byte);
     155
     156  Procedure FreePString(var aPString: PString );
     157
     158  Function NewPString(const aString : String) : PString;
    141159
    142160
     
    145163  uses
    146164    SysUtils,
    147     DebugUnit;
     165    DebugUnit,
     166    ACLUtility;  // TODO
    148167
    149168  constructor TSerializableStringList.Create;
     
    568587
    569588
     589  Function StrIsEmptyOrSpaces(const aReceiver: String) : Boolean;
     590  Begin
     591    Asm
     592      MOV ESI, aReceiver   // get address of aReceiver into ESI
     593      MOV CL,[ESI]     // get length of s
     594      MOVZX ECX, CL      // widen CL
     595      INC ECX
     596
     597    !IsSpacesLoop:
     598      INC ESI   // move to next char
     599      DEC ECX
     600      JE !IsSpacesTrue
     601
     602      MOV AL,[ESI] // load character
     603      CMP AL,32  // is it a space?
     604      JE !IsSpacesLoop // yes, go to next
     605
     606      // no, return false
     607      MOV EAX, 0
     608      JMP !IsSpacesDone
     609
     610    !IsSpacesTrue:
     611      MOV EAX, 1
     612
     613    !IsSpacesDone:
     614      LEAVE
     615      RETN32 4
     616    End;
     617  End;
     618
     619
    570620  Function StrEqualIgnoringCase(const aReceiver: String; const aSecondString: String): Boolean;
    571621  begin
     
    618668
    619669
     670  Function StrInSingleQuotes(const aString : String) : String;
     671  begin
     672    Result := StrSingleQuote + aString + StrSingleQuote;
     673  end;
     674
     675
    620676  Function StrInDoubleQuotes(const aString : String) : String;
    621677  begin
     
    866922
    867923
     924  Function LastPosOfChar(const aChar: char; const aString: String): longint;
     925  Var
     926    tmpPos : longint;
     927  begin
     928    tmpPos := Length(aString);
     929    while tmpPos > 0 do
     930    begin
     931      if aString[tmpPos] = aChar then
     932      begin
     933        Result := tmpPos;
     934        exit;
     935      end;
     936      dec(tmpPos);
     937    end;
     938    Result := 0;
     939  end;
     940
    868941  // --------------------
    869942  // ---- AnsiString ----
     
    9941067
    9951068
     1069  // --------------------
     1070  // ---- Misc TODO  ----
     1071  // --------------------
     1072
     1073  Procedure GetMemString(const aPointer : pointer; var aString: string; const aSize: byte);
     1074  begin
     1075    aString[0] := char(aSize);
     1076    MemCopy(aPointer, Addr(aString[1]), aSize);
     1077  end;
     1078
     1079
     1080  Procedure FreePString(var aPString : PString );
     1081  begin
     1082    if aPString = nil then
     1083    begin
     1084      exit;
     1085    end;
     1086
     1087    FreeMem(aPString, Length(aPString^) + 1);
     1088    aPString := nil;
     1089  end;
     1090
     1091
     1092  Function NewPString(const aString : String) : PString;
     1093  begin
     1094    GetMem(Result, Length(aString) + 1);
     1095    Result^ := aString;
     1096  end;
     1097
    9961098END.
Note: See TracChangeset for help on using the changeset viewer.