Roblox-File-Format/Tokens/String.cs

38 lines
1.1 KiB
C#
Raw Normal View History

using System.Xml;
2021-02-25 20:09:54 +00:00
namespace RobloxFiles.Tokens
{
2021-02-25 20:09:54 +00:00
public class StringToken : IXmlPropertyToken, IAttributeToken<string>
{
2021-02-25 20:09:54 +00:00
public string XmlPropertyToken => "string";
public AttributeType AttributeType => AttributeType.String;
2021-06-05 22:21:12 +00:00
public string ReadAttribute(RbxAttribute attr) => attr.ReadString();
public void WriteAttribute(RbxAttribute attr, string value) => attr.WriteString(value);
public bool ReadProperty(Property prop, XmlNode token)
{
string contents = token.InnerText;
prop.Type = PropertyType.String;
prop.Value = contents;
return true;
}
public void WriteProperty(Property prop, XmlDocument doc, XmlNode node)
{
string value = prop.Value.ToInvariantString();
if (value.Contains("\r") || value.Contains("\n"))
{
XmlCDataSection cdata = doc.CreateCDataSection(value);
node.AppendChild(cdata);
}
else
{
node.InnerText = value;
}
}
}
}