Пример #1
0
        /// <summary>
        /// The setlocale function installs the specified system locale or its portion as the new C locale. The modifications remain in effect and influences the execution of all locale-sensitive C library functions until the next call to setlocale. If locale is a null pointer, setlocale queries the current C locale without modifying it.
        /// </summary>
        /// <param name="category">Locale category identifier</param>
        /// <param name="locale">System-specific locale identifier. Can be "" for the user-preferred locale or "C" for the minimal locale</param>
        /// <returns>String identifying the C locale after applying the changes, if any, or null pointer on failure. A copy of the returned string along with the category used in this call to std::setlocale may be used later in the program to restore the locale back to the state at the end of this call.</returns>
        public static String SetLocale(LocaleGuard.LocaleCategory category, String locale = null)
        {
            IntPtr oldLocalePtr;

            if (locale == null)
            {
                oldLocalePtr = stdSetlocale(category, IntPtr.Zero);
                return(oldLocalePtr == IntPtr.Zero ? null : Marshal.PtrToStringAnsi(oldLocalePtr));
            }
            IntPtr localePtr = Marshal.StringToHGlobalAnsi(locale);

            try
            {
                oldLocalePtr = stdSetlocale(category, localePtr);
            }
            finally
            {
                Marshal.FreeHGlobal(localePtr);
            }
            return(oldLocalePtr == IntPtr.Zero ? null : Marshal.PtrToStringAnsi(oldLocalePtr));
        }
Пример #2
0
 private static extern IntPtr stdSetlocale(
     LocaleGuard.LocaleCategory category,
     IntPtr locale);