public override void Add(WitResponseNode aItem) { var tmp = new WitResponseArray(); tmp.Add(aItem); Set(tmp); }
public override void Add(string aKey, WitResponseNode aItem) { var tmp = new WitResponseClass(); tmp.Add(aKey, aItem); Set(tmp); }
public override WitResponseNode Remove(string aKey) { if (!m_Dict.ContainsKey(aKey)) { return(null); } WitResponseNode tmp = m_Dict[aKey]; m_Dict.Remove(aKey); return(tmp); }
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); }
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); } }
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. }
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); } }
public override WitResponseNode Remove(WitResponseNode aNode) { m_List.Remove(aNode); return(aNode); }
public override void Add(string aKey, WitResponseNode aItem) { m_List.Add(aItem); }
public virtual void Add(string aKey, WitResponseNode aItem) { }
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); }
public static WitResponseNode Parse(string aJSON) { return(WitResponseNode.Parse(aJSON)); }
public WitResponseLazyCreator(WitResponseNode aNode, string aKey) { m_Node = aNode; m_Key = aKey; }
public WitResponseLazyCreator(WitResponseNode aNode) { m_Node = aNode; m_Key = null; }
public virtual WitResponseNode Remove(WitResponseNode aNode) { return(aNode); }
public virtual void Add(WitResponseNode aItem) { Add("", aItem); }