Changeset 11009 for branches/DataPreprocessing/HeuristicLab.Persistence/3.3/Default/Xml/Primitive/Char2XmlFormatter.cs
- Timestamp:
- 06/12/14 13:26:18 (10 years ago)
- Location:
- branches/DataPreprocessing
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/DataPreprocessing
- Property svn:ignore
-
old new 8 8 FxCopResults.txt 9 9 Google.ProtocolBuffers-0.9.1.dll 10 Google.ProtocolBuffers-2.4.1.473.dll 10 11 HeuristicLab 3.3.5.1.ReSharper.user 11 12 HeuristicLab 3.3.6.0.ReSharper.user 12 13 HeuristicLab.4.5.resharper.user 13 14 HeuristicLab.ExtLibs.6.0.ReSharper.user 15 HeuristicLab.Scripting.Development 14 16 HeuristicLab.resharper.user 15 17 ProtoGen.exe … … 17 19 _ReSharper.HeuristicLab 18 20 _ReSharper.HeuristicLab 3.3 21 _ReSharper.HeuristicLab 3.3 Tests 19 22 _ReSharper.HeuristicLab.ExtLibs 20 23 bin 21 24 protoc.exe 22 _ReSharper.HeuristicLab 3.3 Tests23 Google.ProtocolBuffers-2.4.1.473.dll
-
- Property svn:mergeinfo changed
- Property svn:ignore
-
branches/DataPreprocessing/HeuristicLab.Persistence
- Property svn:mergeinfo changed
/trunk/sources/HeuristicLab.Persistence (added) merged: 10889,10895-10896,10958,10960-10961
- Property svn:mergeinfo changed
-
branches/DataPreprocessing/HeuristicLab.Persistence/3.3/Default/Xml/Primitive/Char2XmlFormatter.cs
r9456 r11009 20 20 #endregion 21 21 22 using System; 23 using System.Text; 24 using System.Text.RegularExpressions; 22 25 using HeuristicLab.Persistence.Core; 23 26 using HeuristicLab.Persistence.Interfaces; … … 27 30 internal sealed class Char2XmlSerializer : PrimitiveSerializerBase<char, XmlString> { 28 31 32 private static readonly Regex base64Regex = new Regex("<Base64>(.+)</Base64>"); 33 34 private static bool IsSpecial(char c) { 35 return c <= 0x1F && c != 0x9 && c != 0xA && c != 0xD; 36 } 37 38 private static string ToBase64String(char c) { 39 return string.Format("<Base64>{0}</Base64>", Convert.ToBase64String(Encoding.ASCII.GetBytes(new[] {c}))); 40 } 41 29 42 public override XmlString Format(char c) { 30 return new XmlString( new string(c, 1));43 return new XmlString(IsSpecial(c) ? ToBase64String(c) : new string(c, 1)); 31 44 } 32 45 33 46 public override char Parse(XmlString x) { 34 if (x.Data.Length != 1) 35 throw new PersistenceException("Invalid character format, XML string length != 1"); 36 return x.Data[0]; 47 if (x.Data.Length <= 1) return x.Data[0]; 48 var m = base64Regex.Match(x.Data); 49 if (m.Success) 50 return Encoding.ASCII.GetString(Convert.FromBase64String(m.Groups[1].Value))[0]; 51 throw new PersistenceException("Invalid character format, XML string length != 1"); 37 52 } 38 53 }
Note: See TracChangeset
for help on using the changeset viewer.