private static String EscapeUnicode(char c, IEscapeProvider d) { // escaping not defined if (d.GetUnicodePattern() == null) { return(c.ToString()); } if (!d.NeedEscapeUnicode(c)) { return(c.ToString()); } return(d.GetUnicodePattern().Replace(" ", ((int)c).ToString("X4"))); }
private static String CheckSuffix(String str, int start, int end, IEscapeProvider d) { String s; // the length of escaping code not constant so check all variants foreach (int j in d.GetUnescape().KeysLength) { if (j > end - start + 1) { continue; } s = str.Substring(end - j + 1, j); s = UnescapeEntity(s, d); if (s != null) { return(str.Substring(start, end - start - j + 1) + s); } } // check unicode if (d.GetUnicodePattern() == null) { return(null); } int p = d.GetUnicodePattern().Length + 3; if (p > end - start + 1) { return(null); } s = str.Substring(end - p + 1, p); s = UnescapeUnicode(s, d); if (s != null) { return(str.Substring(start, end - start - p + 1) + s); } return(null); }
private static String UnescapeUnicode(this String s, IEscapeProvider d) { String p = d.GetUnicodePattern(); if (p == null) { return(null); } if (p.Length + 3 == s.Length) { String hex = s.Substring(p.IndexOf(' '), 4); ushort value; if (ushort.TryParse(hex, NumberStyles.HexNumber, null, out value)) { return(((char)value).ToString()); } } return(null); }
private static String UnescapeUnicode(this String s, IEscapeProvider d) { String p = d.GetUnicodePattern(); if (p == null) return null; if (p.Length + 3 == s.Length) { String hex = s.Substring(p.IndexOf(' '), 4); ushort value; if (ushort.TryParse(hex, NumberStyles.HexNumber, null, out value)) return ((char)value).ToString(); } return null; }
private static String CheckSuffix(String str, int start, int end, IEscapeProvider d) { String s; // the length of escaping code not constant so check all variants foreach (int j in d.GetUnescape().KeysLength) { if (j > end - start + 1) continue; s = str.Substring(end - j + 1, j); s = UnescapeEntity(s, d); if (s != null) return str.Substring(start, end - start - j + 1) + s; } // check unicode if (d.GetUnicodePattern() == null) return null; int p = d.GetUnicodePattern().Length + 3; if (p > end - start + 1) return null; s = str.Substring(end - p + 1, p); s = UnescapeUnicode(s, d); if (s != null) return str.Substring(start, end - start - p + 1) + s; return null; }
private static String EscapeUnicode(char c, IEscapeProvider d) { // escaping not defined if (d.GetUnicodePattern() == null) return c.ToString(); if (!d.NeedEscapeUnicode(c)) return c.ToString(); return d.GetUnicodePattern().Replace(" ", ((int)c).ToString("X4")); }