10using NanoXLSX.Utils.Xml;
19 internal class PlainText : IFormattableText
21 private const string TAG_NAME =
"t";
22 private const string PRESERVE_ATTRIBUTE_NAME =
"space";
23 private const string PRESERVE_ATTRIBUTE_PREFIX_NAME =
"xml";
24 private const string PRESERVE_ATTRIBUTE_VALUE =
"preserve";
29 public string Value {
private get;
set; }
35 public XmlElement GetXmlElement()
37 if (
string.IsNullOrEmpty(Value))
39 return XmlElement.CreateElement(TAG_NAME);
41 string value = XmlUtils.SanitizeXmlValue(Value);
42 value = ParserUtils.NormalizeNewLines(value);
43 XmlElement element =
null;
44 if (Char.IsWhiteSpace(value, 0) || Char.IsWhiteSpace(value, value.Length - 1))
46 element = XmlElement.CreateElementWithAttribute(TAG_NAME, PRESERVE_ATTRIBUTE_NAME, PRESERVE_ATTRIBUTE_VALUE,
"", PRESERVE_ATTRIBUTE_PREFIX_NAME);
50 element = XmlElement.CreateElement(TAG_NAME);
52 element.InnerValue = value;
60 public PlainText(
string value)
70 public override bool Equals(
object obj)
72 if (this.Value ==
null && obj ==
null || (this.Value ==
null && ((PlainText)obj).Value ==
null))
76 else if (this.Value !=
null && !(obj is PlainText) || this.Value ==
null && ((PlainText)obj).Value !=
null)
80 return this.Value.Equals(((PlainText)obj).Value, StringComparison.Ordinal);
87 public override int GetHashCode()
89 if (this.Value ==
null)
93 return this.Value.GetHashCode();