From 03ca9c92f4ea7e6606865132a5d2e0bb065f384d Mon Sep 17 00:00:00 2001 From: "rosenfield.albert" Date: Tue, 17 Jun 2008 12:44:17 +0000 Subject: [PATCH] Kill all users of StrUtils. --- source/helpers.pas | 19 +++++++++++++------ source/main.pas | 22 +++++++++++----------- 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/source/helpers.pas b/source/helpers.pas index 9a100bc4..0a4436bd 100644 --- a/source/helpers.pas +++ b/source/helpers.pas @@ -10,7 +10,7 @@ interface uses Classes, SysUtils, Graphics, db, clipbrd, dialogs, forms, controls, ShellApi, checklst, windows, ZDataset, ZAbstractDataset, - shlobj, ActiveX, StrUtils, WideStrUtils, VirtualTrees, SynRegExpr, Messages, WideStrings; + shlobj, ActiveX, WideStrUtils, VirtualTrees, SynRegExpr, Messages, WideStrings; type @@ -80,7 +80,7 @@ type function getFirstWord( text: String ): String; function ConvertWindowsCodepageToMysqlCharacterSet(codepage: Cardinal): string; function GetFieldValue( Field: TField ): String; - function LastPos( substr: WideString; str: WideString): Integer; + function LastPos(needle: WideChar; haystack: WideString): Integer; function ConvertServerVersion( Version: Integer ): String; function FormatByteNumber( Bytes: Int64; Decimals: Byte = 1 ): String; Overload; function FormatByteNumber( Bytes: String; Decimals: Byte = 1 ): String; Overload; @@ -2021,12 +2021,19 @@ end; @param string Text @return Integer Last position } -function LastPos( substr: WideString; str: WideString): Integer; +function LastPos(needle: WideChar; haystack: WideString): Integer; +var + reverse: WideString; + i, len, w: Integer; begin + // Reverse string. + len := Length(haystack); + SetLength(reverse, len); + for i := 1 to len do reverse[i] := haystack[len - i + 1]; + // Look for needle. Result := 0; - str := ReverseString( str ); - if Pos( substr, str ) > 0 then - Result := Length(str) - Pos( substr, str ) + 1; + w := Pos(needle, reverse); + if w > 0 then Result := len - w + 1; end; diff --git a/source/main.pas b/source/main.pas index 0d510c6c..1923d72f 100644 --- a/source/main.pas +++ b/source/main.pas @@ -17,7 +17,7 @@ uses ActnList, ImgList, Registry, ShellApi, ToolWin, Clipbrd, db, DBCtrls, SynMemo, synedit, SynEditTypes, ZDataSet, ZSqlProcessor, HeidiComp, sqlhelp, MysqlQueryThread, Childwin, VirtualTrees, TntDBGrids, - StrUtils, DateUtils, PngImageList, OptimizeTables, View, Usermanager, + DateUtils, PngImageList, OptimizeTables, View, Usermanager, SelectDBObject; type @@ -1248,30 +1248,30 @@ begin paramValue := ''; param := ParamStr(curIdx); // Example: --user=root --session="My session name" --password - if AnsiStartsStr('--'+paramName, param) then + if Pos('--' + paramName, param) = 1 then begin - i := Length('--'+paramName) + 1; + i := Length('--' + paramName) + 1; if param[i] = '=' then - paramValue := MidStr(param, i+1, Length(param)+1); - if (AnsiLeftStr(paramValue, 1) = '"') and (AnsiRightStr(paramValue, 1) = '"') then - paramValue := MidStr(paramValue, 2, Length(paramValue)); + paramValue := Copy(param, i + 1, Length(param) - i); + if (Copy(paramValue, 1, 1) = '"') and (Copy(paramValue, Length(paramValue), 1) = '"') then + paramValue := Copy(paramValue, 2, Length(paramValue) - 2); result := True; - end else if AnsiStartsStr('-'+paramChar, param) then + end else if Pos('-' + paramChar, param) = 1 then begin if Length(param) > 2 then begin // Example: -uroot -s"My session name" - paramValue := MidStr(param, 3, Length(param)+1); - if (AnsiLeftStr(paramValue, 1) = '"') and (AnsiRightStr(paramValue, 1) = '"') then - paramValue := MidStr(paramValue, 2, Length(paramValue)); + paramValue := Copy(param, 3, Length(param) - 2); + if (Copy(paramValue, 1, 1) = '"') and (Copy(paramValue, Length(paramValue), 1) = '"') then + paramValue := Copy(paramValue, 2, Length(paramValue) - 2); end else begin // Example: -u root -s "My session name" -p nextIdx := curIdx + 1; if nextIdx <= ParamCount then begin nextParam := ParamStr(nextIdx); - if not AnsiStartsStr('-', nextParam) then + if not Pos('-', nextParam) = 1 then paramValue := nextParam; end; end;