From: handa Date: Tue, 9 Jun 2009 02:28:35 +0000 (+0000) Subject: *** empty log message *** X-Git-Url: http://git.chise.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=640fdcb685e5063b6bc7d17e1acf5545b7b66548;p=m17n%2Fm17n-lib-cs.git *** empty log message *** --- diff --git a/MPlist.cs b/MPlist.cs index d2f7325..5b5cd5f 100644 --- a/MPlist.cs +++ b/MPlist.cs @@ -80,7 +80,7 @@ namespace M17N.Core } } - public MPlist (MStreamReader reader) + private MPlist (MStreamReader reader) { MSymbol key; object val; @@ -92,7 +92,7 @@ namespace M17N.Core next = new MPlist (reader); } - public MPlist (MStreamReader reader, int count) + private MPlist (MStreamReader reader, int count) { MSymbol key; object val; @@ -106,7 +106,7 @@ namespace M17N.Core next = new MPlist (); } - public MPlist (MStreamReader reader, MSymbol target, MSymbol stop) + private MPlist (MStreamReader reader, MSymbol target, MSymbol stop) { MSymbol key; object val; @@ -363,222 +363,222 @@ namespace M17N.Core return (! current.IsEmpty); } } - } - public class MStreamReader : StreamReader - { - private static char[] escaped_char = new char[128]; - private static int[] hexadecimal = new int[128]; + private class MStreamReader : StreamReader + { + private static char[] escaped_char = new char[128]; + private static int[] hexadecimal = new int[128]; - public MStreamReader (Stream stream) : base (stream) - { - } + public MStreamReader (Stream stream) : base (stream) + { + } + + static MStreamReader () + { + for (int i = 0; i < 128; i++) + escaped_char[i] = (char) i; + escaped_char['e'] = (char) 27; + escaped_char['b'] = '\b'; + escaped_char['f'] = '\f'; + escaped_char['n'] = '\n'; + escaped_char['r'] = '\r'; + escaped_char['t'] = '\t'; + escaped_char['\\'] = '\\'; + for (int i = 0; i < 128; i++) + hexadecimal[i] = -1; + for (int i = '0'; i <= '9'; i++) + hexadecimal[i] = i - '0'; + for (int i = 'A'; i <= 'F'; i++) + hexadecimal[i] = hexadecimal[i + 'a' - 'A'] = i -'A' + 10; + } - static MStreamReader () + internal int PeekChar () { - for (int i = 0; i < 128; i++) - escaped_char[i] = (char) i; - escaped_char['e'] = (char) 27; - escaped_char['b'] = '\b'; - escaped_char['f'] = '\f'; - escaped_char['n'] = '\n'; - escaped_char['r'] = '\r'; - escaped_char['t'] = '\t'; - escaped_char['\\'] = '\\'; - for (int i = 0; i < 128; i++) - hexadecimal[i] = -1; - for (int i = '0'; i <= '9'; i++) - hexadecimal[i] = i - '0'; - for (int i = 'A'; i <= 'F'; i++) - hexadecimal[i] = hexadecimal[i + 'a' - 'A'] = i -'A' + 10; + bool comment = false; + int c; + + while ((c = Peek ()) != -1) + { + if (comment) + { + if ((c = Read ()) == '\n') + comment = false; + } + else + { + if (c == ';') + comment = true; + else if (c != ' ' && c != '\t' && c != '\n') + return c; + Read (); + } + } + return c; } - internal int PeekChar () - { - bool comment = false; - int c; + internal int ReadHexadecimal () + { + int i = 0, c; - while ((c = Peek ()) != -1) - { - if (comment) - { - if ((c = Read ()) == '\n') - comment = false; - } - else - { - if (c == ';') - comment = true; - else if (c != ' ' && c != '\t' && c != '\n') - return c; - Read (); - } - } - return c; - } + while ((c = Peek ()) >= 0 && c < 128 && (c = hexadecimal[c]) >= 0) + { + Read (); + i = (i * 16) + c; + } + return i; + } - internal int ReadHexadecimal () - { - int i = 0, c; + internal int ReadInteger () + { + int i = 0, c; - while ((c = Peek ()) >= 0 && c < 128 && (c = hexadecimal[c]) >= 0) - { - Read (); - i = (i * 16) + c; - } - return i; - } + while ((c = Peek ()) >= '0' && c <= '9') + i = (i * 10) + (Read () - '0'); + return i; + } - internal int ReadInteger () - { - int i = 0, c; + internal int ReadChar () + { + int c = Read (); - while ((c = Peek ()) >= '0' && c <= '9') - i = (i * 10) + (Read () - '0'); - return i; - } + if (c == '\\') + { + c = Read (); + if (c == -1) + return -1; + if (c == 'x' || c == 'u') + return ReadHexadecimal (); + if (c < 128) + c = escaped_char[c]; + } + return c; + } - internal int ReadChar () - { - int c = Read (); + internal MText ReadMtext () + { + MText mt = new MText (); + int c; - if (c == '\\') - { - c = Read (); - if (c == -1) - return -1; - if (c == 'x' || c == 'u') - return ReadHexadecimal (); - if (c < 128) - c = escaped_char[c]; - } - return c; - } + while ((c = Peek ()) != -1 && c != '"') + { + if (c == '\\') + { + c = ReadChar (); + if (Peek () == '\n') + { + ReadChar (); + continue; + } + if (c == -1) + { + mt.Cat ('\\'); + break; + } + mt.Cat (c); + } + else + mt.Cat (Read ()); + } + if (c == '"') + Read (); + return mt; + } - internal MText ReadMtext () - { - MText mt = new MText (); - int c; + internal string ReadSymbolName () + { + int c = Peek (); - while ((c = Peek ()) != -1 && c != '"') - { - if (c == '\\') - { - c = ReadChar (); - if (Peek () == '\n') - { - ReadChar (); - continue; - } - if (c == -1) - { - mt.Cat ('\\'); - break; - } - mt.Cat (c); - } - else - mt.Cat (Read ()); - } - if (c == '"') + if (c == -1 || c == '(' || c == ')' || c == ' ' || c == '\n' || c == '"') + return ""; Read (); - return mt; - } + if (c == '\\') + { + c = Read (); + if (c == -1) + c = '\\'; + } + return (char) c + ReadSymbolName (); + } - internal string ReadSymbolName () - { - int c = Peek (); + internal bool ReadElement (out MSymbol key, out object val) + { + int c = PeekChar (); - if (c == -1 || c == '(' || c == ')' || c == ' ' || c == '\n' || c == '"') - return ""; - Read (); - if (c == '\\') - { - c = Read (); - if (c == -1) - c = '\\'; - } - return (char) c + ReadSymbolName (); - } + if (c == '(') + { + Read (); + val = new MPlist (this); + key = MSymbol.plist; + } + else if (c == '"') + { + Read (); + val = ReadMtext (); + key = MSymbol.mtext; + } + else if (c >= '0' && c <= '9') + { + int i = ReadInteger (); - internal bool ReadElement (out MSymbol key, out object val) - { - int c = PeekChar (); + val = i; + key = MSymbol.integer; + } + else if (c == '-') + { + Read (); + c = Peek (); + if (c >= '0' && c <= '9') + { + int i = ReadInteger (); + val = - i; + key = MSymbol.integer; + } + else + { + string str = ReadSymbolName (); - if (c == '(') - { - Read (); - val = new MPlist (this); - key = MSymbol.plist; - } - else if (c == '"') - { - Read (); - val = ReadMtext (); - key = MSymbol.mtext; - } - else if (c >= '0' && c <= '9') - { - int i = ReadInteger (); + val = MSymbol.Of ("-" + str); + key = MSymbol.symbol; + } + } + else if (c == '?') + { + Read (); + val = ReadChar (); + key = MSymbol.integer; + } + else if (c == '#') + { + Read (); + if ((c = Peek ()) == 'x' || c == 'u') + { + Read (); + val = ReadHexadecimal (); + key = MSymbol.integer; + } + else + { + string str = ReadSymbolName (); - val = i; - key = MSymbol.integer; - } - else if (c == '-') - { - Read (); - c = Peek (); - if (c >= '0' && c <= '9') - { - int i = ReadInteger (); - val = - i; - key = MSymbol.integer; - } - else - { - string str = ReadSymbolName (); - - val = MSymbol.Of ("-" + str); - key = MSymbol.symbol; - } - } - else if (c == '?') - { - Read (); - val = ReadChar (); - key = MSymbol.integer; - } - else if (c == '#') - { - Read (); - if ((c = Peek ()) == 'x' || c == 'u') - { + val = MSymbol.Of ("#" + (char) c + str); + key = MSymbol.symbol; + } + } + else if (c == -1 || c == ')') + { + if (c == ')') Read (); - val = ReadHexadecimal (); - key = MSymbol.integer; - } - else - { - string str = ReadSymbolName (); - - val = MSymbol.Of ("#" + (char) c + str); - key = MSymbol.symbol; - } - } - else if (c == -1 || c == ')') - { - if (c == ')') - Read (); - val = null; - key = MSymbol.nil; - return false; - } - else - { - val = MSymbol.Of (ReadSymbolName ()); - key = MSymbol.symbol; - } - return true; + val = null; + key = MSymbol.nil; + return false; + } + else + { + val = MSymbol.Of (ReadSymbolName ()); + key = MSymbol.symbol; + } + return true; + } } } }