8 public enum MTextFormat
10 MTEXT_FORMAT_US_ASCII,
12 MTEXT_FORMAT_UTF_16BE,
13 MTEXT_FORMAT_UTF_16LE,
14 MTEXT_FORMAT_UTF_32BE,
15 MTEXT_FORMAT_UTF_32LE,
22 public enum MTextFormat format;
25 private class MTextPlist : MPlist
27 public class MInterval
31 public int start, end;
32 public MInterval prev, next;
37 public MTextPlist (MText mt)
39 head = tail = new MInterval ();
41 head.end = mt.sb.Length;
45 private StringBuilder sb;
46 private int cache_pos;
47 private int cache_idx;
48 private MTextPlist plist;
50 private static UTF8Encoding utf8 = new UTF8Encoding ();
51 private static UTF32Encoding utf32 = new UTF8Encoding ();
55 cache_pos = cache_idx = 0;
57 sb = new StringBuilder ();
60 public MText (byte[] str)
62 sb = new StringBuilder (utf8.GetString (str));
65 public MText (String str)
67 sb = new StringBuilder (str);
70 private static int inc_idx (int i)
72 return ((sb[i] >= 0xD800 && sb[i] < 0xDC00)
76 private static int dec_idx (int i)
78 return ((sb[i - 1] >= 0xDC00 && sb[i - 1] < 0xE000)
82 private static int pos_to_idx (int pos)
89 if (cache_pos == cache_idx)
91 if (pos < cache_pos - pos)
98 p = cache_pos; i = cache_idx;
104 if (nchars - cache_pos == sb.Length - cache_idx)
105 return (cache_idx + pos - cache_pos);
106 if (pos - cache_pos < nchars - pos)
108 p = char_pos; i = char_idx;
113 p = nchars; i = sb.Length;
118 for (; p < pos; i = inc_idx (i), p++);
120 for (; p > pos; i = dec_idx (i), p--);
126 public int this[int i]
132 this.sb[i] = (char) value;
138 get { return this.sb[i]; }
141 public class MTextProperty