From c963ee69cf385de1f3b61aa2553b8ac7128b302c Mon Sep 17 00:00:00 2001 From: handa Date: Mon, 8 Jun 2009 15:08:52 +0000 Subject: [PATCH] *** empty log message *** --- MDatabase.cs | 6 ++---- MPlist.cs | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ plist.cs | 3 +-- 3 files changed, 65 insertions(+), 6 deletions(-) diff --git a/MDatabase.cs b/MDatabase.cs index e8ca8e5..017b4e4 100644 --- a/MDatabase.cs +++ b/MDatabase.cs @@ -665,8 +665,7 @@ namespace M17N.Core MPlist plist = null; using (FileStream stream = File.OpenRead (dblist.FullName)) { - MStreamReader reader = new MStreamReader (stream); - plist = new MPlist (reader); + plist = new MPlist (stream); } if (plist == null) return; @@ -723,8 +722,7 @@ namespace M17N.Core MPlist plist = null; using (FileStream stream = fileinfo.OpenRead ()) { - MStreamReader reader = new MStreamReader (stream); - plist = new MPlist (reader, 1); + plist = new MPlist (stream, 1); } if (plist != null && plist.IsPlist) { diff --git a/MPlist.cs b/MPlist.cs index 8a040ec..d2f7325 100644 --- a/MPlist.cs +++ b/MPlist.cs @@ -18,6 +18,68 @@ namespace M17N.Core Val = null; } + public MPlist (FileStream stream) + { + MStreamReader reader = new MStreamReader (stream); + MSymbol key; + object val; + bool result = reader.ReadElement (out key, out val); + + Key = key; + Val = val; + if (result) + next = new MPlist (reader); + } + + public MPlist (FileStream stream, int count) + { + MStreamReader reader = new MStreamReader (stream); + MSymbol key; + object val; + bool result = reader.ReadElement (out key, out val); + + Key = key; + Val = val; + if (result && --count > 0) + next = new MPlist (reader, count); + else + next = new MPlist (); + } + + public MPlist (FileStream stream, MSymbol target, MSymbol stop) + { + MStreamReader reader = new MStreamReader (stream); + MSymbol key; + object val; + bool result; + + Key = MSymbol.nil; + Val = null; + while (true) + { + result = reader.ReadElement (out key, out val); + if (! result) + return; + if (key == MSymbol.plist) + { + MPlist plist = (MPlist) val; + + if (plist.IsSymbol) + { + if (plist.Symbol == stop) + return; + if (plist.Symbol == target) + { + Key = target; + Val = val; + next = new MPlist (); + return; + } + } + } + } + } + public MPlist (MStreamReader reader) { MSymbol key; diff --git a/plist.cs b/plist.cs index 2b70511..4a305c8 100644 --- a/plist.cs +++ b/plist.cs @@ -26,8 +26,7 @@ public class Test using (FileStream stream = File.OpenRead ("temp.plist")) { - MStreamReader reader = new MStreamReader (stream); - Console.WriteLine (new MPlist (reader)); + Console.WriteLine (new MPlist (stream)); } plist = new MPlist (); -- 1.7.10.4