瀏覽代碼

* Add EncodeHTMLEntities

michael 5 年之前
父節點
當前提交
116614c42c
共有 1 個文件被更改,包括 14 次插入0 次删除
  1. 14 0
      packages/rtl/sysutils.pas

+ 14 - 0
packages/rtl/sysutils.pas

@@ -626,6 +626,8 @@ function IsEqualGUID(const guid1, guid2: TGuid): Boolean;
 function GuidCase(const guid: TGuid; const List: array of TGuid): Integer;
 Function CreateGUID(out GUID : TGUID) : Integer;
 
+Function EncodeHTMLEntities (S : String) : String;
+
 implementation
 
 procedure ShowException(ExceptObject: TObject; ExceptAddr: Pointer);
@@ -4427,5 +4429,17 @@ begin
     Result := '';
 end;
 
+Function EncodeHTMLEntities (S : String) : String;
+
+begin
+  Result:='';
+  if S='' then exit;
+  asm
+   return S.replace(/[\u00A0-\u9999<>\&]/gim, function(i) {
+     return '&#'+i.charCodeAt(0)+';';
+   });
+  end;
+end;
+
 end.