diff Implab/Formats/JSON/JSONXmlReader.cs @ 180:c32688129f14 ref20160224

refactoring complete, JSONParser rewritten
author cin
date Thu, 24 Mar 2016 02:30:46 +0300
parents 419aa51b04fd
children 8222a2ab3ab7
line wrap: on
line diff
--- a/Implab/Formats/JSON/JSONXmlReader.cs	Wed Mar 23 19:52:08 2016 +0300
+++ b/Implab/Formats/JSON/JSONXmlReader.cs	Thu Mar 24 02:30:46 2016 +0300
@@ -1,15 +1,11 @@
 using Implab;
-using Implab.Parsing;
 using System;
 using System.Collections.Generic;
 using System.Globalization;
 using System.IO;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
 using System.Xml;
 
-namespace Implab.JSON {
+namespace Implab.Formats.JSON {
     public class JSONXmlReader : XmlReader {
 
         enum ValueContext {
@@ -30,7 +26,7 @@
         ReadState m_state = ReadState.Initial;
         Stack<LocalNameContext> m_localNameStack = new Stack<LocalNameContext>();
         LocalNameContext m_localName;
-        int m_depthCorrection = 0;
+        int m_depthCorrection;
 
         readonly string m_rootName;
         readonly string m_prefix;
@@ -119,8 +115,8 @@
         public override string LookupNamespace(string prefix) {
             if (String.IsNullOrEmpty(prefix) || prefix == m_prefix)
                 return m_namespaceUri;
-            else
-                return String.Empty;
+            
+            return String.Empty;
         }
 
         public override bool MoveToAttribute(string name, string ns) {
@@ -183,11 +179,11 @@
         }
 
         public override bool Read() {
-            if (m_state != System.Xml.ReadState.Interactive && m_state != System.Xml.ReadState.Initial)
+            if (m_state != ReadState.Interactive && m_state != ReadState.Initial)
                 return false;
 
             if (m_state == ReadState.Initial)
-                m_state = System.Xml.ReadState.Interactive;
+                m_state = ReadState.Interactive;
 
             try {
                 switch (m_parser.ElementType) {
@@ -223,9 +219,8 @@
                                 m_depthCorrection--;
                                 SetLocalName(itemName, true);
                                 continue;
-                            } else {
-                                SetLocalName(itemName, true);
                             }
+                            SetLocalName(itemName, true);
                             break;
                         case JSONElementType.BeginObject:
                             SetLocalName(itemName);
@@ -243,16 +238,14 @@
                             SetLocalName(itemName);
                             m_valueContext = m_parser.ElementValue == null ? ValueContext.ElementEmpty : ValueContext.ElementStart;
                             break;
-                        default:
-                            break;
                     }
                     return true;
                 }
 
-                m_state = System.Xml.ReadState.EndOfFile;
+                m_state = ReadState.EndOfFile;
                 return false;
             } catch {
-                m_state = System.Xml.ReadState.Error;
+                m_state = ReadState.Error;
                 throw;
             }
         }
@@ -275,8 +268,7 @@
                     return String.Empty;
                 if (Convert.GetTypeCode(m_parser.ElementValue) == TypeCode.Double)
                     return ((double)m_parser.ElementValue).ToString(CultureInfo.InvariantCulture);
-                else
-                    return m_parser.ElementValue.ToString();
+                return m_parser.ElementValue.ToString();
             }
         }
 
@@ -323,7 +315,7 @@
         /// The reader will be disposed when the XmlReader is disposed.
         /// </remarks>
         public static JSONXmlReader Create(TextReader reader,  JSONXmlReaderOptions options) {
-            return new JSONXmlReader(new JSONParser(reader, true), options);
+            return new JSONXmlReader(new JSONParser(reader), options);
         }
 
         /// <summary>