diff --git a/trunk/Projects/SAMufasaGUI/testunit.pas b/trunk/Projects/SAMufasaGUI/testunit.pas index f43bb3a..6ac831d 100644 --- a/trunk/Projects/SAMufasaGUI/testunit.pas +++ b/trunk/Projects/SAMufasaGUI/testunit.pas @@ -43,7 +43,7 @@ uses ColorBox , about, framefunctionlist, ocr, updateform, simbasettings; const - SimbaVersion = 554; + SimbaVersion = 555; type diff --git a/trunk/Units/MMLAddon/PSInc/Wrappers/strings.inc b/trunk/Units/MMLAddon/PSInc/Wrappers/strings.inc index 48b0658..9bbc50d 100644 --- a/trunk/Units/MMLAddon/PSInc/Wrappers/strings.inc +++ b/trunk/Units/MMLAddon/PSInc/Wrappers/strings.inc @@ -1 +1 @@ -function psFormat(const fmt : string;const args : array of const) : string; extdecl; extdecl; begin; Result := Format(fmt,Args); end; function Capitalize(str : string) : string; extdecl; var i , l : integer; cap : boolean; Range : set of char; begin; result := str; l := length(str); cap := true; Range := ['a'..'z'] + ['A'..'Z']; for i := 1 to l do if cap and (str[i] in Range) then begin; result[i] := UpperCase(str[i])[1]; cap := false; end else if not (str[i] in Range) then cap := true; end; type StrExtr =(Numbers, Letters, Others); function ExtractFromStr( Str : string; Extract : StrExtr) : string; extdecl; var Range : set of char; i : integer; begin; case Extract of Numbers : Range := ['0'..'9']; Letters : Range := ['A'..'Z'] + ['a'..'z']; Others : Range := [#0..#255] - ['0'..'9'] - ['A'..'Z'] - ['a'..'z']; end; for i := length(str) downto 1 do if str[i] in Range then result := str[i] + result; end; function ps_BoolToStr(bool : boolean) : string; extdecl; begin; result := BoolToStr(bool,true); end; function ps_Replace(Text, FindStr, ReplaceStr: string; Flags: TReplaceFlags): string; extdecl; begin; result := StringReplace(Text,FindStr,ReplaceStr,Flags); end; function ps_IntToStr(int : integer) : string; extdecl; begin result := inttostr(int); end; function ps_FloatToStr(flt : extended) : string; extdecl; begin result := floattostr(flt); end; function ps_StrToInt(value: String): Integer; extdecl; begin result := StrToInt(value); end; function ps_StrToIntDef(value: String; default: Integer): Integer; extdecl; begin result := StrToIntDef(value,default); end; function ps_StrToFloat(value: String): Extended; extdecl; begin result := StrToFloat(value); end; function ps_StrToFloatDef(value: String; default: Extended): Extended; extdecl; begin result := StrToFloatDef(value,default); end; function ps_StrToBool(value: String): Boolean;extdecl; begin result := StrToBool(value); end; function ps_StrToBoolDef(value: String; default: Boolean): Boolean; extdecl; begin result := StrToBoolDef(value,default); end; function ps_Between(s1, s2, str: string): string; extdecl; var I,J : integer; begin; Result := ''; I := pos(s1,str); if I > 0 then begin; i := i + length(s1); j := posex(s2,str,i); if j > 0 then Result := copy(str,i,j-i); end; end; \ No newline at end of file +function ps_Format(const fmt : string;const args : array of const) : string; extdecl; begin; Result := Format(fmt,Args); end; function ps_Capitalize(str : string) : string;extdecl; begin result := Capitalize(str); end; function ps_ExtractFromStr( Str : string; Extract : StrExtr) : string; extdecl; begin result := extractfromstr(str,extract); end; function ps_BoolToStr(bool : boolean) : string; extdecl; begin; result := BoolToStr(bool,true); end; function ps_Replace(Text, FindStr, ReplaceStr: string; Flags: TReplaceFlags): string; extdecl; begin; result := StringReplace(Text,FindStr,ReplaceStr,Flags); end; function ps_IntToStr(int : integer) : string; extdecl; begin result := inttostr(int); end; function ps_FloatToStr(flt : extended) : string; extdecl; begin result := floattostr(flt); end; function ps_StrToInt(value: String): Integer; extdecl; begin result := StrToInt(value); end; function ps_StrToIntDef(value: String; default: Integer): Integer; extdecl; begin result := StrToIntDef(value,default); end; function ps_StrToFloat(value: String): Extended; extdecl; begin result := StrToFloat(value); end; function ps_StrToFloatDef(value: String; default: Extended): Extended; extdecl; begin result := StrToFloatDef(value,default); end; function ps_StrToBool(value: String): Boolean;extdecl; begin result := StrToBool(value); end; function ps_StrToBoolDef(value: String; default: Boolean): Boolean; extdecl; begin result := StrToBoolDef(value,default); end; function ps_Between(s1, s2, str: string): string; extdecl; var I,J : integer; begin; Result := ''; I := pos(s1,str); if I > 0 then begin; i := i + length(s1); j := posex(s2,str,i); if j > 0 then Result := copy(str,i,j-i); end; end; function ps_Implode(Glue : string; Pieces: TStringArray): string;extdecl; begin result := implode(glue,pieces); end; function ps_Explode(del, str: string): TStringArray;extdecl; begin result := Explode(del,str); end; procedure ps_ExplodeWrap(del, str: string; var res : TStringArray);extdecl; begin res := Explode(del,str); end; \ No newline at end of file diff --git a/trunk/Units/MMLAddon/PSInc/psexportedmethods.inc b/trunk/Units/MMLAddon/PSInc/psexportedmethods.inc index ce3d4ae..220e2fb 100644 --- a/trunk/Units/MMLAddon/PSInc/psexportedmethods.inc +++ b/trunk/Units/MMLAddon/PSInc/psexportedmethods.inc @@ -131,8 +131,8 @@ AddFunction(@ClearDebug,'procedure ClearDebug;'); {string} SetCurrSection('String'); -AddFunction(@Capitalize,'function Capitalize(str : string) : string;'); -AddFunction(@psFormat,'function Format(const fmt : string;const args : array of const) : string;'); +AddFunction(@ps_Capitalize,'function Capitalize(str : string) : string;'); +AddFunction(@ps_Format,'function Format(const fmt : string;const args : array of const) : string;'); AddFunction(nil,'function ToStr(x) : string;'); AddFunction(@ps_Between,'function Between(s1, s2, str: string): string;'); AddFunction(@ps_IntToStr, 'function IntToStr(value: Integer): String;'); @@ -144,9 +144,13 @@ AddFunction(@ps_StrToFloat, 'function StrToFloat(value: String): Extended;'); AddFunction(@ps_StrToFloatDef, 'function StrToFloatDef(value: String; default: Extended): Extended;'); AddFunction(@ps_StrToBool, 'function StrToBool(value: String): Boolean;'); AddFunction(@ps_StrToBoolDef, 'function StrToBoolDef(value: String; default: Boolean): Boolean;'); -AddFunction(@ExtractFromStr,'function ExtractFromStr( Str : string; Extract : StrExtr) : string;'); +AddFunction(@ps_ExtractFromStr,'function ExtractFromStr( Str : string; Extract : StrExtr) : string;'); AddFunction(@ps_Replace,'function Replace(Text, FindStr, ReplaceStr: string; Flags: TReplaceFlags): string;'); AddFunction(@ps_Replace,'function ReplaceWrap(Text, FindStr, ReplaceStr: string; Flags: TReplaceFlags): string;'); +AddFunction(@ps_Implode,'function Implode(Glue: string; Pieces: TStringArray): string;'); +AddFunction(@ps_Explode,'function Explode(del, str: string): TStringArray;'); +AddFunction(@ps_explodewrap,'procedure ExplodeWrap(del, str: string; var res : TStringArray);'); + {web} SetCurrSection('Web'); AddFunction(@OpenWebPage,'procedure OpenWebPage(url : string);'); diff --git a/trunk/Units/MMLAddon/mmlpsthread.pas b/trunk/Units/MMLAddon/mmlpsthread.pas index 40347a4..e53ebe5 100644 --- a/trunk/Units/MMLAddon/mmlpsthread.pas +++ b/trunk/Units/MMLAddon/mmlpsthread.pas @@ -181,6 +181,7 @@ uses fontloader, IOmanager,//TTarget_Exported IniFiles,//Silly INI files + stringutil, //String st00f uPSR_std, uPSR_controls,uPSR_classes,uPSR_graphics,uPSR_stdctrls,uPSR_forms, uPSR_extctrls, //Runtime-libs Graphics, //For Graphics types diff --git a/trunk/Units/MMLAddon/stringutil.pas b/trunk/Units/MMLAddon/stringutil.pas new file mode 100644 index 0000000..f279111 --- /dev/null +++ b/trunk/Units/MMLAddon/stringutil.pas @@ -0,0 +1,115 @@ +unit stringutil; + +{$mode objfpc} + +interface + +uses + Classes, SysUtils,mufasatypes; + +type + StrExtr =(Numbers, Letters, Others); +function ExtractFromStr( Str : string; Extract : StrExtr) : string; +function Capitalize(str : string) : string; +function Implode(Glue : string; Pieces: TStringArray): string; +function Explode(del, str: string): TStringArray; + +implementation + +function Implode(Glue: string;Pieces: TStringArray): string; +var + I, Len : integer; +begin + Len := high(Pieces); + if (Len < 0) then + exit; + Result := Pieces[0]; + for i := 1 to len do + result := result + Glue + Pieces[i]; +end; + +function Explode(del, str: string): TStringArray; +var + i,ii : integer; + lastpos : integer; + lenstr : integer; + lendel : integer; + lenres : integer; + matches : boolean; +begin; + lastpos := 1; + lenres := 0; + setlength(result,lenres); + lendel := length(del); + lenstr := length(str); + // for i := 1 to lenstr do + i := 1; + while i < lenstr do + begin; + if not ((i + lendel - 1) > lenstr) then + begin + matches := true; + for ii := 1 to lendel do + if str[i + ii - 1] <> del[ii] then + begin + matches := false; + break; + end; + if matches then + begin; + inc(lenres); + setlength(result,lenres); + result[lenres-1] := Copy(str,lastpos,i-lastpos); + lastpos := i+lendel; + i := i + lendel-1;//Dirty + end; + end else //We cannot possibly find a delimiter anymore, thus copy the rest of the string + Break; + inc(i); + end; + //Copy the rest of the string (if it's not a delimiter) + if (lenstr - lastpos + 1) = 0 then + exit; + inc(lenres); + setlength(result,lenres); + result[lenres-1] := Copy(str,lastpos,lenstr - lastpos + 1); + if result[lenres-1] = del then + result[lenres-1] := ''; +end; + +function Capitalize(str : string) : string; +var + i , l : integer; + cap : boolean; + Range : set of char; +begin; + result := str; + l := length(str); + cap := true; + Range := ['a'..'z'] + ['A'..'Z']; + for i := 1 to l do + if cap and (str[i] in Range) then + begin; + result[i] := UpperCase(str[i])[1]; + cap := false; + end else if not (str[i] in Range) then + cap := true; +end; + +function ExtractFromStr( Str : string; Extract : StrExtr) : string; +var + Range : set of char; + i : integer; +begin; + case Extract of + Numbers : Range := ['0'..'9']; + Letters : Range := ['A'..'Z'] + ['a'..'z']; + Others : Range := [#0..#255] - ['0'..'9'] - ['A'..'Z'] - ['a'..'z']; + end; + for i := length(str) downto 1 do + if str[i] in Range then + result := str[i] + result; +end; + +end. +