1
0
mirror of https://github.com/moparisthebest/Simba synced 2025-03-03 02:41:54 -05:00

Added Compress/Decompress String; Base64 conversion and 'procedure Simba'

This commit is contained in:
Raymond 2010-05-12 19:05:56 +02:00
parent adcc10fc58
commit 559a3f977c
6 changed files with 71 additions and 3 deletions

View File

@ -271,7 +271,7 @@
<Unit42>
<Filename Value="../../Units/Misc/dcpbase64.pas"/>
<IsPartOfProject Value="True"/>
<UnitName Value="dcpbase64"/>
<UnitName Value="DCPbase64"/>
</Unit42>
<Unit43>
<Filename Value="../../Units/Misc/mPasLex.pas"/>

View File

@ -158,6 +158,16 @@ procedure ps_HakunaMatata; extdecl;
begin;
OpenWebPage('http://www.youtube.com/v/ejEVczA8PLU&hl=en&fs=1&autoplay=1');
end;
procedure ps_Simba; extdecl;
begin
psWriteln(DecompressString(Base64Decode('9AoAAHicldU7b+0gDADgvdL9D+AisSDOTrpUvWvGuzNVOkMn9v72a942j6T1dJrEX7AxqRAXYaS9up3iz8suVxoMKe+'+
'NC6LGnbEhiCCfTzPfJ5cmgidj5J9MsezSQAyApGHGR17N9SpGoBj1tkuRkJHoAk3WeMfTC66GWbaTFtMAwZDPRjh73U4uCKGnRTh3NMK0mAjiXxA975iERASl'+
'QjfcRLBVS963TKCQDb0m8Brwwv1IKAWkErcipPNAC5+JdPmY62hE/O3L8yE+T4k4PpGwi2aiEIn25zcqKMQ1a6bgNtGN4kJqJ1tYeqFwrMNDcCFvKjMsWXLOK'+
'N19toPbBN2PmacG9BogFoW7CQD00JTHdZlLml1yQZiv8zzBxGlQzxoxlx+Gdjo8JQDMV8w/0UmCctC/PGZDIKKPFMIGOM8M5IlUyuMel05IwY3hiHoMTLJYdg'+
'RKvhJxsGt5wzKI8PApjpQTQmj5CkIRIO6S3REPXZjD1kyNGxABm60IxLkdu8HqQOaRmt0TcTVVFHzCdq2oX6ae2CMRuo/bWuhdHfMhfSI8PTE3xIjAuIRu7An'+
'hv0kN+e38+1GMPYH/hq1PcyKsywdWvI1n9Y4YXzsLydgSphI4G7i/AexYRTW2RJmBPqFqTcgtUW7T6dgQlwIDfrsIsyDCphcbot5eDPgviZ8Yt0S4Ne4Iuoy/H'+
'+//1sR/NLyhCQ==')));
end;
function ps_Random(Int: integer): integer; extdecl;
begin

View File

