public static int ConvertToUtf32(string s, int index)
        {
            CheckParameter(s, index);

            if (!Char.IsSurrogate(s[index]))
            {
                return(s[index]);
            }
            if (!CharEx.IsHighSurrogate(s[index]) ||
                index == s.Length - 1 ||
                !CharEx.IsLowSurrogate(s[index + 1]))
            {
                throw new ArgumentException(String.Format("The string contains invalid surrogate pair character at {0}", index));
            }
            return(ConvertToUtf32(s[index], s[index + 1]));
        }
Example #2
0
 public static int ConvertToUtf32(string s, int index)
 {
     if (s == null)
     {
         throw new ArgumentNullException("s");
     }
     if (index < 0 || index >= s.Length)
     {
         throw new ArgumentOutOfRangeException("index");
     }
     if (!Char.IsSurrogate(s [index]))
     {
         return(s [index]);
     }
     if (!Char.IsHighSurrogate(s [index]) ||
         index == s.Length - 1 ||
         !Char.IsLowSurrogate(s [index + 1]))
     {
         throw new ArgumentException(String.Format("The string contains invalid surrogate pair character at {0}", index));
     }
     return(ConvertToUtf32(s [index], s [index + 1]));
 }
 public static Boolean IsSurrogate(this Char c)
 {
     return(Char.IsSurrogate(c));
 }
Example #4
0
 /// <summary>
 /// Indicates whether the specified character has a surrogate code unit.
 /// </summary>
 /// <param name="Char">The Unicode character to evaluate.</param>
 /// <returns>true if <paramref name="Char"/> is either a high surrogate or a low surrogate; otherwise, false.</returns>
 public static Boolean IsSurrogate(this Char Char) => Char.IsSurrogate(Char);