예제 #1
0
        /// <summary>
        /// Gets the collation rules for the specified locale.
        /// </summary>
        /// <param name="locale">The locale.</param>
        /// <param name="collatorRuleOption">UColRuleOption to use. Default is UColRuleOption.UCOL_TAILORING_ONLY</param>
        public static string GetCollationRules(Locale locale, UColRuleOption collatorRuleOption = UColRuleOption.UCOL_TAILORING_ONLY)
        {
            ErrorCode err;

            using (RuleBasedCollator.SafeRuleBasedCollatorHandle coll = NativeMethods.ucol_open(locale.Id, out err))
            {
                if (coll.IsInvalid || err.IsFailure())
                {
                    return(null);
                }

                const int len    = 1000;
                IntPtr    buffer = Marshal.AllocCoTaskMem(len * 2);
                try
                {
                    int actualLen = NativeMethods.ucol_getRulesEx(coll, collatorRuleOption, buffer, len);
                    if (actualLen > len)
                    {
                        Marshal.FreeCoTaskMem(buffer);
                        buffer = Marshal.AllocCoTaskMem(actualLen * 2);
                        NativeMethods.ucol_getRulesEx(coll, collatorRuleOption, buffer, actualLen);
                    }
                    return(Marshal.PtrToStringUni(buffer, actualLen));
                }
                finally
                {
                    Marshal.FreeCoTaskMem(buffer);
                }
            }
        }
예제 #2
0
 public static int ucol_getRulesEx(
     RuleBasedCollator.SafeRuleBasedCollatorHandle coll,
     UColRuleOption delta,
     IntPtr buffer, int bufferLen)
 {
     if (CollatorMethods.ucol_getRulesEx == null)
     {
         CollatorMethods.ucol_getRulesEx = GetMethod <CollatorMethodsContainer.ucol_getRulesExDelegate>(IcuI18NLibHandle, "ucol_getRulesEx");
     }
     return(CollatorMethods.ucol_getRulesEx(coll, delta, buffer, bufferLen));
 }
예제 #3
0
        /// <summary>
        /// Gets the collation rules for the specified locale.
        /// </summary>
        /// <param name="locale">The locale.</param>
        /// <param name="collatorRuleOption">UColRuleOption to use. Default is UColRuleOption.UCOL_TAILORING_ONLY</param>
        public static string GetCollationRules(Locale locale, UColRuleOption collatorRuleOption = UColRuleOption.UCOL_TAILORING_ONLY)
        {
            using (var coll = NativeMethods.ucol_open(locale.Id, out var err))
            {
                if (coll.IsInvalid || err.IsFailure())
                {
                    return(null);
                }

                return(NativeMethods.GetUnicodeString((ptr, length) =>
                {
                    // ReSharper disable once AccessToDisposedClosure
                    length = NativeMethods.ucol_getRulesEx(coll, collatorRuleOption, ptr, length);
                    return new Tuple <ErrorCode, int>(ErrorCode.ZERO_ERROR, length);
                }, 1000));
            }
        }
예제 #4
0
 /// <summary>
 /// Gets the collation rules for the specified locale.
 /// </summary>
 /// <param name="locale">The locale.</param>
 /// <param name="collatorRuleOption">UColRuleOption to use. Default is UColRuleOption.UCOL_TAILORING_ONLY</param>
 public static string GetCollationRules(string locale, UColRuleOption collatorRuleOption = UColRuleOption.UCOL_TAILORING_ONLY)
 {
     return(GetCollationRules(new Locale(locale), collatorRuleOption));
 }