Last change
on this file since 1564 was
1564,
checked in by epitzer, 15 years ago
|
Stronger typing for formatters with the help of generics. Separate format and serial data type. (#548)
|
File size:
943 bytes
|
Line | |
---|
1 | using System;
|
---|
2 | using System.Text;
|
---|
3 | using HeuristicLab.Persistence.Core;
|
---|
4 | using HeuristicLab.Persistence.Interfaces;
|
---|
5 | using System.Xml;
|
---|
6 |
|
---|
7 | namespace HeuristicLab.Persistence.Default.Xml.Primitive {
|
---|
8 |
|
---|
9 | [EmptyStorableClass]
|
---|
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());
|
---|
18 | }
|
---|
19 |
|
---|
20 | private static readonly string[] separators = new string[] { "<![CDATA[", "]]>" };
|
---|
21 |
|
---|
22 | public override string Parse(XmlString x) {
|
---|
23 | StringBuilder sb = new StringBuilder();
|
---|
24 | foreach (string s in x.Data.Split(separators,
|
---|
25 | StringSplitOptions.RemoveEmptyEntries)) {
|
---|
26 | sb.Append(s);
|
---|
27 | }
|
---|
28 | return sb.ToString();
|
---|
29 | }
|
---|
30 | }
|
---|
31 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.