faster replacement on unicode chars
authorAlan Knowles <alan@roojs.com>
Wed, 16 Dec 2020 02:41:00 +0000 (10:41 +0800)
committerAlan Knowles <alan@roojs.com>
Wed, 16 Dec 2020 02:41:00 +0000 (10:41 +0800)
seed/toSVG.js

index 7cdfcb7..1fb9180 100644 (file)
@@ -282,19 +282,10 @@ function toSVG() {
     svg += '</svg>';
 
     
-    function U2A(str)
-    {
-        var ret = '';
-        for (var i = 0;i < str.length; i++) {
-            ret += str.charCodeAt(i) > 254 ? ('&#' + str.charCodeAt(i) + ';') : str.charAt(i);
-        }
-        return ret;
-    }
+    return svg.replace(/[\u00A0-\u2666<>\&]/g, function(c) {
+        return '&#'+c.charCodeAt(0) + ';';
+    });
         
-    return U2A(svg);
-    
-    
     
-    return svg;
 };
  
\ No newline at end of file