private static LLSD DeserializeNotationArray(StringReader reader) { int character; LLSDArray llsdArray = new LLSDArray(); while (((character = PeekAndSkipWhitespace(reader)) > 0) && ((char)character != arrayEndNotationMarker)) { llsdArray.Add(DeserializeNotationElement(reader)); character = ReadAndSkipWhitespace(reader); if (character < 0) { throw new LLSDException("Notation LLSD parsing: Unexpected end of array discovered."); } else if ((char)character == kommaNotationDelimiter) { continue; } else if ((char)character == arrayEndNotationMarker) { break; } } if (character < 0) { throw new LLSDException("Notation LLSD parsing: Unexpected end of array discovered."); } return((LLSD)llsdArray); }
private static LLSDArray ParseXmlArray(XmlTextReader reader) { if (reader.NodeType != XmlNodeType.Element || reader.LocalName != "array") { throw new LLSDException("Expected <array>"); } LLSDArray array = new LLSDArray(); if (reader.IsEmptyElement) { reader.Read(); return(array); } if (reader.Read()) { while (true) { SkipWhitespace(reader); if (reader.NodeType == XmlNodeType.EndElement && reader.LocalName == "array") { reader.Read(); break; } array.Add(ParseXmlElement(reader)); } } return(array); }
private static LLSD ParseBinaryArray(MemoryStream stream) { int numElements = NetworkToHostInt(ConsumeBytes(stream, int32Length)); int crrElement = 0; LLSDArray llsdArray = new LLSDArray(); while (crrElement < numElements) { llsdArray.Add(ParseBinaryElement(stream)); crrElement++; } if (!FindByte(stream, arrayEndBinaryMarker)) { throw new LLSDException("Binary LLSD parsing: Missing end marker in array."); } return((LLSD)llsdArray); }
private static LLSD ParseNotationElement(string notationData, out int endPos) { if (notationData.Length == 0) { endPos = 0; return(null); } // Identify what type of object this is switch (notationData[0]) { case '!': endPos = 1; return(new LLSD()); case '1': endPos = 1; return(LLSD.FromBoolean(true)); case '0': endPos = 1; return(LLSD.FromBoolean(false)); case 'i': { if (notationData.Length < 2) { endPos = notationData.Length; return(LLSD.FromInteger(0)); } int value; endPos = FindEnd(notationData, 1); if (Helpers.TryParse(notationData.Substring(1, endPos - 1), out value)) { return(LLSD.FromInteger(value)); } else { return(LLSD.FromInteger(0)); } } case 'r': { if (notationData.Length < 2) { endPos = notationData.Length; return(LLSD.FromReal(0d)); } double value; endPos = FindEnd(notationData, 1); if (Helpers.TryParse(notationData.Substring(1, endPos - 1), out value)) { return(LLSD.FromReal(value)); } else { return(LLSD.FromReal(0d)); } } case 'u': { if (notationData.Length < 17) { endPos = notationData.Length; return(LLSD.FromUUID(LLUUID.Zero)); } LLUUID value; endPos = FindEnd(notationData, 1); if (Helpers.TryParse(notationData.Substring(1, endPos - 1), out value)) { return(LLSD.FromUUID(value)); } else { return(LLSD.FromUUID(LLUUID.Zero)); } } case 'b': throw new NotImplementedException("Notation binary type is unimplemented"); case 's': case '"': case '\'': if (notationData.Length < 2) { endPos = notationData.Length; return(LLSD.FromString(String.Empty)); } endPos = FindEnd(notationData, 1); return(LLSD.FromString(notationData.Substring(1, endPos - 1).Trim(new char[] { '"', '\'' }))); case 'l': throw new NotImplementedException("Notation URI type is unimplemented"); case 'd': throw new NotImplementedException("Notation date type is unimplemented"); case '[': { if (notationData.IndexOf(']') == -1) { throw new LLSDException("Invalid notation array"); } int pos = 0; LLSDArray array = new LLSDArray(); while (notationData[pos] != ']') { ++pos; // Advance past comma if need be if (notationData[pos] == ',') { ++pos; } // Allow a single whitespace character if (pos < notationData.Length && notationData[pos] == ' ') { ++pos; } int end; array.Add(ParseNotationElement(notationData.Substring(pos), out end)); pos += end; } endPos = pos + 1; return(array); } case '{': { if (notationData.IndexOf('}') == -1) { throw new LLSDException("Invalid notation map"); } int pos = 0; LLSDMap hashtable = new LLSDMap(); while (notationData[pos] != '}') { ++pos; // Advance past comma if need be if (notationData[pos] == ',') { ++pos; } // Allow a single whitespace character if (pos < notationData.Length && notationData[pos] == ' ') { ++pos; } if (notationData[pos] != '\'') { throw new LLSDException("Expected a map key"); } int endquote = notationData.IndexOf('\'', pos + 1); if (endquote == -1 || (endquote + 1) >= notationData.Length || notationData[endquote + 1] != ':') { throw new LLSDException("Invalid map format"); } string key = notationData.Substring(pos, endquote - pos); key = key.Trim(new char[] { '"', '\'' }); //key.Replace("'", String.Empty); pos += (endquote - pos) + 2; int end; hashtable[key] = ParseNotationElement(notationData.Substring(pos), out end); pos += end; } endPos = pos + 1; return(hashtable); } default: throw new LLSDException("Unknown notation value type"); } }