private static jsObject _NamedValue(string Text, ref int Index, int LastIndex, jsObject Storage) { var Name = ""; var X = Text[Index]; if (X == '"') { Name = Text.FindMatchingBrackets("\"", "\"", Index); Index += Name.Length + 2; } else if (X == '\'') { Name = Text.FindMatchingBrackets("'", "'", Index); Index += Name.Length + 2; } else { Name = Text.Substring("", ":", Index, false).Trim(); } Index = Text.IndexOf(':', Index); if (Index != -1) { Index++; while (char.IsWhiteSpace(Text[Index])) { Index++; } X = Text[Index]; if (X == '"' || X == '\'') { Storage.Set(Name, _String(Text, ref Index, LastIndex)); } else if (X == '{') { Storage.Set(Name, _Object(Text, ref Index, LastIndex, jsObject.NewObject())); } else if (X == '[') { Storage.Set(Name, _Array(Text, ref Index, LastIndex, jsObject.NewArray())); } else { Storage.Set(Name, _Raw(Text, ref Index, LastIndex)); } return(Storage); } return(null); }
private static jsObject _Array(string Text, ref int Index, int LastIndex, jsObject Storage) { int Open = Index, Close = Index; if (Text.FindMatchingBrackets("[", "]", ref Open, ref Close)) { do { if (Text[Open] == ',') { Open++; } while (Open < Close && char.IsWhiteSpace(Text[Open])) { Open++; } if (Open == Close) { break; } var X = Text[Open]; var Name = Storage.Count.ToString(); if (X == '"' || X == '\'') { Storage.Set(Name, _String(Text, ref Open, Close)); } else if (X == '{') { Storage.Set(Name, _Object(Text, ref Open, Close, jsObject.NewObject())); } else if (X == '[') { Storage.Set(Name, _Array(Text, ref Open, Close, jsObject.NewArray())); } else { Storage.Set(Name, _Raw(Text, ref Open, Close)); } }while (Open < Close); Index = Close + 1; return(Storage); } return(null); }
public void Set <T>(string[] Keys, T Value) { jsObject Current = this; for (int i = 0; i < Keys.Length; i++) { var Sub = Keys[i]; if ((Keys.Length - i) == 1) { if (Sub.Contains('.')) { Current.Set(Sub, Value); } else { Current.AssignValue <T>(Sub, Value); } break; } var Next = Current.Get <jsObject>(Sub); if (Next == null) { Next = new jsObject(); if (Sub.Contains('.')) { Current.Set(Sub, Next); } else { Current.AssignValue <jsObject>(Sub, Next); } } Current = Next; } }