Exemplo n.º 1
0
        private unsafe byte[] GetCollationKeyPosix(string text)
        {
            var sortHandle = PosixHelper.Instance.GetSortHandle(_cultureInfo.CompareInfo);

            fixed(char *pText = text)
            {
                var length = PosixNativeMethods.GetSortKey(sortHandle, pText, text.Length, null, 0, CompareOptions.None);

                if (length == 0)
                {
                    throw new Win32Exception(Marshal.GetLastWin32Error(), "Failed to GetSortKey for text=" + text);
                }

                var sortKey = new byte[length];

                fixed(byte *pSortKey = sortKey)
                {
                    length = PosixNativeMethods.GetSortKey(sortHandle, pText, text.Length, pSortKey, sortKey.Length, CompareOptions.None);
                    if (length == 0)
                    {
                        throw new Win32Exception(Marshal.GetLastWin32Error(), "Failed to GetSortKey for text=" + text);
                    }
                    return(sortKey);
                }
            }
        }
Exemplo n.º 2
0
        private unsafe byte[] GetCollationKeyPosix(string text)
        {
            var sortHandle = PosixHelper.Instance.GetSortHandle(_cultureInfo.CompareInfo);

            var length = PosixNativeMethods.GetSortKey(sortHandle, text, text.Length, null, 0, CompareOptions.None);

            if (length == 0)
            {
                throw new Win32Exception();
            }

            var sortKey = new byte[length];

            fixed(byte *pSortKey = sortKey)
            {
                length = PosixNativeMethods.GetSortKey(sortHandle, text, text.Length, pSortKey, sortKey.Length, CompareOptions.None);
                if (length == 0)
                {
                    throw new Win32Exception();
                }

                return(sortKey);
            }
        }