| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #ifndef GrAutoLocaleSetter_DEFINED | 8 #ifndef GrAutoLocaleSetter_DEFINED |
| 9 #define GrAutoLocaleSetter_DEFINED | 9 #define GrAutoLocaleSetter_DEFINED |
| 10 | 10 |
| 11 #include "GrTypes.h" | 11 #include "GrTypes.h" |
| 12 | 12 |
| 13 #if !defined(SK_BUILD_FOR_ANDROID) | 13 #if !defined(SK_BUILD_FOR_ANDROID) |
| 14 #include <locale.h> | 14 #include <locale.h> |
| 15 #endif | 15 #endif |
| 16 | 16 |
| 17 #if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS) | 17 #if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS) |
| 18 #include <xlocale.h> | 18 #include <xlocale.h> |
| 19 #endif | 19 #endif |
| 20 | 20 |
| 21 /** | 21 /** |
| 22 * Helper class for ensuring that we don't use the wrong locale when building sh
aders. Android | 22 * Helper class for ensuring that we don't use the wrong locale when building sh
aders. Android |
| 23 * doesn't support locale in the NDK, so this is a no-op there. | 23 * doesn't support locale in the NDK, so this is a no-op there. |
| 24 */ | 24 */ |
| 25 class GrAutoLocaleSetter { | 25 class GrAutoLocaleSetter : public SkNoncopyable { |
| 26 public: | 26 public: |
| 27 GrAutoLocaleSetter (const char* name) { | 27 GrAutoLocaleSetter (const char* name) { |
| 28 #if defined(SK_BUILD_FOR_WIN) | 28 #if defined(SK_BUILD_FOR_WIN) |
| 29 fOldPerThreadLocale = _configthreadlocale(_ENABLE_PER_THREAD_LOCALE); | 29 fOldPerThreadLocale = _configthreadlocale(_ENABLE_PER_THREAD_LOCALE); |
| 30 fOldLocale = setlocale(LC_ALL, name); | 30 fOldLocale = setlocale(LC_ALL, name); |
| 31 #elif !defined(SK_BUILD_FOR_ANDROID) && !defined(__UCLIBC__) | 31 #elif !defined(SK_BUILD_FOR_ANDROID) && !defined(__UCLIBC__) |
| 32 fLocale = newlocale(LC_ALL, name, 0); | 32 fLocale = newlocale(LC_ALL, name, 0); |
| 33 if (fLocale) { | 33 if (fLocale) { |
| 34 fOldLocale = uselocale(fLocale); | 34 fOldLocale = uselocale(fLocale); |
| 35 } else { |
| 36 fOldLocale = static_cast<locale_t>(0); |
| 35 } | 37 } |
| 36 #else | 38 #else |
| 37 (void) name; // suppress unused param warning. | 39 (void) name; // suppress unused param warning. |
| 38 #endif | 40 #endif |
| 39 } | 41 } |
| 40 | 42 |
| 41 ~GrAutoLocaleSetter () { | 43 ~GrAutoLocaleSetter () { |
| 42 #if defined(SK_BUILD_FOR_WIN) | 44 #if defined(SK_BUILD_FOR_WIN) |
| 43 setlocale(LC_ALL, fOldLocale); | 45 setlocale(LC_ALL, fOldLocale); |
| 44 _configthreadlocale(fOldPerThreadLocale); | 46 _configthreadlocale(fOldPerThreadLocale); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 55 int fOldPerThreadLocale; | 57 int fOldPerThreadLocale; |
| 56 const char* fOldLocale; | 58 const char* fOldLocale; |
| 57 #elif !defined(SK_BUILD_FOR_ANDROID) && !defined(__UCLIBC__) | 59 #elif !defined(SK_BUILD_FOR_ANDROID) && !defined(__UCLIBC__) |
| 58 locale_t fOldLocale; | 60 locale_t fOldLocale; |
| 59 locale_t fLocale; | 61 locale_t fLocale; |
| 60 #endif | 62 #endif |
| 61 }; | 63 }; |
| 62 | 64 |
| 63 #endif | 65 #endif |
| 64 | 66 |
| OLD | NEW |