public static dynamic GetValue(this JyndData data, JyndItem item) { switch (data.Source[item.Data]) { case '"': return(data.GetText(item)); case '{': return(data.GetObject(item)); case '[': return(data.GetArray(item)); case 'n': return(data.GetNull(item)); case 't': return(data.GetTrue(item)); case 'f': return(data.GetFalse(item)); default: return(data.GetNumber(item)); } }
public void AddItem(short indexInstance, ushort data, short dataLength, short dataInstance) { items[count++] = new JyndItem { IndexInstance = indexInstance, Data = data, DataLength = dataLength, DataInstance = dataInstance }; }
public void AddIndexed(ushort index, byte indexLength, short indexInstance, ushort data, short dataLength, short dataInstance) { ushort hash = ToHash(source, index, indexLength); hashes[hash] = (short)count; items[count++] = new JyndItem { Hash = hash, Index = index, IndexLength = indexLength, IndexInstance = indexInstance, Data = data, DataLength = dataLength, DataInstance = dataInstance }; }
public static unsafe dynamic GetBigIntegerOrNull(this JyndData data, JyndItem item) { if (data.Source[item.Data] == 'n') { return(data.GetNull(item)); fixed(char *ptr = data.Source) { char *str = ptr + item.Data; int length = item.DataLength; bool signed = *str == '-'; if (signed) { length--; str++; } return(GetNumberAsBigInteger(str, item, signed, length)); } }
public static bool IsObject(this JyndData data, JyndItem item) { return(data.Source[item.Data] == '{'); }
private static dynamic GetNumber(this JyndData data, JyndItem item) { if (item.DataLength > 0) return(GetNumberAsIntegralType(data, item)); }
private static JyndArray GetArray(this JyndData data, JyndItem item) { return(new JyndArray(data, item.DataInstance)); }
private static JyndObject GetObject(this JyndData data, JyndItem item) { return(new JyndObject(data, item.DataInstance)); }
private static bool GetFalse(this JyndData data, JyndItem item) { return(false); }
private static bool GetTrue(this JyndData data, JyndItem item) { return(true); }
private static object GetNull(this JyndData data, JyndItem item) { return(null); }
public static bool IsArray(this JyndData data, JyndItem item) { return(data.Source[item.Data] == '['); }
private static string GetText(this JyndData data, JyndItem item) { if (item.DataLength > 0) { return(data.Source.Substring(item.Data + 1, item.DataLength - 2)); } StringBuilder builder = new StringBuilder(); int end = item.Data - item.DataLength - 1; int start = item.Data + 1; for (int i = start; i < end; i++) { if (data.Source[i] == '\\') { builder.Append(data.Source, start, i - start); i++; switch (data.Source[i]) { case 'u': int number = 0; i++; for (int k = i; k < i + 4; k++) { if (data.Source[k] <= '9') { number = number * 16 + data.Source[k] - '0'; } else if (data.Source[k] <= 'f') { number = number * 16 + data.Source[k] - 'a' + 10; } else { number = number * 16 + data.Source[k] - 'A' + 10; } } builder.Append((char)number); i += 3; break; case '"': builder.Append('"'); break; case '\\': builder.Append('\\'); break; case '/': builder.Append('/'); break; case 'b': builder.Append('\b'); break; case 'f': builder.Append('\f'); break; case 'n': builder.Append('\n'); break; case 'r': builder.Append('\r'); break; case 't': builder.Append('\t'); break; } start = i + 1; } } if (start != item.Data + 1) { builder.Append(data.Source, start, end - start); } return(builder.ToString()); }