diff --git a/src/shared/utils.pas b/src/shared/utils.pas
index 1caa1f3338c12bb30327a45ac45a4abff404199b..d8b6e85c266dcf6fb2142759b53e8b5e35e913aa 100644 (file)
--- a/src/shared/utils.pas
+++ b/src/shared/utils.pas
function UpCase1251 (ch: Char): Char;
function LoCase1251 (ch: Char): Char;
+function toLowerCase1251 (const s: AnsiString): AnsiString;
+
// `true` if strings are equal; ignoring case for cp1251
function StrEquCI1251 (const s0, s1: AnsiString): Boolean;
TFormatStrFCallback = procedure (constref buf; len: SizeUInt);
// returns formatted string if `writerCB` is `nil`, empty string otherwise
-function formatstrf (const fmt: AnsiString; args: array of const; writerCB: TFormatStrFCallback=nil): AnsiString;
+function formatstrf (const fmt: AnsiString; const args: array of const; writerCB: TFormatStrFCallback=nil): AnsiString;
function wchar2win (wc: WideChar): AnsiChar; inline;
function utf2win (const s: AnsiString): AnsiString;
procedure clear (); inline;
procedure append (constref it: ItemT); inline;
+ procedure delete (idx: Integer); inline;
+ function remove (idx: Integer): ItemT; inline;
public
property count: Integer read mCount;
procedure TSimpleList.append (constref it: ItemT); inline;
+var
+ newsz: Integer;
begin
- if (mCount = Length(mItems)) then
+ if (mCount >= Length(mItems)) then
begin
- if (mCount = 0) then SetLength(mItems, 128) else SetLength(mItems, mCount*2);
+ newsz := mCount+(mCount div 3)+128;
+ SetLength(mItems, newsz);
end;
mItems[mCount] := it;
Inc(mCount);
end;
+procedure TSimpleList.delete (idx: Integer); inline;
+var
+ f: Integer;
+begin
+ if (idx >= 0) and (idx < mCount) then
+ begin
+ for f := idx+1 to mCount-1 do mItems[f-1] := mItems[f];
+ end;
+end;
+
+
+function TSimpleList.remove (idx: Integer): ItemT; inline;
+var
+ f: Integer;
+begin
+ if (idx >= 0) and (idx < mCount) then
+ begin
+ result := mItems[idx];
+ for f := idx+1 to mCount-1 do mItems[f-1] := mItems[f];
+ end
+ else
+ begin
+ result := Default(ItemT);
+ end;
+end;
+
+
// ////////////////////////////////////////////////////////////////////////// //
var
wc2shitmap: array[0..65535] of AnsiChar;
end;
+function toLowerCase1251 (const s: AnsiString): AnsiString;
+var
+ f: Integer;
+ ch: AnsiChar;
+begin
+ for ch in s do
+ begin
+ if (ch <> LoCase1251(ch)) then
+ begin
+ result := '';
+ SetLength(result, Length(s));
+ for f := 1 to Length(s) do result[f] := LoCase1251(s[f]);
+ exit;
+ end;
+ end;
+ // nothing to do
+ result := s;
+end;
+
+
// ////////////////////////////////////////////////////////////////////////// //
// utils
// `ch`: utf8 start
*)
-function formatstrf (const fmt: AnsiString; args: array of const; writerCB: TFormatStrFCallback=nil): AnsiString;
+function formatstrf (const fmt: AnsiString; const args: array of const; writerCB: TFormatStrFCallback=nil): AnsiString;
const
PadSpaces: AnsiString = ' ';
PadZeroes: AnsiString = '00000000000000000000000000000000000000000000000000000000000000000000000';
xpos := High(strbuf);
strbuf[xpos] := #0; Dec(xpos);
repeat
- if hex then
+ if not hex then
begin
strbuf[xpos] := AnsiChar((n mod 10)+48);
Dec(xpos);
xpos := High(strbuf);
strbuf[xpos] := #0; Dec(xpos);
repeat
- if hex then
+ if not hex then
begin
strbuf[xpos] := AnsiChar((n mod 10)+48);
Dec(xpos);