mirror of
https://github.com/moparisthebest/Simba
synced 2024-12-24 08:18:52 -05:00
Added explode + implode (explode is tres dirty!)
git-svn-id: http://www.villavu.com/repositories/merlijn/mufasa@555 3f818213-9676-44b0-a9b4-5e4c4e03d09d
This commit is contained in:
parent
479ced7f01
commit
18c43a2aa6
@ -43,7 +43,7 @@ uses
|
|||||||
ColorBox , about, framefunctionlist, ocr, updateform, simbasettings;
|
ColorBox , about, framefunctionlist, ocr, updateform, simbasettings;
|
||||||
|
|
||||||
const
|
const
|
||||||
SimbaVersion = 554;
|
SimbaVersion = 555;
|
||||||
|
|
||||||
type
|
type
|
||||||
|
|
||||||
|
@ -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'];
Format(const fmt : string;const args : array of const) : string; extdecl;
Format(const fmt : string;const args : array of const) : string; extdecl;
function Capitalize(str : string) : string;
Format(const fmt : string;const args : array of const) : string; extdecl;
var
result[i] := UpperCase(str[i])[1];
cap := false;
end else if not (str[i] in Range) then
cap := true;
end;
extdecl;
begin;
StrExtr =(Numbers, Letters, Others);
function ExtractFromStr( Str : string; Extract : StrExtr) : string; extdecl;
var
Range : set of char;
i : integer;
begin;
extdecl;
function Capitalize(str : string) : string;
Numbers : Range := ['0'..'9'];
Letters : Range := ['A'..'Z'] + ['a'..'z'];
begin;
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;
|
function ps_Format(const fmt : string;const args : array of const) : string; extdecl;
begin;
Result := Format(fmt,Args);
end;
begin;
begin;
function Capitalize(str : string) : string;
begin;
var
end;
begin;
i , l : integer;
begin;
function Capitalize(str : string) : string;
Result := Format(fmt,Args);
;
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;
|
@ -131,8 +131,8 @@ AddFunction(@ClearDebug,'procedure ClearDebug;');
|
|||||||
|
|
||||||
{string}
|
{string}
|
||||||
SetCurrSection('String');
|
SetCurrSection('String');
|
||||||
AddFunction(@Capitalize,'function Capitalize(str : string) : string;');
|
AddFunction(@ps_Capitalize,'function Capitalize(str : string) : string;');
|
||||||
AddFunction(@psFormat,'function Format(const fmt : string;const args : array of const) : string;');
|
AddFunction(@ps_Format,'function Format(const fmt : string;const args : array of const) : string;');
|
||||||
AddFunction(nil,'function ToStr(x) : string;');
|
AddFunction(nil,'function ToStr(x) : string;');
|
||||||
AddFunction(@ps_Between,'function Between(s1, s2, str: string): string;');
|
AddFunction(@ps_Between,'function Between(s1, s2, str: string): string;');
|
||||||
AddFunction(@ps_IntToStr, 'function IntToStr(value: Integer): 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_StrToFloatDef, 'function StrToFloatDef(value: String; default: Extended): Extended;');
|
||||||
AddFunction(@ps_StrToBool, 'function StrToBool(value: String): Boolean;');
|
AddFunction(@ps_StrToBool, 'function StrToBool(value: String): Boolean;');
|
||||||
AddFunction(@ps_StrToBoolDef, 'function StrToBoolDef(value: String; default: Boolean): 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 Replace(Text, FindStr, ReplaceStr: string; Flags: TReplaceFlags): string;');
|
||||||
AddFunction(@ps_Replace,'function ReplaceWrap(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}
|
{web}
|
||||||
SetCurrSection('Web');
|
SetCurrSection('Web');
|
||||||
AddFunction(@OpenWebPage,'procedure OpenWebPage(url : string);');
|
AddFunction(@OpenWebPage,'procedure OpenWebPage(url : string);');
|
||||||
|
@ -181,6 +181,7 @@ uses
|
|||||||
fontloader,
|
fontloader,
|
||||||
IOmanager,//TTarget_Exported
|
IOmanager,//TTarget_Exported
|
||||||
IniFiles,//Silly INI files
|
IniFiles,//Silly INI files
|
||||||
|
stringutil, //String st00f
|
||||||
uPSR_std, uPSR_controls,uPSR_classes,uPSR_graphics,uPSR_stdctrls,uPSR_forms,
|
uPSR_std, uPSR_controls,uPSR_classes,uPSR_graphics,uPSR_stdctrls,uPSR_forms,
|
||||||
uPSR_extctrls, //Runtime-libs
|
uPSR_extctrls, //Runtime-libs
|
||||||
Graphics, //For Graphics types
|
Graphics, //For Graphics types
|
||||||
|
115
trunk/Units/MMLAddon/stringutil.pas
Normal file
115
trunk/Units/MMLAddon/stringutil.pas
Normal file
@ -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.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user