hedgewars/uUtils.pas
branchwebgl
changeset 8833 c13ebed437cb
parent 8444 75db7bb8dce8
parent 8575 228fbb2a76a4
child 8841 338f7c2bac2c
--- a/hedgewars/uUtils.pas	Wed Feb 20 02:21:58 2013 +0100
+++ b/hedgewars/uUtils.pas	Tue Apr 02 21:00:57 2013 +0200
@@ -87,6 +87,9 @@
 procedure AudioServicesPlaySystemSound(num: LongInt); cdecl; external;
 {$ENDIF}
 
+function  sanitizeForLog(s: shortstring): shortstring;
+function  sanitizeCharForLog(c: char): shortstring;
+
 procedure initModule(isNotPreview: boolean);
 procedure freeModule;
 
@@ -375,15 +378,15 @@
     if (#$1100  <= u) and  (
                            (u <= #$11FF )  or // Hangul Jamo
        ((#$2E80  <= u) and (u <= #$2FDF))  or // CJK Radicals Supplement / Kangxi Radicals
-       ((#$2FF0  <= u) and (u <= #$303F))  or // Ideographic Description Characters / CJK Radicals Supplement
-       ((#$3130  <= u) and (u <= #$318F))  or // Hangul Compatibility Jamo
+       ((#$2FF0  <= u) and (u <= #$31FF))  or // Ideographic Description Characters / CJK Radicals Supplement / Hiragana / Hangul Compatibility Jamo / Katakana
        ((#$31C0  <= u) and (u <= #$31EF))  or // CJK Strokes
-       ((#$3200  <= u) and (u <= #$4DBF))  or // Enclosed CJK Letters and Months / CJK Compatibility / CJK Unified Ideographs Extension A
+       ((#$3200  <= u) and (u <= #$4DBF))  or // Enclosed CJK Letters and Months / CJK Compatibility / CJK Unified Ideographs Extension A / Circled Katakana
        ((#$4E00  <= u) and (u <= #$9FFF))  or // CJK Unified Ideographs
        ((#$AC00  <= u) and (u <= #$D7AF))  or // Hangul Syllables
        ((#$F900  <= u) and (u <= #$FAFF))  or // CJK Compatibility Ideographs
-       ((#$FE30  <= u) and (u <= #$FE4F)))    // CJK Compatibility Forms
-       then
+       ((#$FE30  <= u) and (u <= #$FE4F))  or // CJK Compatibility Forms
+       ((#$FF66  <= u) and (u <= #$FF9D)))    // halfwidth katakana
+       then 
         begin
             CheckCJKFont:=  THWFont( ord(font) + ((ord(High(THWFont))+1) div 2) );
             exit;
@@ -458,6 +461,31 @@
 {$ENDIF}
 end;
 
+function  sanitizeForLog(s: shortstring): shortstring;
+var i: byte;
+    r: shortstring;
+begin
+    r[0]:= s[0];
+    for i:= 1 to length(s) do
+        if (s[i] < #32) or (s[i] > #127) then
+            r[i]:= '?'
+            else
+            r[i]:= s[i];
+            
+    sanitizeForLog:= r
+end;
+
+function  sanitizeCharForLog(c: char): shortstring;
+var r: shortstring;
+begin
+    if (c < #32) or (c > #127) then
+        r:= '#' + inttostr(byte(c))
+        else
+        r:= c;
+            
+    sanitizeCharForLog:= r
+end;
+
 procedure initModule(isNotPreview: boolean);
 {$IFDEF DEBUGFILE}
 var logfileBase: shortstring;