Chromium Code Reviews| 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_WIN) | |
| 14 #include "SkString.h" | |
| 15 #endif | |
| 16 | |
| 13 #if !defined(SK_BUILD_FOR_ANDROID) | 17 #if !defined(SK_BUILD_FOR_ANDROID) |
| 14 #include <locale.h> | 18 #include <locale.h> |
| 15 #endif | 19 #endif |
| 16 | 20 |
| 17 #if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS) | 21 #if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS) |
| 18 #include <xlocale.h> | 22 #include <xlocale.h> |
| 19 #endif | 23 #endif |
| 20 | 24 |
| 21 /** | 25 /** |
| 22 * Helper class for ensuring that we don't use the wrong locale when building sh aders. Android | 26 * Helper class for ensuring that we don't use the wrong locale when building sh aders. Android |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 35 } else { | 39 } else { |
| 36 fOldLocale = static_cast<locale_t>(0); | 40 fOldLocale = static_cast<locale_t>(0); |
| 37 } | 41 } |
| 38 #else | 42 #else |
| 39 (void) name; // suppress unused param warning. | 43 (void) name; // suppress unused param warning. |
| 40 #endif | 44 #endif |
| 41 } | 45 } |
| 42 | 46 |
| 43 ~GrAutoLocaleSetter () { | 47 ~GrAutoLocaleSetter () { |
| 44 #if defined(SK_BUILD_FOR_WIN) | 48 #if defined(SK_BUILD_FOR_WIN) |
| 45 if (fOldLocale) { | 49 if (!fOldLocale.isEmpty()) { |
|
bsalomon
2015/12/10 15:12:23
IIUC empty string is valid.
"If locale points to a
Kimmo Kinnunen
2015/12/11 07:50:17
Done.
| |
| 46 setlocale(LC_ALL, fOldLocale); | 50 setlocale(LC_ALL, fOldLocale.c_str()); |
| 47 } | 51 } |
| 48 _configthreadlocale(fOldPerThreadLocale); | 52 _configthreadlocale(fOldPerThreadLocale); |
| 49 #elif !defined(SK_BUILD_FOR_ANDROID) && !defined(__UCLIBC__) | 53 #elif !defined(SK_BUILD_FOR_ANDROID) && !defined(__UCLIBC__) |
| 50 if (fLocale) { | 54 if (fLocale) { |
| 51 uselocale(fOldLocale); | 55 uselocale(fOldLocale); |
| 52 freelocale(fLocale); | 56 freelocale(fLocale); |
| 53 } | 57 } |
| 54 #endif | 58 #endif |
| 55 } | 59 } |
| 56 | 60 |
| 57 private: | 61 private: |
| 58 #if defined(SK_BUILD_FOR_WIN) | 62 #if defined(SK_BUILD_FOR_WIN) |
| 59 int fOldPerThreadLocale; | 63 int fOldPerThreadLocale; |
| 60 const char* fOldLocale; | 64 SkString fOldLocale; |
| 61 #elif !defined(SK_BUILD_FOR_ANDROID) && !defined(__UCLIBC__) | 65 #elif !defined(SK_BUILD_FOR_ANDROID) && !defined(__UCLIBC__) |
| 62 locale_t fOldLocale; | 66 locale_t fOldLocale; |
| 63 locale_t fLocale; | 67 locale_t fLocale; |
| 64 #endif | 68 #endif |
| 65 }; | 69 }; |
| 66 | 70 |
| 67 #endif | 71 #endif |
| 68 | 72 |
| OLD | NEW |