nesco, ты кажется тоже где-то дельфячий WideCharToString юзал...
Add(MainForm,15194538,42,84)
{
Left=10
Top=10
Position=1
link(onCreate,836762:doSearch,[])
}
Add(StrList,13871442,98,42)
{
Strings=#102:<title>Травиан - онлайн игра – Римляне, Галлы, Германцы</title>|
}
Add(BlockFind,836762,98,119)
{
IncludeBlock=1
StartBlock="<title>"
EndBlock="</title>"
link(onSearch,2591357:doUTF8,[])
link(Text,13871442:Text,[])
}
Add(Memo,14969934,210,119)
{
Left=10
Top=15
Width=365
Height=230
ScrollBars=3
}
Add(InlineCode,2591357,154,119)
{
WorkPoints=#6:doUTF8|
EventPoints=#6:onUTF8|
VarPoints=#6:Result|
DataPoints=#3:Str|
Code=#15:unit HiAsmUnit;|0:|9:interface|0:|29:uses windows,kol,Share,Debug;|0:|4:type|28: THiAsmClass = class(TDebug)|10: private|19: FResult:String;|11: public |18: Str:THI_Event;|21: onUTF8:THI_Event;|0:|50: procedure doUTF8(var _Data:TData; Index:word);|50: procedure Result(var _Data:TData; Index:word);|5: end;|0:|14:implementation|0:|45:{Convert string from UTF-8 format into ASCII}|42:function UTF8ToStr(Value: String): String;|3:var|18: buffer: Pointer;|18: BufLen: integer;|5:begin|15: Result := ';|67: BufLen := MultiByteToWideChar(CP_UTF8, 0, @Value[1], -1, nil, 0);|26: if BufLen < 1 then exit;|27: GetMem(buffer, 2*BufLen);|65: MultiByteToWideChar(CP_UTF8, 0, @Value[1], -1, buffer, BufLen);|84:// Result := WideCharToString(buffer); //под FPC не работает эта фигня правильно :(|61: BufLen := WideCharToMultiByte(3,0,buffer,-1,nil,0,nil,nil);|26: if BufLen > 1 then begin|31: SetLength(Result,BufLen-1);|65: WideCharToMultiByte(3,0,buffer,-1,@Result[1],BufLen,nil,nil);|6: end;|18: FreeMem(buffer);|4:end;|0:|78:{Convert string from UTF-8 format mixed with standart ASCII symbols($00..$7f)}|47:function UTF8ToStrSmart(Value: String): String;|3:var|17: i,Len: integer;|14: HByte: Byte;|5:begin|15: Result := ';|26: if Value = ' then Exit;|43: i := 1; while i <= Length(Value) do begin|27: HByte := Ord(Value[i]);|30: //Get length of UTF-8 char|45: if HByte and $FC = $FC then Len := 6|45: else if HByte and $F8 = $F8 then Len := 5|45: else if HByte and $F0 = $F0 then Len := 4|45: else if HByte and $E0 = $E0 then Len := 3|45: else if HByte and $C0 = $C0 then Len := 2|14: else begin|34: Result := Result + Value[i];|13: Inc(i);|15: Continue;|8: end;|52: Result := Result + UTF8ToStr(Copy(Value,i,Len));|15: Inc(i,Len);|6: end;|4:end;|0:|79://function StringToWideString(const s: AnsiString; codePage: Word): WideString;|73:function StringToWideString(const s: String; codePage: Word): WideString;|17:var l: integer;|5:begin|30: if s = ' then Result := '|13: else begin|83: l := MultiByteToWideChar(codePage, MB_PRECOMPOSED, PChar(@s[1]), -1, nil, 0);|31: SetLength(Result, l - 1);|19: if l > 1 then|103: MultiByteToWideChar(CodePage, MB_PRECOMPOSED, PChar(@s[1]), -1, PWideChar(@Result[1]), l - 1);|7: end;|27:end; { StringToWideString }|0:|0:|29:procedure THiAsmClass.doUTF8;|5:begin|51: FResult := UTF8ToStrSmart(ReadString(_Data,Str));|41: _hi_CreateEvent(_Data,@onUTF8,FResult);|4:end;|0:|29:procedure THiAsmClass.Result;|5:begin|26: dtString(_Data,FResult);|4:end;|0:|4:end.|
link(onUTF8,14969934:doAdd,[])
}