library GetKrc;{ Important note about DLL memory management: ShareMem must be the
first unit in your library's USES clause AND your project's (select
Project-View Source) USES clause if your DLL exports any procedures or
functions that pass strings as parameters or function results. This
applies to all strings passed to and from your DLL--even those that
are nested in records and classes. ShareMem is the interface unit to
the BORLNDMM.DLL shared memory manager, which must be deployed along
with your DLL. To avoid using BORLNDMM.DLL, pass string information
using PChar or ShortString parameters. }uses
System.SysUtils,
System.Classes,
System.ZLib,
System.RegularExpressionsCore;const
miarry:array [0..15] of Char=(
'@','G','a','w','^','2','t','G','Q','6','1','-','Î','Ò','n','i');function KrcToLrc(filename: PChar): PChar;stdcall;
function ZDecompressStr2(const s: TBytes): UTF8String;
var
BIn,BOut: TBytes;
begin
BIn := s;
ZDecompress(BIn, BOut);
Result := TEncoding.UTF8.GetString(BOut);
end; function ToTime(timebuff: string): string;
var
maketime:string;
min,sec,hsec:string;
begin
timebuff:=Copy(timebuff,2,pos(',',timebuff)-2);
maketime:=IntToStr(strtoint(timebuff) div 1000);
hsec:=IntToStr(strtoint(timebuff) mod 1000);
min:=IntToStr(strtoint(maketime) div 60);
sec:= IntToStr(strtoint(maketime) mod 60); if StrToInt(min)<10 then min:='0'+min;
if StrToInt(sec)<10 then sec:='0'+sec;
Result:='['+min+':'+sec + '.' +Copy(hsec,1,2)+']';
end;var
Stream:TFileStream;
Top:array [0..3] of Byte;
k,j,l:Integer;
lrc_str:UTF8String;
reg:TPerlRegEx;
zip_byte:TBytes;
begin
Stream:=TFileStream.Create(filename,fmOpenReadWrite);
try
j :=Stream.Size;
SetLength(zip_byte,J-4);
Stream.read(Top,4);
Stream.Read(zip_byte,J-4);
for k := Low(zip_byte) to High(zip_byte) do
begin
l:=k mod 16;
zip_byte[k]:=zip_byte[k] xor Byte(miarry[l]);
end;
lrc_str:=ZDecompressStr2(zip_byte);
reg:=TPerlRegEx.Create();
try
reg.Subject:=lrc_str;
reg.RegEx:='(\<\d+\,\d+\,\d+\>)+';
reg.Replacement:='';
reg.ReplaceAll;
lrc_str:=reg.Subject;
reg.Subject:=lrc_str;
reg.RegEx:='(\[\d+\,\d+\])+';
while reg.MatchAgain do
begin
reg.Replacement:=ToTime(reg.Groups[0]);
reg.Replace;
end;
finally
Result:=PChar(UTF8ToString(reg.Subject));
reg.Free;
end;
finally
Stream.Free;
end;
end;exports KrcToLrc;begin
end.Delphi Xe3 下的DLL,依然坑爹的1.09MB。。
楼主对正则和语法还不是很熟悉,都是自己想怎么来解析就怎么解析
参照的是网上的JAVA代码翻译过来的
Mark一下