public ListOrValue getValueByKeyName(string keyName) { var val = new ListOrValue(); if (!isList()) { return(val); // should be list to find a value by key name } var len = m_list.Count; if (len % 2 != 0) { return(val); // an 'object' list shoul have a pair number of items } for (var i = 0; i < len; i += 2) { var key = m_list[i]; if (key.isList()) { return(new ListOrValue()); // if a given } if (!val.isDefault()) { continue; // even after finding the value should continue looking if the list is indeed a valid object list } if (key.m_value.extract() == keyName) { val = m_list[i + 1]; } } return(val); // the found item or default if none was found }
public static ListOrValue parseRoot(TokenPos[] tokens) { //ListOrValue retVal = new ListOrValue(); if (tokens == null || tokens.Length < 1) { return(new ListOrValue()); } var tok = new TokenPos( tokens[0].getSource(), TokenType.document, 0, tokens[0].sourceLength() //retVal.tokenSectionLength() //retVal.m_value.m_source.Length ); ListOrValue retVal = new ListOrValue(new List <ListOrValue>(), tok); //retVal.m_value.m_type = TokenType.document; //retVal.m_value.m_start = 0; //retVal.m_value.m_source = tokens[0].m_source; //retVal.m_value.m_end = retVal.m_value.m_source.Length; //retVal.m_list = new List<ListOrValue>(); var tokensLength = tokens.Length; int idx = 0; while (idx < tokensLength) { var item = parseToken(tokens, idx, out idx); if (item.isDefault()) { continue; } retVal.add(item); } if (retVal.count() < 1) { return(new ListOrValue()); } return(retVal); }
public static ListOrValue parseToken(TokenPos[] tokens, int curIdx, out int nextIdx) { nextIdx = curIdx + 1; //ListOrValue curListOrVal = new ListOrValue(); var curTok = tokens[curIdx]; var tokensLength = tokens.Length; if (curTok.getType() == TokenType.neutral) { return(new ListOrValue()); } //ListOrValue curListOrVal = new ListOrValue(null, curTok); //curListOrVal.m_value = curTok; if (curTok.getType() != TokenType.list) { return(new ListOrValue(null, curTok)); } // is list ListOrValue curListOrVal = new ListOrValue(new List <ListOrValue>(), curTok); //curListOrVal.m_list = new List<ListOrValue>(); while (nextIdx < tokensLength) { if (tokens[nextIdx].getStart() >= curTok.getEnd()) { break; } var item = parseToken(tokens, nextIdx, out nextIdx); if (item.isDefault()) { continue; } curListOrVal.add(item); } return(curListOrVal); }
public void add(ListOrValue listOrValue) { m_list.Add(listOrValue); }