コード例 #1
0
        public override void Add(WitResponseNode aItem)
        {
            var tmp = new WitResponseArray();

            tmp.Add(aItem);
            Set(tmp);
        }
コード例 #2
0
        public override void Add(string aKey, WitResponseNode aItem)
        {
            var tmp = new WitResponseClass();

            tmp.Add(aKey, aItem);
            Set(tmp);
        }
コード例 #3
0
        public override WitResponseNode Remove(string aKey)
        {
            if (!m_Dict.ContainsKey(aKey))
            {
                return(null);
            }
            WitResponseNode tmp = m_Dict[aKey];

            m_Dict.Remove(aKey);
            return(tmp);
        }
コード例 #4
0
        public override WitResponseNode Remove(int aIndex)
        {
            if (aIndex < 0 || aIndex >= m_List.Count)
            {
                return(null);
            }
            WitResponseNode tmp = m_List[aIndex];

            m_List.RemoveAt(aIndex);
            return(tmp);
        }
コード例 #5
0
 public override WitResponseNode Remove(WitResponseNode aNode)
 {
     try
     {
         var item = m_Dict.Where(k => k.Value == aNode).First();
         m_Dict.Remove(item.Key);
         return(aNode);
     }
     catch
     {
         return(null);
     }
 }
コード例 #6
0
        private void Set(WitResponseNode aVal)
        {
            if (m_Key == null)
            {
                m_Node.Add(aVal);
            }
            else
            {
                m_Node.Add(m_Key, aVal);
            }

            m_Node = null; // Be GC friendly.
        }
コード例 #7
0
 public override void Add(string aKey, WitResponseNode aItem)
 {
     if (!string.IsNullOrEmpty(aKey))
     {
         if (m_Dict.ContainsKey(aKey))
         {
             m_Dict[aKey] = aItem;
         }
         else
         {
             m_Dict.Add(aKey, aItem);
         }
     }
     else
     {
         m_Dict.Add(Guid.NewGuid().ToString(), aItem);
     }
 }
コード例 #8
0
 public override WitResponseNode Remove(WitResponseNode aNode)
 {
     m_List.Remove(aNode);
     return(aNode);
 }
コード例 #9
0
 public override void Add(string aKey, WitResponseNode aItem)
 {
     m_List.Add(aItem);
 }
コード例 #10
0
 public virtual void Add(string aKey, WitResponseNode aItem)
 {
 }
コード例 #11
0
        public static WitResponseNode Parse(string aJSON)
        {
            Stack <WitResponseNode> stack = new Stack <WitResponseNode>();
            WitResponseNode         ctx   = null;
            int    i         = 0;
            string Token     = "";
            string TokenName = "";
            bool   QuoteMode = false;

            while (i < aJSON.Length)
            {
                switch (aJSON[i])
                {
                case '{':
                    if (QuoteMode)
                    {
                        Token += aJSON[i];
                        break;
                    }

                    stack.Push(new WitResponseClass());
                    if (ctx != null)
                    {
                        TokenName = TokenName.Trim();
                        if (ctx is WitResponseArray)
                        {
                            ctx.Add(stack.Peek());
                        }
                        else if (TokenName != "")
                        {
                            ctx.Add(TokenName, stack.Peek());
                        }
                    }

                    TokenName = "";
                    Token     = "";
                    ctx       = stack.Peek();
                    break;

                case '[':
                    if (QuoteMode)
                    {
                        Token += aJSON[i];
                        break;
                    }

                    stack.Push(new WitResponseArray());
                    if (ctx != null)
                    {
                        TokenName = TokenName.Trim();
                        if (ctx is WitResponseArray)
                        {
                            ctx.Add(stack.Peek());
                        }
                        else if (TokenName != "")
                        {
                            ctx.Add(TokenName, stack.Peek());
                        }
                    }

                    TokenName = "";
                    Token     = "";
                    ctx       = stack.Peek();
                    break;

                case '}':
                case ']':
                    if (QuoteMode)
                    {
                        Token += aJSON[i];
                        break;
                    }

                    if (stack.Count == 0)
                    {
                        throw new JSONParseException("JSON Parse: Too many closing brackets");
                    }

                    stack.Pop();
                    if (Token != "")
                    {
                        TokenName = TokenName.Trim();
                        if (ctx is WitResponseArray)
                        {
                            ctx.Add(Token);
                        }
                        else if (TokenName != "")
                        {
                            ctx.Add(TokenName, Token);
                        }
                    }

                    TokenName = "";
                    Token     = "";
                    if (stack.Count > 0)
                    {
                        ctx = stack.Peek();
                    }
                    break;

                case ':':
                    if (QuoteMode)
                    {
                        Token += aJSON[i];
                        break;
                    }

                    TokenName = Token;
                    Token     = "";
                    break;

                case '"':
                    QuoteMode ^= true;
                    break;

                case ',':
                    if (QuoteMode)
                    {
                        Token += aJSON[i];
                        break;
                    }

                    if (Token != "")
                    {
                        if (ctx is WitResponseArray)
                        {
                            ctx.Add(Token);
                        }
                        else if (TokenName != "")
                        {
                            ctx.Add(TokenName, Token);
                        }
                    }

                    TokenName = "";
                    Token     = "";
                    break;

                case '\r':
                case '\n':
                    break;

                case ' ':
                case '\t':
                    if (QuoteMode)
                    {
                        Token += aJSON[i];
                    }
                    break;

                case '\\':
                    ++i;
                    if (QuoteMode)
                    {
                        char C = aJSON[i];
                        switch (C)
                        {
                        case 't':
                            Token += '\t';
                            break;

                        case 'r':
                            Token += '\r';
                            break;

                        case 'n':
                            Token += '\n';
                            break;

                        case 'b':
                            Token += '\b';
                            break;

                        case 'f':
                            Token += '\f';
                            break;

                        case 'u':
                        {
                            string s = aJSON.Substring(i + 1, 4);
                            Token += (char)int.Parse(s,
                                                     System.Globalization.NumberStyles.AllowHexSpecifier);
                            i += 4;
                            break;
                        }

                        default:
                            Token += C;
                            break;
                        }
                    }

                    break;

                default:
                    Token += aJSON[i];
                    break;
                }

                ++i;
            }

            if (QuoteMode)
            {
                throw new JSONParseException("JSON Parse: Quotation marks seems to be messed up.");
            }

            return(ctx);
        }
コード例 #12
0
 public static WitResponseNode Parse(string aJSON)
 {
     return(WitResponseNode.Parse(aJSON));
 }
コード例 #13
0
 public WitResponseLazyCreator(WitResponseNode aNode, string aKey)
 {
     m_Node = aNode;
     m_Key  = aKey;
 }
コード例 #14
0
 public WitResponseLazyCreator(WitResponseNode aNode)
 {
     m_Node = aNode;
     m_Key  = null;
 }
コード例 #15
0
 public virtual WitResponseNode Remove(WitResponseNode aNode)
 {
     return(aNode);
 }
コード例 #16
0
 public virtual void Add(WitResponseNode aItem)
 {
     Add("", aItem);
 }