Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Entry.cs « locale-builder « tools - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 07beccdb53e307c87b0d278f06fc71758e56252a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
//
//
//

using System;
using System.Text;
using System.Collections;

namespace Mono.Tools.LocaleBuilder {

        public class Entry {

		// maps strings to indexes
		static Hashtable hash;
		static ArrayList string_order;
		// idx 0 is reserved to indicate null
		static int curpos = 1;

		// serialize the strings in Hashtable.
		public static string GetStrings () {
			Console.WriteLine ("Total string data size: {0}", curpos);
			if (curpos > UInt16.MaxValue)
				throw new Exception ("need to increase idx size in culture-info.h");
			StringBuilder ret = new StringBuilder ();
			// the null entry
			ret.Append ("\"\\0\"\n");
			foreach (string s in string_order) {
				ret.Append ("\t\"");
				ret.Append (s);
				ret.Append ("\\0\"\n");
			}
			return ret.ToString ();
		}
		static Entry () {
			hash = new Hashtable ();
			string_order = new ArrayList ();
		}
		static int AddString (string s, int size) {
			object o = hash [s];
			if (o == null) {
				int ret;
				string_order.Add (s);
				ret = curpos;
				hash [s] = curpos;
				curpos += size + 1; // null terminator
				return ret;
			} else {
				return (int)o;
			}
		}

                protected static String EncodeStringIdx (string str)
                {
                        if (str == null)
                                return "0";

                        StringBuilder ret = new StringBuilder ();
                        byte [] ba = new UTF8Encoding ().GetBytes (str);
                        bool in_hex = false;
                        foreach (byte b in ba) {
                                if (b > 127 || (in_hex && is_hex (b))) {
                                        ret.AppendFormat ("\\x{0:x}", b);
                                        in_hex = true;
                                } else {
                                        if (b == '\\')
                                                ret.Append ('\\');
                                        ret.Append ((char) b);
                                        in_hex = false;
                                }
                        }
			int res = AddString (ret.ToString (), ba.Length);
                        return res.ToString ();
                }

                private static bool is_hex (int e)
		{
			return (e >= '0' && e <= '9') || (e >= 'A' && e <= 'F') || (e >= 'a' && e <= 'f');
		}
        }
}