Changeset 105


Ignore:
Timestamp:
Apr 5, 2007, 8:34:33 PM (18 years ago)
Author:
RBRi
Message:

%more stringutils refactoring

Location:
trunk/NewView
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/NewView/FileDialogForm.pas

    r97 r105  
    123123  PmWin,
    124124  SysUtils,
    125   ACLStringUtility,
    126125  FileUtilsUnit,
    127126  ACLDialogs,
     
    131130  SettingsUnit,
    132131  HelpFile,
     132  StringUtilsUnit,
    133133  DebugUnit;
    134134
     
    286286  filename: string;
    287287  ShowList: boolean;
    288   NameAndTitle: string;
     288  tmpNameAndTitle: string;
    289289Begin
    290290  CompletionsListBox.Items.Clear;
     
    295295    for i := 0 to FileListBox.Items.Count - 1 do
    296296    begin
    297       NameAndTitle := FileListBox.Items[ i ];
    298       Filename := ExtractNextValue( NameAndTitle, #9 );
    299 
    300       if StrStarts( search, filename ) then
     297      tmpNameAndTitle := FileListBox.Items[ i ];
     298      Filename := StrLeftUntil(tmpNameAndTitle, [StrTAB]);
     299
     300      if StrStartsWithIgnoringCase(filename, search) then
    301301        CompletionsListBox.Items.Add( filename );
    302302    end;
     
    306306  if CompletionsListBox.Items.Count = 1 then
    307307  begin
    308     if not StringsSame( CompletionsListBox.Items[ 0 ], search ) then
     308    if not StrEqualIgnoringCase(CompletionsListBox.Items[0], search) then
    309309      ShowList := true;
    310310  end
     
    436436    begin
    437437      NameAndTitle := FileListBox.Items[ FileIndex ];
    438       FileNames.Add( ExtractNextValue( NameAndTitle, #9 ) );
     438      FileNames.Add(StrLeftUntil(NameAndTitle, [StrTAB]));
    439439    end;
    440440  end;
     
    471471    begin
    472472      DoErrorDlg( InvalidFilterErrorTitle,
    473                   StrDoubleQuote( FileNameText )
     473                  StrInDoubleQuotes(FileNameText)
    474474                  + InvalidFilterError
    475                   + EndLine
     475                  + StrCRLF
    476476                  + '  \ / :' );
    477477      exit;
     
    611611                               + Filename );
    612612
    613     FileListBox.Items.Add( Filename
    614                            + #9
    615                            + Title );
     613    FileListBox.Items.Add(Filename + StrTAB + Title );
    616614  end;
    617615  FileListBox.Items.EndUpdate;
  • trunk/NewView/NavigatePointUnit.pas

    r33 r105  
    4848  SysUtils,
    4949  ACLUtility,
    50   ACLStringUtility;
     50  StringUtilsUnit,
     51  DebugUnit;
    5152
    5253procedure SaveWindowList( Var F: TextFile;
     
    167168constructor TSavedHelpWindow.Load( Var F: TextFile );
    168169var
    169   s: string;
     170  tmpString : string;
    170171  TopicIndex: integer;
     172  tmpParts : TStringList;
    171173begin
    172174  inherited Create;
     
    174176  Rect:= THelpWindowRect.Create;
    175177
    176   ReadLn( F, S );
     178  ReadLn( F, tmpString);
     179  tmpParts := TStringList.Create;
     180  StrExtractStrings(tmpParts, tmpString, [','], #0);
    177181
    178   TopicIndex   := StrToInt( ExtractNextValue( S, ',' ) );
     182  TopicIndex   := StrToInt(tmpParts[0]);
    179183  Topic := HelpFile.Topics[ TopicIndex ];
    180   Group        := StrToInt( ExtractNextValue( S, ',' ) );
    181   Rect.Left    := StrToInt( ExtractNextValue( S, ',' ) );
    182   Rect.Bottom  := StrToInt( ExtractNextValue( S, ',' ) );
    183   Rect.Width   := StrToInt( ExtractNextValue( S, ',' ) );
    184   Rect.Height  := StrToInt( ExtractNextValue( S, ',' ) );
    185   TopCharIndex := StrToInt( ExtractNextValue( S, ',' ) );
     184  Group        := StrToInt(tmpParts[1]);
     185  Rect.Left    := StrToInt(tmpParts[2]);
     186  Rect.Bottom  := StrToInt(tmpParts[3]);
     187  Rect.Width   := StrToInt(tmpParts[4]);
     188  Rect.Height  := StrToInt(tmpParts[5]);
     189  TopCharIndex := StrToInt(tmpParts[6]);
     190
     191  tmpParts.Destroy;
    186192
    187193  LoadWindowList( F, ChildWindows, HelpFile );
  • trunk/NewView/StringUtilsUnit.pas

    r102 r105  
    1313
    1414const
     15  StrTAB = chr(9);
    1516  StrCR = chr(13);
    1617  StrLF = chr(10);
     
    7677  Function StrLeftUntil(const aReceiver: String; const aSetOfChars: TSetOfChars) : String;
    7778
    78   // returns true if the String starts with the provides one
     79  // returns true if the String starts with the provided one
    7980  // this is case SENSITIVE
    8081  Function StrStartsWith(const aReceiver: String; const aStartString: String): Boolean;
    8182
    82   // returns true if the String starts with the provides one
     83  // returns true if the String starts with the provided one
    8384  // this is case INsensitive
    8485  Function StrStartsWithIgnoringCase(const aReceiver: String; const aStartString: String): Boolean;
     
    8889  Function StrEndsWith(const aReceiver: String; const anEndString: String): Boolean;
    8990
    90   // returns true if the String ends with the provides one
     91  // returns true if the String ends with the provided one
    9192  // this is case INsensitive
    9293  Function StrEndsWithIgnoringCase(const aReceiver: String; const anEndString: String): Boolean;
     94
     95  // returns true if the Strings are the same
     96  // this is case INsensitive
     97  Function StrEqualIgnoringCase(const aReceiver: String; const aSecondString: String): Boolean;
    9398
    9499  // the IntToStr generates wrong results
     
    106111
    107112  uses
     113    SysUtils,
    108114    DebugUnit;
    109115
     
    502508
    503509
     510  Function StrEqualIgnoringCase(const aReceiver: String; const aSecondString: String): Boolean;
     511  begin
     512    Result := CompareText(aReceiver, aSecondString) = 0;
     513  end;
     514
     515
    504516  Function LongWordToStr(const aLongWord: LongWord) : String;
    505517  Var
  • trunk/NewView/unittests/StringUtilsUnitTests.pas

    r102 r105  
    410410  END;
    411411
     412  PROCEDURE testStrExtractStrings_DelimiterSameAsEscapeChar;
     413  VAR
     414    tmpResult : TStringList;
     415  BEGIN
     416    tmpResult := TStringList.Create;
     417    StrExtractStrings(tmpResult, 'a;b;;cd;;;', [';'], ';');
     418
     419    assertEqualsInt('testStrExtractStrings_EscapedEscapeChar', 3, tmpResult.count);
     420    assertEqualsString('testStrExtractStrings_EscapedEscapeChar', 'a', tmpResult[0]);
     421    assertEqualsString('testStrExtractStrings_EscapedEscapeChar', 'b;cd;', tmpResult[1]);
     422    assertEqualsString('testStrExtractStrings_EscapedEscapeChar', '', tmpResult[2]);
     423
     424    tmpResult.Destroy;
     425  END;
    412426
    413427  // ------------------------------------------------------
     
    12671281
    12681282
     1283  // ----------------------------------------------------------
     1284
     1285
     1286  PROCEDURE testStrEqualIgnoringCase_BothEmpty;
     1287  VAR
     1288    tmpResult : Boolean;
     1289  BEGIN
     1290    tmpResult := StrEqualIgnoringCase('', '');
     1291
     1292    assertTrue('testStrEqualIgnoringCase_BothEmpty', tmpResult);
     1293  END;
     1294
     1295
     1296  PROCEDURE testStrEqualIgnoringCase_FirstEmpty;
     1297  VAR
     1298    tmpResult : Boolean;
     1299  BEGIN
     1300    tmpResult := StrEqualIgnoringCase('', 'xy');
     1301
     1302    assertFalse('testStrEqualIgnoringCase_FirstEmpty', tmpResult);
     1303  END;
     1304
     1305  PROCEDURE testStrEqualIgnoringCase_SecondEmpty;
     1306  VAR
     1307    tmpResult : Boolean;
     1308  BEGIN
     1309    tmpResult := StrEqualIgnoringCase('xy', '');
     1310
     1311    assertFalse('testStrEqualIgnoringCase_SecondEmpty', tmpResult);
     1312  END;
     1313
     1314  PROCEDURE testStrEqualIgnoringCase_DifferentLength;
     1315  VAR
     1316    tmpResult : Boolean;
     1317  BEGIN
     1318    tmpResult := StrEqualIgnoringCase('xy', 'xyz');
     1319
     1320    assertFalse('testStrEqualIgnoringCase_DifferentLength', tmpResult);
     1321  END;
     1322
     1323  PROCEDURE testStrEqualIgnoringCase_DifferentCase;
     1324  VAR
     1325    tmpResult : Boolean;
     1326  BEGIN
     1327    tmpResult := StrEqualIgnoringCase('xYz', 'xyz');
     1328
     1329    assertTrue('testStrEqualIgnoringCase_DifferentCase', tmpResult);
     1330  END;
     1331
     1332  PROCEDURE testStrEqualIgnoringCase;
     1333  VAR
     1334    tmpResult : Boolean;
     1335  BEGIN
     1336    tmpResult := StrEqualIgnoringCase('XYz', 'XYz');
     1337
     1338    assertTrue('testStrEqualIgnoringCase', tmpResult);
     1339  END;
     1340
     1341  // ----------------------------------------------------------
     1342
     1343
    12691344  PROCEDURE testLongWordToStr_Zero;
    12701345  VAR
     
    12961371
    12971372
     1373  // ----------------------------------------------------------
     1374
    12981375
    12991376  PROCEDURE testBoolToStr_true;
     
    13151392    assertEqualsString('testBoolToStr_false', 'False', tmpResult);
    13161393  END;
     1394
    13171395
    13181396  // ----------------------------------------------------------
     
    13751453    result.add(@testStrExtractStrings_EscapedDelimiter);
    13761454    result.add(@testStrExtractStrings_EscapedEscapeChar);
     1455    result.add(@testStrExtractStrings_DelimiterSameAsEscapeChar);
    13771456
    13781457    result.add(@testStrExtractStringsIgnoreEmpty_EmptyReceiver);
     
    14671546    result.add(@testStrEndsWithIgnoringCase_StringMatchCaseInSensitive);
    14681547
     1548    result.add(@testStrEqualIgnoringCase_BothEmpty);
     1549    result.add(@testStrEqualIgnoringCase_FirstEmpty);
     1550    result.add(@testStrEqualIgnoringCase_SecondEmpty);
     1551    result.add(@testStrEqualIgnoringCase_DifferentLength);
     1552    result.add(@testStrEqualIgnoringCase_DifferentCase);
     1553    result.add(@testStrEqualIgnoringCase);
     1554
    14691555    result.add(@testLongWordToStr_Zero);
    14701556    result.add(@testLongWordToStr_Four);
Note: See TracChangeset for help on using the changeset viewer.