--- a/hedgewars/uLocale.pas Thu Oct 04 20:04:32 2018 +0300
+++ b/hedgewars/uLocale.pas Thu Oct 04 13:26:48 2018 -0400
@@ -23,15 +23,31 @@
uses uTypes;
const MAX_EVENT_STRINGS = 255;
-const MAX_FORMAT_STRING_SYMBOLS = 9;
procedure LoadLocale(FileName: shortstring);
-function Format(fmt: shortstring; args: array of shortstring): shortstring;
-function FormatA(fmt: ansistring; args: array of ansistring): ansistring;
-function Format(fmt: shortstring; arg: shortstring): shortstring;
-function FormatA(fmt: ansistring; arg: ansistring): ansistring;
function GetEventString(e: TEventId): ansistring;
+function Format(fmt: shortstring; arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9: shortstring; argCount: Byte): shortstring;
+function Format(fmt: shortstring; arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9: shortstring): shortstring;
+function Format(fmt: shortstring; arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8: shortstring): shortstring;
+function Format(fmt: shortstring; arg1, arg2, arg3, arg4, arg5, arg6, arg7: shortstring): shortstring;
+function Format(fmt: shortstring; arg1, arg2, arg3, arg4, arg5, arg6: shortstring): shortstring;
+function Format(fmt: shortstring; arg1, arg2, arg3, arg4, arg5: shortstring): shortstring;
+function Format(fmt: shortstring; arg1, arg2, arg3, arg4: shortstring): shortstring;
+function Format(fmt: shortstring; arg1, arg2, arg3: shortstring): shortstring;
+function Format(fmt: shortstring; arg1, arg2: shortstring): shortstring;
+function Format(fmt: shortstring; arg1: shortstring): shortstring;
+function FormatA(fmt: ansistring; arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9: ansistring; argCount: Byte): ansistring;
+function FormatA(fmt: ansistring; arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9: ansistring): ansistring;
+function FormatA(fmt: ansistring; arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8: ansistring): ansistring;
+function FormatA(fmt: ansistring; arg1, arg2, arg3, arg4, arg5, arg6, arg7: ansistring): ansistring;
+function FormatA(fmt: ansistring; arg1, arg2, arg3, arg4, arg5, arg6: ansistring): ansistring;
+function FormatA(fmt: ansistring; arg1, arg2, arg3, arg4, arg5: ansistring): ansistring;
+function FormatA(fmt: ansistring; arg1, arg2, arg3, arg4: ansistring): ansistring;
+function FormatA(fmt: ansistring; arg1, arg2, arg3: ansistring): ansistring;
+function FormatA(fmt: ansistring; arg1, arg2: ansistring): ansistring;
+function FormatA(fmt: ansistring; arg1: ansistring): ansistring;
+
{$IFDEF HWLIBRARY}
procedure LoadLocaleWrapper(path: pchar; userpath: pchar; filename: pchar); cdecl; export;
{$ENDIF}
@@ -119,60 +135,147 @@
end;
// Format the string fmt.
-// Take a shortstring with placeholders %1, %2, %3, etc. and replace
+// Take a shortstring with placeholders %1, %2, %3, ... %9. and replace
// them with the corresponding elements of an array with up to
-// MAX_FORMAT_STRING_SYMBOLS. Important! Each placeholder can only be
-// used exactly once and numbers MUST NOT be skipped (e.g. using %1 and %3
-// but not %2.
-function Format(fmt: shortstring; args: array of shortstring): shortstring;
+// argCount. ArgCount must not be larger than 9.
+// Each placeholder must be used exactly once and numbers MUST NOT be
+// skipped (e.g. using %1 and %3 but not %2.
+function Format(fmt: shortstring; arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9: shortstring; argCount: Byte): shortstring;
var i, p: LongInt;
-tempstr: shortstring;
+tempstr, curArg: shortstring;
begin
tempstr:= fmt;
-for i:=0 to MAX_FORMAT_STRING_SYMBOLS - 1 do
+for i:=0 to argCount - 1 do
begin
+ case i of
+ 0: curArg:= arg1;
+ 1: curArg:= arg2;
+ 2: curArg:= arg3;
+ 3: curArg:= arg4;
+ 4: curArg:= arg5;
+ 5: curArg:= arg6;
+ 6: curArg:= arg7;
+ 7: curArg:= arg8;
+ 8: curArg:= arg9;
+ end;
+
p:= Pos('%'+IntToStr(i+1), tempstr);
- if (p = 0) or (i >= Length(args)) then
+ if (p = 0) then
break
else
begin
delete(tempstr, p, 2);
- insert(args[i], tempstr, p);
+ insert(curArg, tempstr, p);
end;
end;
Format:= tempstr;
end;
// Same as Format, but for ansistring
-function FormatA(fmt: ansistring; args: array of ansistring): ansistring;
+function FormatA(fmt: ansistring; arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9: ansistring; argCount: Byte): ansistring;
var i, p: LongInt;
-tempstr: ansistring;
+tempstr, curArg: ansistring;
begin
tempstr:= fmt;
-for i:=0 to MAX_FORMAT_STRING_SYMBOLS - 1 do
+for i:=0 to argCount - 1 do
begin
+ case i of
+ 0: curArg:= arg1;
+ 1: curArg:= arg2;
+ 2: curArg:= arg3;
+ 3: curArg:= arg4;
+ 4: curArg:= arg5;
+ 5: curArg:= arg6;
+ 6: curArg:= arg7;
+ 7: curArg:= arg8;
+ 8: curArg:= arg9;
+ end;
+
p:= Pos('%'+IntToStr(i+1), tempstr);
- if (p = 0) or (i >= Length(args)) then
+ if (p = 0) then
break
else
begin
delete(tempstr, p, 2);
- insert(args[i], tempstr, p);
+ insert(curArg, tempstr, p);
end;
end;
FormatA:= tempstr;
end;
-// Same as Format above, but with only one placeholder %1, replaced by arg.
-function Format(fmt: shortstring; arg: shortstring): shortstring;
+// The following functions are just shortcuts of Format/FormatA, with fewer argument counts
+function Format(fmt: shortstring; arg1: shortstring): shortstring;
+begin
+ Format:= Format(fmt, arg1, '', '', '', '', '', '', '', '', 1);
+end;
+function Format(fmt: shortstring; arg1, arg2: shortstring): shortstring;
+begin
+ Format:= Format(fmt, arg1, arg2, '', '', '', '', '', '', '', 2);
+end;
+function Format(fmt: shortstring; arg1, arg2, arg3: shortstring): shortstring;
+begin
+ Format:= Format(fmt, arg1, arg2, arg3, '', '', '', '', '', '', 3);
+end;
+function Format(fmt: shortstring; arg1, arg2, arg3, arg4: shortstring): shortstring;
begin
- Format:= Format(fmt, [arg]);
+ Format:= Format(fmt, arg1, arg2, arg3, arg4, '', '', '', '', '', 4);
+end;
+function Format(fmt: shortstring; arg1, arg2, arg3, arg4, arg5: shortstring): shortstring;
+begin
+ Format:= Format(fmt, arg1, arg2, arg3, arg4, arg5, '', '', '', '', 5);
+end;
+function Format(fmt: shortstring; arg1, arg2, arg3, arg4, arg5, arg6: shortstring): shortstring;
+begin
+ Format:= Format(fmt, arg1, arg2, arg3, arg4, arg5, arg6, '', '', '', 6);
+end;
+function Format(fmt: shortstring; arg1, arg2, arg3, arg4, arg5, arg6, arg7: shortstring): shortstring;
+begin
+ Format:= Format(fmt, arg1, arg2, arg3, arg4, arg5, arg6, arg7, '', '', 7);
+end;
+function Format(fmt: shortstring; arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8: shortstring): shortstring;
+begin
+ Format:= Format(fmt, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, '', 8);
+end;
+function Format(fmt: shortstring; arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9: shortstring): shortstring;
+begin
+ Format:= Format(fmt, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, 9);
end;
-// Same as above, but for ansistring
-function FormatA(fmt: ansistring; arg: ansistring): ansistring;
+function FormatA(fmt: ansistring; arg1: ansistring): ansistring;
+begin
+ FormatA:= FormatA(fmt, arg1, '', '', '', '', '', '', '', '', 1);
+end;
+function FormatA(fmt: ansistring; arg1, arg2: ansistring): ansistring;
+begin
+ FormatA:= FormatA(fmt, arg1, arg2, '', '', '', '', '', '', '', 2);
+end;
+function FormatA(fmt: ansistring; arg1, arg2, arg3: ansistring): ansistring;
+begin
+ FormatA:= FormatA(fmt, arg1, arg2, arg3, '', '', '', '', '', '', 3);
+end;
+function FormatA(fmt: ansistring; arg1, arg2, arg3, arg4: ansistring): ansistring;
+begin
+ FormatA:= FormatA(fmt, arg1, arg2, arg3, arg4, '', '', '', '', '', 4);
+end;
+function FormatA(fmt: ansistring; arg1, arg2, arg3, arg4, arg5: ansistring): ansistring;
begin
- FormatA:= FormatA(fmt, [arg]);
+ FormatA:= FormatA(fmt, arg1, arg2, arg3, arg4, arg5, '', '', '', '', 5);
+end;
+function FormatA(fmt: ansistring; arg1, arg2, arg3, arg4, arg5, arg6: ansistring): ansistring;
+begin
+ FormatA:= FormatA(fmt, arg1, arg2, arg3, arg4, arg5, arg6, '', '', '', 6);
+end;
+function FormatA(fmt: ansistring; arg1, arg2, arg3, arg4, arg5, arg6, arg7: ansistring): ansistring;
+begin
+ FormatA:= FormatA(fmt, arg1, arg2, arg3, arg4, arg5, arg6, arg7, '', '', 7);
+end;
+function FormatA(fmt: ansistring; arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8: ansistring): ansistring;
+begin
+ FormatA:= FormatA(fmt, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, '', 8);
+end;
+function FormatA(fmt: ansistring; arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9: ansistring): ansistring;
+begin
+ FormatA:= FormatA(fmt, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, 9);
end;
{$IFDEF HWLIBRARY}