Ejemplo n.º 1
0
        /// <summary>
        /// Get the description for a given ICU code point.
        /// </summary>
        /// <param name="code">the code point to get description/name of</param>
        /// <param name="nameChoice">what type of information to retrieve</param>
        /// <param name="name">return string</param>
        /// <returns>length of string</returns>
        private static int CharName(int code, UCharNameChoice nameChoice, out string name)
        {
            const int nSize  = 255;
            IntPtr    resPtr = Marshal.AllocCoTaskMem(nSize);

            try
            {
                ErrorCode error;
                int       nResult = NativeMethods.u_CharName(code, nameChoice, resPtr, nSize, out error);
                if (error != ErrorCode.NoErrors)
                {
                    nResult = -1;
                    name    = null;
                }
                else
                {
                    name = Marshal.PtrToStringAnsi(resPtr);
                }
                return(nResult);
            }
            finally
            {
                Marshal.FreeCoTaskMem(resPtr);
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Get the description for a given ICU code point.
 /// </summary>
 /// <param name="code">the code point to get description/name of</param>
 /// <param name="nameChoice">what type of information to retrieve</param>
 /// <param name="name">return string</param>
 /// <returns>length of string</returns>
 private static int CharName(int code, UCharNameChoice nameChoice, out string name)
 {
     name = NativeMethods.GetAnsiString((ptr, length) =>
     {
         length = NativeMethods.u_charName(code, nameChoice, ptr, length, out var err);
         return(new Tuple <ErrorCode, int>(err, length));
     });
     return(name.Length);
 }