private MTextPlist plist;
private static UTF8Encoding utf8 = new UTF8Encoding ();
+ private static UTF32Encoding utf32 = new UTF8Encoding ();
public MText ()
{
public MText (byte[] str)
{
- cache_pos = cache_idx = 0;
- plist = null;
sb = new StringBuilder (utf8.GetString (str));
}
public MText (String str)
{
- cache_pos = cache_idx = 0;
- plist = null;
sb = new StringBuilder (str);
}
+ private static int inc_idx (int i)
+ {
+ return ((sb[i] >= 0xD800 && sb[i] < 0xDC00)
+ ? i + 2 : i + 1);
+ }
+
+ private static int dec_idx (int i)
+ {
+ return ((sb[i - 1] >= 0xDC00 && sb[i - 1] < 0xE000)
+ ? i - 2 : i - 1);
+ }
+
+ private static int pos_to_idx (int pos)
+ {
+ int p, i;
+ bool forward;
+
+ if (pos < cache_pos)
+ {
+ if (cache_pos == cache_idx)
+ return cache_idx;
+ if (pos < cache_pos - pos)
+ {
+ p = i = 0;
+ forward = true;
+ }
+ else
+ {
+ p = cache_pos; i = cache_idx;
+ forward = false;
+ }
+ }
+ else
+ {
+ if (nchars - cache_pos == sb.Length - cache_idx)
+ return (cache_idx + pos - cache_pos);
+ if (pos - cache_pos < nchars - pos)
+ {
+ p = char_pos; i = char_idx;
+ forward = true;
+ }
+ else
+ {
+ p = nchars; i = sb.Length;
+ forward = false;
+ }
+ }
+ if (forward)
+ for (; p < pos; i = inc_idx (i), p++);
+ else
+ for (; p > pos; i = dec_idx (i), p--);
+ cache_pos = p;
+ cache_idx = i;
+ return i;
+ }
+
public int this[int i]
{
- set { this.sb[i] = (char) value; }
+ set {
+ if (i != cache_pos)
+ i = pos_to_idx (i);
+ if (value < 0x10000)
+ this.sb[i] = (char) value;
+ else
+ {
+
+ }
+ }
get { return this.sb[i]; }
}
- }
public class MTextProperty
{