Changeset 1564 for trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/Primitive/String2XmlFormatter.cs
- Timestamp:
- 04/16/09 12:40:41 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/Primitive/String2XmlFormatter.cs
r1542 r1564 8 8 9 9 [EmptyStorableClass] 10 public class String2XmlFormatter : IFormatter { 11 12 public Type Type { get { return typeof(string); } } 13 public IFormat Format { get { return XmlFormat.Instance; } } 14 15 public object DoFormat(object o) { 16 return "<![CDATA[" + 17 ((string)o).Replace("]]>", "]]]]><![CDATA[>") + 18 "]]>"; 10 public class String2XmlFormatter : FormatterBase<string, XmlString> { 11 12 public override XmlString Format(string s) { 13 StringBuilder sb = new StringBuilder(); 14 sb.Append("<![CDATA["); 15 sb.Append(s.Replace("]]>", "]]]]><![CDATA[>")); 16 sb.Append("]]>"); 17 return new XmlString(sb.ToString()); 19 18 } 20 19 21 public object Parse(object o) { 20 private static readonly string[] separators = new string[] { "<![CDATA[", "]]>" }; 21 22 public override string Parse(XmlString x) { 22 23 StringBuilder sb = new StringBuilder(); 23 foreach (string s in ((string)o).Split( 24 new[] { "<![CDATA[", "]]>" }, 24 foreach (string s in x.Data.Split(separators, 25 25 StringSplitOptions.RemoveEmptyEntries)) { 26 26 sb.Append(s);
Note: See TracChangeset
for help on using the changeset viewer.