{
#if false
public enum MTextFormat
- {
- MTEXT_FORMAT_US_ASCII,
- MTEXT_FORMAT_UTF_8,
- MTEXT_FORMAT_UTF_16BE,
- MTEXT_FORMAT_UTF_16LE,
- MTEXT_FORMAT_UTF_32BE,
- MTEXT_FORMAT_UTF_32LE,
- }
+ {
+ MTEXT_FORMAT_US_ASCII,
+ MTEXT_FORMAT_UTF_8,
+ MTEXT_FORMAT_UTF_16BE,
+ MTEXT_FORMAT_UTF_16LE,
+ MTEXT_FORMAT_UTF_32BE,
+ MTEXT_FORMAT_UTF_32LE,
+ }
#endif
public class MTextProperty
}
}
- public class MText
+ public class MText : IEnumerable, IComparable<MText>, IEquatable<MText>
{
#if false
public enum MTextFormat format;
{
int len = str.Length, n = 0;
- for (int i = 0; i < len; i++)
- n += surrogate_high_p (str[i]) ? 2 : 1;
+ for (int i = 0; i < len; i++, n++)
+ if (surrogate_high_p (str[i]))
+ i++;
return n;
}
{
int len = str.Length, n = 0;
- for (int i = 0; i < len; i++)
- n += surrogate_high_p (str[i]) ? 2 : 1;
+ for (int i = 0; i < len; i++, n++)
+ if (surrogate_high_p (str[i]))
+ i++;
return n;
}
public MText ()
- {
- sb = new StringBuilder ();
- }
+ {
+ sb = new StringBuilder ();
+ }
public MText (byte[] str)
- {
- sb = new StringBuilder (utf8.GetString (str));
- nchars = count_chars (sb);
- }
+ {
+ sb = new StringBuilder (utf8.GetString (str));
+ nchars = count_chars (sb);
+ }
public MText (String str)
- {
- sb = new StringBuilder (str);
- nchars = count_chars (str);
- }
+ {
+ sb = new StringBuilder (str);
+ nchars = count_chars (str);
+ }
public MText (StringBuilder str)
- {
- sb = str;
- nchars = count_chars (str);
- }
+ {
+ sb = str;
+ nchars = count_chars (str);
+ }
public static MText operator+ (MText mt1, MText mt2)
{
- MText mt = new MText (mt1.sb.ToString);
+ MText mt = new MText ();
+ mt.sb.Append (mt1.sb);
mt.sb.Append (mt2.sb);
mt.nchars = mt1.nchars + mt2.nchars;
return mt;
}
public bool ReadOnly { get { return read_only; } }
+ public int Length { get { return nchars; } }
+
+ public int CompareTo (MText other)
+ {
+ return this.sb.ToString ().CompareTo (other.sb.ToString ());
+ }
- public override string ToString ()
+ public bool Equals (MText other)
+ {
+ return this.sb.Equals (other.sb);
+ }
+
+ public override String ToString ()
{
return sb.ToString ();
}
root_interval.Push (from, to, prop);
}
+ public IEnumerator GetEnumerator()
+ {
+ return new MTextEnum (this);
+ }
+
private class MInterval
{
// Start and end positions of this interval and its children.
stack.Push (prop);
}
}
+
+ private class MTextEnum : IEnumerator
+ {
+ private MText mt;
+ private int pos = -1;
+
+ public MTextEnum (MText mt)
+ {
+ this.mt = mt;
+ }
+
+ public bool MoveNext ()
+ {
+ pos++;
+ return (pos < mt.nchars);
+ }
+
+ public void Reset ()
+ {
+ pos = -1;
+ }
+
+ public object Current
+ {
+ get {
+ //if (pos < 0 || pos >= mt.nchars)
+ //throw new InvalidOperationException ();
+ return mt[pos];
+ }
+ }
+ }
}
}
MText mt = new MText ("a𝄀あc");
MText mt2;
- Console.WriteLine (mt[0]);
- Console.WriteLine (mt[1]);
- Console.WriteLine (mt[2]);
- Console.WriteLine (mt[3]);
+ Console.WriteLine ("Length={0}", mt.Length);
+ foreach (int c in mt)
+ Console.WriteLine ("U+{0:X4}", c);
Console.WriteLine (mt + new MText ("漢字"));
mt2 = mt.dup ();
mt[1] = 'b';
Console.WriteLine (mt2);
-
- List<int> list = new List<int>();
-
- list.Add (1);
- list.Add (2);
- for (int i = 0; i < 2; i++)
- Console.WriteLine (list[i]);
}
}