/// <summary> /// Parses a string representation into a KFF file. Throws an exception if the string is malformed. /// </summary> /// <param name="fileName">The name of the file that will be parsed.</param> /// <param name="s">The string to parse.</param> public KFFFile Parse(string fileName, string s) { if (s == null) { throw new ArgumentNullException("The string to parse can't be null."); } if (s == "") { return(new KFFFile(fileName)); } this.fileName = fileName; this.s = s; this.pos = 0; KFFFile f = new KFFFile(fileName); SkipWhiteSpacesAndComments(); while (pos < s.Length) { int begin = pos; Tag newTag = Tag(); if (f.Has(newTag.name)) { throw new KFFParseException("Found duplicated Tag '" + newTag.name + "' (" + TextFileData.Calculate(this.fileName, this.s, begin) + ")."); } f.Set(newTag); } return(f); }
/// <summary> /// Gets the string representation of the file in the writer. /// </summary> public string ToString(KFFFile file) { StringBuilder sb = new StringBuilder(); List <Tag> tags = file.tags.value; for (int i = 0; i < tags.Count; i++) { string tag = StringFromAnyTag(tags[i]); sb.Append(tag); } return(sb.ToString()); }