function EncodeJSStr(const value: Widestring): Widestring; var P: PWideChar; begin Result := ''; P := PWideChar(value); while P^ <> #0 do begin case P^ of '"', '\', '/': Result := Result + '\' + P^; #$08: Result := Result + '\b'; #$0C: Result := Result + '\f'; #$0A: Result := Result + '\n'; #$0D: Result := Result + '\r'; #$09: Result := Result + '\t'; else if WORD(P^) > $FF then Result := Result + LowerCase(Format('\u%x', [WORD(P^)])) else Result := Result + P^; end; inc(P); end; end; function DecodeJSStr(const value: Widestring): Widestring; var P: PWideChar; v: WideChar; tmp: Widestring; begin Result := ''; P := PWideChar(value); while P^ <> #0 do begin v := #0; case P^ of '\': begin inc(P); case P^ of '"', '\', '/': v := P^; 'b': v := #$08; 'f': v := #$0C; 'n': v := #$0A; 'r': v := #$0D; 't': v := #$09; 'u': begin tmp := Copy(P, 2, 4); v := WideChar(StrToInt('$' + tmp)); inc(P, 4); end; end; end; else v := P^; end; Result := Result + v; inc(P); end; end; |
Copyright © 2014 DelphiW.com 开发 源码 文档 技巧 All Rights Reserved
晋ICP备14006235号-8 晋公网安备 14108102000087号
执行时间: 0.042152166366577 seconds