This commit was manufactured by cvs2svn to create branch 'mono-1-0'.
[mono.git] / tools / locale-builder / Entry.cs
1 //
2 //
3 //
4
5 using System;
6 using System.Text;
7
8 namespace Mono.Tools.LocaleBuilder {
9
10         public class Entry {
11
12                 protected static String EncodeString (string str)
13                 {
14                         if (str == null)
15                                 return String.Empty;
16
17                         StringBuilder ret = new StringBuilder ();
18                         byte [] ba = new UTF8Encoding ().GetBytes (str);
19                         bool in_hex = false;
20                         foreach (byte b in ba) {
21                                 if (b > 127 || (in_hex && is_hex (b))) {
22                                         ret.AppendFormat ("\\x{0:x}", b);
23                                         in_hex = true;
24                                 } else {
25                                         if (b == '\\')
26                                                 ret.Append ('\\');
27                                         ret.Append ((char) b);
28                                         in_hex = false;
29                                 }
30                         }
31                         return ret.ToString ();
32                 }
33
34                 private static bool is_hex (int e)
35                 {
36                         return (e >= '0' && e <= '9') || (e >= 'A' && e <= 'F') || (e >= 'a' && e <= 'f');
37                 }
38         }
39 }
40
41
42
43