10using NanoXLSX.Utils.Xml;
19 internal class PlainText : IFormattableText
21 private const string ITEM_TAG_NAME =
"si";
22 private const string TEXT_TAG_NAME =
"t";
23 private const string PRESERVE_ATTRIBUTE_NAME =
"space";
24 private const string PRESERVE_ATTRIBUTE_PREFIX_NAME =
"xml";
25 private const string PRESERVE_ATTRIBUTE_VALUE =
"preserve";
30 public string Value {
private get;
set; }
36 public XmlElement GetXmlElement()
38 XmlElement siElement = XmlElement.CreateElement(ITEM_TAG_NAME);
39 if (
string.IsNullOrEmpty(Value))
41 siElement.AddChildElement(TEXT_TAG_NAME);
44 string value = XmlUtils.SanitizeXmlValue(Value);
45 value = ParserUtils.NormalizeNewLines(value);
46 XmlElement element =
null;
47 if (Char.IsWhiteSpace(value, 0) || Char.IsWhiteSpace(value, value.Length - 1))
49 element = XmlElement.CreateElementWithAttribute(TEXT_TAG_NAME, PRESERVE_ATTRIBUTE_NAME, PRESERVE_ATTRIBUTE_VALUE,
"", PRESERVE_ATTRIBUTE_PREFIX_NAME);
53 element = XmlElement.CreateElement(TEXT_TAG_NAME);
55 element.InnerValue = value;
56 siElement.AddChildElement(element);
64 public PlainText(
string value)
74 public override bool Equals(
object obj)
76 if (this.Value ==
null && obj ==
null || (this.Value ==
null && ((PlainText)obj).Value ==
null))
80 else if (this.Value !=
null && !(obj is PlainText) || this.Value ==
null && ((PlainText)obj).Value !=
null)
84 return this.Value.Equals(((PlainText)obj).Value, StringComparison.Ordinal);
91 public override int GetHashCode()
93 if (this.Value ==
null)
97 return this.Value.GetHashCode();