uset_open() public static method

Creates a Unicode set that contains the range of characters start..end, inclusive. If start > end then an empty set is created (same as using uset_openEmpty().
public static uset_open ( char start, char end ) : IntPtr
start char First character of the range, inclusive
end char Last character of the range, inclusive
return IntPtr
Exemplo n.º 1
0
        /// <summary>
        /// Returns a string representation of this Unicode set
        /// </summary>
        /// <param name="set">Unicode set to convert.  Null set throws an exception</param>
        /// <returns>pattern string</returns>
        public static string ToPattern(IEnumerable <string> set)
        {
            if (set == null)
            {
                throw new ArgumentNullException("set");
            }
            // uset_openEmpty unavailable, so this is equivalent
            IntPtr uset = NativeMethods.uset_open('1', '0');

            try
            {
                foreach (string str in set)
                {
                    if (!string.IsNullOrEmpty(str))
                    {
                        if (str.Length == 1)
                        {
                            NativeMethods.uset_add(uset, str[0]);
                        }
                        else
                        {
                            NativeMethods.uset_addString(uset, str, str.Length);
                        }
                    }
                }

                var    err            = ErrorCode.ZERO_ERROR;
                int    resultCapacity = NativeMethods.uset_toPattern(uset, IntPtr.Zero, 0, true, ref err);
                IntPtr buffer         = Marshal.AllocCoTaskMem(resultCapacity * 2);
                try
                {
                    err            = ErrorCode.ZERO_ERROR;
                    resultCapacity = NativeMethods.uset_toPattern(uset, buffer, resultCapacity, true, ref err);
                    if (err > ErrorCode.NoErrors)
                    {
                        throw new Exception("UnicodeSet.ToPattern() failed with code " + err);
                    }
                    return(Marshal.PtrToStringUni(buffer, resultCapacity));
                }
                finally
                {
                    Marshal.FreeCoTaskMem(buffer);
                }
            }
            finally
            {
                NativeMethods.uset_close(uset);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Returns a string representation of this Unicode set
        /// </summary>
        /// <param name="set">Unicode set to convert.  Null set throws an exception</param>
        /// <returns>pattern string</returns>
        public static string ToPattern(IEnumerable <string> set)
        {
            if (set == null)
            {
                throw new ArgumentNullException(nameof(set));
            }
            // uset_openEmpty unavailable, so this is equivalent
            IntPtr uset = NativeMethods.uset_open('1', '0');

            try
            {
                foreach (string str in set)
                {
                    if (!string.IsNullOrEmpty(str))
                    {
                        if (str.Length == 1)
                        {
                            NativeMethods.uset_add(uset, str.First());
                        }
                        else
                        {
                            NativeMethods.uset_addString(uset, str, str.Length);
                        }
                    }
                }

                return(NativeMethods.GetUnicodeString((ptr, length) =>
                {
                    length = NativeMethods.uset_toPattern(uset, ptr, length, true, out var err);
                    return new Tuple <ErrorCode, int>(err, length);
                }));
            }
            finally
            {
                NativeMethods.uset_close(uset);
            }
        }