@ -1 +1 @@
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; function ps_Padl(s: String; i: longInt): String;extdecl; begin result := StringOfChar(Char(' '), i - length(s)) + s; end; function ps_Padz(s: String; i: longInt): String;extdecl; begin result := StringOfChar(Char('0'), i - length(s)) + s; end; function ps_Padr(s: String; i: longInt): String;extdecl; begin result := s + StringOfChar(Char(' '), i - Length(s)); end; function ps_ExecRegExpr( const RegExpr, InputStr : String) : boolean;extdecl; begin result := execregexpr(RegExpr,InputStr); end; procedure ps_SplitRegExpr( const RegExpr, InputStr : String; Pieces : TStrings);extdecl; begin SplitRegExpr(RegExpr,InputStr,Pieces); end; function ps_ReplaceRegExpr( const RegExpr, InputStr, ReplaceStr : String; UseSubstitution : boolean) : String;extdecl; begin result := ReplaceRegExpr(RegExpr,InputStr,ReplaceStr,UseSubstitution); end;
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_CompressString(const Str : string) : string; extdecl; begin result := CompressString(str); end; function ps_DecompressString(const Compressed : string) : string; extdecl; begin result := DecompressString(Compressed); end; function ps_Base64Encode(const str : string) : string; extdecl; begin result := Base64Encode(str); end; function ps_Base64Decode(const str : string) : string; extdecl; begin result := Base64Decode(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; function ps_Padl(s: String; i: longInt): String;extdecl; begin result := StringOfChar(Char(' '), i - length(s)) + s; end; function ps_Padz(s: String; i: longInt): String;extdecl; begin result := StringOfChar(Char('0'), i - length(s)) + s; end; function ps_Padr(s: String; i: longInt): String;extdecl; begin result := s + StringOfChar(Char(' '), i - Length(s)); end; function ps_ExecRegExpr( const RegExpr, InputStr : String) : boolean;extdecl; begin result := execregexpr(RegExpr,InputStr); end; procedure ps_SplitRegExpr( const RegExpr, InputStr : String; Pieces : TStrings);extdecl; begin SplitRegExpr(RegExpr,InputStr,Pieces); end; function ps_ReplaceRegExpr( const RegExpr, InputStr, ReplaceStr : String; UseSubstitution : boolean) : String;extdecl; begin result := ReplaceRegExpr(RegExpr,InputStr,ReplaceStr,UseSubstitution); end;

View File

@ -131,6 +131,7 @@ AddFunction(@ps_DecodeTime,'procedure DecodeTime(DateTime : TDateTime; var Hour,
AddFunction(@ps_DecodeDate,'procedure DecodeDate ( const SourceDate : TDateTime; var Year, Month, Day : Word );');
AddFunction(@ps_ConvertTime,'procedure ConvertTime(Time: integer; var h, m, s: integer);');
AddFunction(@ps_HakunaMatata,'procedure HakunaMatata;');
AddFunction(@ps_Simba,'procedure Simba;');
AddFunction(@ps_TerminateScript,'procedure TerminateScript;');
AddFunction(@ps_DisplayDebugImgWindow,'procedure DisplayDebugImgWindow(w, h: integer);');
AddFunction(@ps_DrawBitmapDebugImg,'procedure DrawBitmapDebugImg(bmp: integer);');
@ -146,6 +147,10 @@ AddFunction(@ps_InputQuery,'function InputQuery(const ACaption, APrompt : String
{string}
SetCurrSection('String');
AddFunction(@ps_Capitalize,'function Capitalize(str : string) : string;');
AddFunction(@ps_CompressString,'function CompressString(const Str : string) : string;');
AddFunction(@ps_DecompressString,'function DecompressString(const Compressed : string) : string;');
AddFunction(@ps_Base64Encode,'function Base64Encode(const str : string) : string;');
AddFunction(@ps_Base64Decode,'function Base64Decode(const 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;');

View File

@ -13,8 +13,14 @@ 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;
function CompressString(const Str : string) : string;
function DecompressString(const Compressed : string) : string;
function Base64Encode(const str : string) : string;
function Base64Decode(const str : string) : string;
implementation
uses
paszlib, DCPbase64;
function Implode(Glue: string;Pieces: TStringArray): string;
var
@ -76,6 +82,53 @@ begin;
result[lenres-1] := Copy(str,lastpos,lenstr - lastpos + 1);
end;
function CompressString(const Str: string): string;
var
Destlen:longword;
begin
result := '';
Destlen :=BufferLen;
if length(str) < 1 then
exit;
if compress(BufferString,destlen,PChar(Str),length(str)) = Z_OK then
begin
setlength(result,Destlen + 4);
PInteger(@result[1])^ := Length(str);
Move(bufferstring[0],result[5],Destlen);
end;
end;
function DecompressString(const Compressed: string): string;
var
destlen : Longword;
len,dest : integer;
Compress : PChar;
begin
result := '';
len := Length(Compressed);
Compress := PChar(Compressed);
if len < 5 then
exit;
dest := PInteger(@compress[0])^;
Inc(Compress,sizeof(integer));
if dest < 1 then
exit;
destlen := dest;
setlength(result,destlen);
if uncompress(PChar(result),destlen,Compress,len) <> z_OK then
result := '';
end;
function Base64Encode(const str: string): string;
begin
result := Base64EncodeStr(str);
end;
function Base64Decode(const str: string): string;
begin
result := Base64DecodeStr(str);
end;
function Capitalize(str : string) : string;
var
i , l : integer;

View File

@ -625,7 +625,7 @@ begin
CorrectData[i].B := FData[i].B;
end;
DestLen := BufferLen;
if compress(Pchar(BufferString),destlen,PChar(DataStr),w*h*3) = Z_OK then
if compress(BufferString,destlen,PChar(DataStr),w*h*3) = Z_OK then
begin;
SetLength(DataStr,DestLen);
move(bufferstring[0],dataStr[1],DestLen);