uset_addString() public static method

Adds the given string to the given Unicode set
public static uset_addString ( IntPtr set, string str, int strLen ) : void
set IntPtr The Unicode set to which to add the string
str string The string to add
strLen int The length of the string or -1 if null
return void
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);
            }
        }