Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(173)

Side by Side Diff: src/locale.cpp

Issue 1441603003: Cherry-pick upstream r252457 (Closed) Base URL: https://chromium.googlesource.com/a/native_client/pnacl-libcxx.git@master
Patch Set: Use __musl__ define to detect musl Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « include/support/musl/xlocale.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 //===------------------------- locale.cpp ---------------------------------===// 1 //===------------------------- locale.cpp ---------------------------------===//
2 // 2 //
3 // The LLVM Compiler Infrastructure 3 // The LLVM Compiler Infrastructure
4 // 4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open 5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details. 6 // Source Licenses. See LICENSE.TXT for details.
7 // 7 //
8 //===----------------------------------------------------------------------===// 8 //===----------------------------------------------------------------------===//
9 9
10 // On Solaris, we need to define something to make the C99 parts of localeconv 10 // On Solaris, we need to define something to make the C99 parts of localeconv
(...skipping 792 matching lines...) Expand 10 before | Expand all | Expand 10 after
803 if (!(isascii(*low) && (ctype<char>::classic_table()[*low] & m))) 803 if (!(isascii(*low) && (ctype<char>::classic_table()[*low] & m)))
804 break; 804 break;
805 return low; 805 return low;
806 } 806 }
807 807
808 wchar_t 808 wchar_t
809 ctype<wchar_t>::do_toupper(char_type c) const 809 ctype<wchar_t>::do_toupper(char_type c) const
810 { 810 {
811 #ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE 811 #ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
812 return isascii(c) ? _DefaultRuneLocale.__mapupper[c] : c; 812 return isascii(c) ? _DefaultRuneLocale.__mapupper[c] : c;
813 #elif defined(__GLIBC__) || defined(__EMSCRIPTEN__) || defined(__NetBSD__) 813 #elif defined(__GLIBC__) || defined(__EMSCRIPTEN__) || \
814 defined(__NetBSD__) || defined(_LIBCPP_HAS_MUSL_LIBC)
814 return isascii(c) ? ctype<char>::__classic_upper_table()[c] : c; 815 return isascii(c) ? ctype<char>::__classic_upper_table()[c] : c;
815 #else 816 #else
816 return (isascii(c) && iswlower_l(c, __cloc())) ? c-L'a'+L'A' : c; 817 return (isascii(c) && iswlower_l(c, __cloc())) ? c-L'a'+L'A' : c;
817 #endif 818 #endif
818 } 819 }
819 820
820 const wchar_t* 821 const wchar_t*
821 ctype<wchar_t>::do_toupper(char_type* low, const char_type* high) const 822 ctype<wchar_t>::do_toupper(char_type* low, const char_type* high) const
822 { 823 {
823 for (; low != high; ++low) 824 for (; low != high; ++low)
824 #ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE 825 #ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
825 *low = isascii(*low) ? _DefaultRuneLocale.__mapupper[*low] : *low; 826 *low = isascii(*low) ? _DefaultRuneLocale.__mapupper[*low] : *low;
826 #elif defined(__GLIBC__) || defined(__EMSCRIPTEN__) || defined(__NetBSD__) 827 #elif defined(__GLIBC__) || defined(__EMSCRIPTEN__) || \
828 defined(__NetBSD__) || defined(_LIBCPP_HAS_MUSL_LIBC)
827 *low = isascii(*low) ? ctype<char>::__classic_upper_table()[*low] 829 *low = isascii(*low) ? ctype<char>::__classic_upper_table()[*low]
828 : *low; 830 : *low;
829 #else 831 #else
830 *low = (isascii(*low) && islower_l(*low, __cloc())) ? (*low-L'a'+L'A') : *low; 832 *low = (isascii(*low) && islower_l(*low, __cloc())) ? (*low-L'a'+L'A') : *low;
831 #endif 833 #endif
832 return low; 834 return low;
833 } 835 }
834 836
835 wchar_t 837 wchar_t
836 ctype<wchar_t>::do_tolower(char_type c) const 838 ctype<wchar_t>::do_tolower(char_type c) const
837 { 839 {
838 #ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE 840 #ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
839 return isascii(c) ? _DefaultRuneLocale.__maplower[c] : c; 841 return isascii(c) ? _DefaultRuneLocale.__maplower[c] : c;
840 #elif defined(__GLIBC__) || defined(__EMSCRIPTEN__) || defined(__NetBSD__) 842 #elif defined(__GLIBC__) || defined(__EMSCRIPTEN__) || \
843 defined(__NetBSD__) || defined(_LIBCPP_HAS_MUSL_LIBC)
841 return isascii(c) ? ctype<char>::__classic_lower_table()[c] : c; 844 return isascii(c) ? ctype<char>::__classic_lower_table()[c] : c;
842 #else 845 #else
843 return (isascii(c) && isupper_l(c, __cloc())) ? c-L'A'+'a' : c; 846 return (isascii(c) && isupper_l(c, __cloc())) ? c-L'A'+'a' : c;
844 #endif 847 #endif
845 } 848 }
846 849
847 const wchar_t* 850 const wchar_t*
848 ctype<wchar_t>::do_tolower(char_type* low, const char_type* high) const 851 ctype<wchar_t>::do_tolower(char_type* low, const char_type* high) const
849 { 852 {
850 for (; low != high; ++low) 853 for (; low != high; ++low)
851 #ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE 854 #ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
852 *low = isascii(*low) ? _DefaultRuneLocale.__maplower[*low] : *low; 855 *low = isascii(*low) ? _DefaultRuneLocale.__maplower[*low] : *low;
853 #elif defined(__GLIBC__) || defined(__EMSCRIPTEN__) || defined(__NetBSD__) 856 #elif defined(__GLIBC__) || defined(__EMSCRIPTEN__) || \
857 defined(__NetBSD__) || defined(_LIBCPP_HAS_MUSL_LIBC)
854 *low = isascii(*low) ? ctype<char>::__classic_lower_table()[*low] 858 *low = isascii(*low) ? ctype<char>::__classic_lower_table()[*low]
855 : *low; 859 : *low;
856 #else 860 #else
857 *low = (isascii(*low) && isupper_l(*low, __cloc())) ? *low-L'A'+L'a' : * low; 861 *low = (isascii(*low) && isupper_l(*low, __cloc())) ? *low-L'A'+L'a' : * low;
858 #endif 862 #endif
859 return low; 863 return low;
860 } 864 }
861 865
862 wchar_t 866 wchar_t
863 ctype<wchar_t>::do_widen(char c) const 867 ctype<wchar_t>::do_widen(char c) const
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
912 } 916 }
913 917
914 char 918 char
915 ctype<char>::do_toupper(char_type c) const 919 ctype<char>::do_toupper(char_type c) const
916 { 920 {
917 #ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE 921 #ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
918 return isascii(c) ? 922 return isascii(c) ?
919 static_cast<char>(_DefaultRuneLocale.__mapupper[static_cast<ptrdiff_t>(c)] ) : c; 923 static_cast<char>(_DefaultRuneLocale.__mapupper[static_cast<ptrdiff_t>(c)] ) : c;
920 #elif defined(__NetBSD__) 924 #elif defined(__NetBSD__)
921 return static_cast<char>(__classic_upper_table()[static_cast<unsigned char>( c)]); 925 return static_cast<char>(__classic_upper_table()[static_cast<unsigned char>( c)]);
922 #elif defined(__GLIBC__) || defined(__EMSCRIPTEN__) 926 #elif defined(__GLIBC__) || defined(__EMSCRIPTEN__) || defined(_LIBCPP_HAS_MUSL_ LIBC)
923 return isascii(c) ? 927 return isascii(c) ?
924 static_cast<char>(__classic_upper_table()[static_cast<unsigned char>(c)]) : c; 928 static_cast<char>(__classic_upper_table()[static_cast<unsigned char>(c)]) : c;
925 #else 929 #else
926 return (isascii(c) && islower_l(c, __cloc())) ? c-'a'+'A' : c; 930 return (isascii(c) && islower_l(c, __cloc())) ? c-'a'+'A' : c;
927 #endif 931 #endif
928 } 932 }
929 933
930 const char* 934 const char*
931 ctype<char>::do_toupper(char_type* low, const char_type* high) const 935 ctype<char>::do_toupper(char_type* low, const char_type* high) const
932 { 936 {
933 for (; low != high; ++low) 937 for (; low != high; ++low)
934 #ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE 938 #ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
935 *low = isascii(*low) ? 939 *low = isascii(*low) ?
936 static_cast<char>(_DefaultRuneLocale.__mapupper[static_cast<ptrdiff_t> (*low)]) : *low; 940 static_cast<char>(_DefaultRuneLocale.__mapupper[static_cast<ptrdiff_t> (*low)]) : *low;
937 #elif defined(__NetBSD__) 941 #elif defined(__NetBSD__)
938 *low = static_cast<char>(__classic_upper_table()[static_cast<unsigned ch ar>(*low)]); 942 *low = static_cast<char>(__classic_upper_table()[static_cast<unsigned ch ar>(*low)]);
939 #elif defined(__GLIBC__) || defined(__EMSCRIPTEN__) 943 #elif defined(__GLIBC__) || defined(__EMSCRIPTEN__) || defined(_LIBCPP_HAS_MUSL_ LIBC)
940 *low = isascii(*low) ? 944 *low = isascii(*low) ?
941 static_cast<char>(__classic_upper_table()[static_cast<size_t>(*low)]) : *low; 945 static_cast<char>(__classic_upper_table()[static_cast<size_t>(*low)]) : *low;
942 #else 946 #else
943 *low = (isascii(*low) && islower_l(*low, __cloc())) ? *low-'a'+'A' : *lo w; 947 *low = (isascii(*low) && islower_l(*low, __cloc())) ? *low-'a'+'A' : *lo w;
944 #endif 948 #endif
945 return low; 949 return low;
946 } 950 }
947 951
948 char 952 char
949 ctype<char>::do_tolower(char_type c) const 953 ctype<char>::do_tolower(char_type c) const
950 { 954 {
951 #ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE 955 #ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
952 return isascii(c) ? 956 return isascii(c) ?
953 static_cast<char>(_DefaultRuneLocale.__maplower[static_cast<ptrdiff_t>(c)] ) : c; 957 static_cast<char>(_DefaultRuneLocale.__maplower[static_cast<ptrdiff_t>(c)] ) : c;
954 #elif defined(__NetBSD__) 958 #elif defined(__NetBSD__)
955 return static_cast<char>(__classic_lower_table()[static_cast<unsigned char>( c)]); 959 return static_cast<char>(__classic_lower_table()[static_cast<unsigned char>( c)]);
956 #elif defined(__GLIBC__) || defined(__EMSCRIPTEN__) || defined(__NetBSD__) 960 #elif defined(__GLIBC__) || defined(__EMSCRIPTEN__) || defined(_LIBCPP_HAS_MUSL_ LIBC)
957 return isascii(c) ? 961 return isascii(c) ?
958 static_cast<char>(__classic_lower_table()[static_cast<size_t>(c)]) : c; 962 static_cast<char>(__classic_lower_table()[static_cast<size_t>(c)]) : c;
959 #else 963 #else
960 return (isascii(c) && isupper_l(c, __cloc())) ? c-'A'+'a' : c; 964 return (isascii(c) && isupper_l(c, __cloc())) ? c-'A'+'a' : c;
961 #endif 965 #endif
962 } 966 }
963 967
964 const char* 968 const char*
965 ctype<char>::do_tolower(char_type* low, const char_type* high) const 969 ctype<char>::do_tolower(char_type* low, const char_type* high) const
966 { 970 {
967 for (; low != high; ++low) 971 for (; low != high; ++low)
968 #ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE 972 #ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
969 *low = isascii(*low) ? static_cast<char>(_DefaultRuneLocale.__maplower[s tatic_cast<ptrdiff_t>(*low)]) : *low; 973 *low = isascii(*low) ? static_cast<char>(_DefaultRuneLocale.__maplower[s tatic_cast<ptrdiff_t>(*low)]) : *low;
970 #elif defined(__NetBSD__) 974 #elif defined(__NetBSD__)
971 *low = static_cast<char>(__classic_lower_table()[static_cast<unsigned ch ar>(*low)]); 975 *low = static_cast<char>(__classic_lower_table()[static_cast<unsigned ch ar>(*low)]);
972 #elif defined(__GLIBC__) || defined(__EMSCRIPTEN__) 976 #elif defined(__GLIBC__) || defined(__EMSCRIPTEN__) || defined(_LIBCPP_HAS_MUSL_ LIBC)
973 *low = isascii(*low) ? static_cast<char>(__classic_lower_table()[static_ cast<size_t>(*low)]) : *low; 977 *low = isascii(*low) ? static_cast<char>(__classic_lower_table()[static_ cast<size_t>(*low)]) : *low;
974 #else 978 #else
975 *low = (isascii(*low) && isupper_l(*low, __cloc())) ? *low-'A'+'a' : *lo w; 979 *low = (isascii(*low) && isupper_l(*low, __cloc())) ? *low-'A'+'a' : *lo w;
976 #endif 980 #endif
977 return low; 981 return low;
978 } 982 }
979 983
980 char 984 char
981 ctype<char>::do_widen(char c) const 985 ctype<char>::do_widen(char c) const
982 { 986 {
(...skipping 20 matching lines...) Expand all
1003 ctype<char>::do_narrow(const char_type* low, const char_type* high, char dfault, char* dest) const 1007 ctype<char>::do_narrow(const char_type* low, const char_type* high, char dfault, char* dest) const
1004 { 1008 {
1005 for (; low != high; ++low, ++dest) 1009 for (; low != high; ++low, ++dest)
1006 if (isascii(*low)) 1010 if (isascii(*low))
1007 *dest = *low; 1011 *dest = *low;
1008 else 1012 else
1009 *dest = dfault; 1013 *dest = dfault;
1010 return low; 1014 return low;
1011 } 1015 }
1012 1016
1013 #ifdef __EMSCRIPTEN__ 1017 #if defined(__EMSCRIPTEN__) || defined(_LIBCPP_HAS_MUSL_LIBC)
1014 extern "C" const unsigned short ** __ctype_b_loc(); 1018 extern "C" const unsigned short ** __ctype_b_loc();
1015 extern "C" const int ** __ctype_tolower_loc(); 1019 extern "C" const int ** __ctype_tolower_loc();
1016 extern "C" const int ** __ctype_toupper_loc(); 1020 extern "C" const int ** __ctype_toupper_loc();
1017 #endif 1021 #endif
1018 1022
1019 const ctype<char>::mask* 1023 const ctype<char>::mask*
1020 ctype<char>::classic_table() _NOEXCEPT 1024 ctype<char>::classic_table() _NOEXCEPT
1021 { 1025 {
1022 #if defined(__APPLE__) || defined(__FreeBSD__) 1026 #if defined(__APPLE__) || defined(__FreeBSD__)
1023 return _DefaultRuneLocale.__runetype; 1027 return _DefaultRuneLocale.__runetype;
1024 #elif defined(__NetBSD__) 1028 #elif defined(__NetBSD__)
1025 return _C_ctype_tab_ + 1; 1029 return _C_ctype_tab_ + 1;
1026 #elif defined(__GLIBC__) 1030 #elif defined(__GLIBC__)
1027 return __cloc()->__ctype_b; 1031 return __cloc()->__ctype_b;
1028 #elif __sun__ 1032 #elif __sun__
1029 return __ctype_mask; 1033 return __ctype_mask;
1030 #elif defined(_LIBCPP_MSVCRT) || defined(__MINGW32__) 1034 #elif defined(_LIBCPP_MSVCRT) || defined(__MINGW32__)
1031 return _ctype+1; // internal ctype mask table defined in msvcrt.dll 1035 return _ctype+1; // internal ctype mask table defined in msvcrt.dll
1032 // This is assumed to be safe, which is a nonsense assumption because we're 1036 // This is assumed to be safe, which is a nonsense assumption because we're
1033 // going to end up dereferencing it later... 1037 // going to end up dereferencing it later...
1034 #elif defined(__EMSCRIPTEN__) 1038 #elif defined(__EMSCRIPTEN__) || defined(_LIBCPP_HAS_MUSL_LIBC)
1035 return *__ctype_b_loc(); 1039 return *__ctype_b_loc();
1036 #elif defined(_NEWLIB_VERSION) // @LOCALMOD-START 1040 #elif defined(_NEWLIB_VERSION) // @LOCALMOD-START
1037 // Newlib has a 257-entry table in ctype_.c, where (char)0 starts at [1]. 1041 // Newlib has a 257-entry table in ctype_.c, where (char)0 starts at [1].
1038 return _ctype_ + 1; 1042 return _ctype_ + 1;
1039 // @LOCALMOD-END 1043 // @LOCALMOD-END
1040 #elif defined(_AIX) 1044 #elif defined(_AIX)
1041 return (const unsigned int *)__lc_ctype_ptr->obj->mask; 1045 return (const unsigned int *)__lc_ctype_ptr->obj->mask;
1042 #elif defined(__ANDROID__) 1046 #elif defined(__ANDROID__)
1043 return reinterpret_cast<const unsigned char*>(_ctype_) + 1; 1047 return reinterpret_cast<const unsigned char*>(_ctype_) + 1;
1044 #else 1048 #else
(...skipping 24 matching lines...) Expand all
1069 { 1073 {
1070 return _C_tolower_tab_ + 1; 1074 return _C_tolower_tab_ + 1;
1071 } 1075 }
1072 1076
1073 const short* 1077 const short*
1074 ctype<char>::__classic_upper_table() _NOEXCEPT 1078 ctype<char>::__classic_upper_table() _NOEXCEPT
1075 { 1079 {
1076 return _C_toupper_tab_ + 1; 1080 return _C_toupper_tab_ + 1;
1077 } 1081 }
1078 1082
1079 #elif defined(__EMSCRIPTEN__) 1083 #elif defined(__EMSCRIPTEN__) || defined(_LIBCPP_HAS_MUSL_LIBC)
1080 const int* 1084 const int*
1081 ctype<char>::__classic_lower_table() _NOEXCEPT 1085 ctype<char>::__classic_lower_table() _NOEXCEPT
1082 { 1086 {
1083 return *__ctype_tolower_loc(); 1087 return *__ctype_tolower_loc();
1084 } 1088 }
1085 1089
1086 const int* 1090 const int*
1087 ctype<char>::__classic_upper_table() _NOEXCEPT 1091 ctype<char>::__classic_upper_table() _NOEXCEPT
1088 { 1092 {
1089 return *__ctype_toupper_loc(); 1093 return *__ctype_toupper_loc();
1090 } 1094 }
1091 #endif // __GLIBC__ || __EMSCRIPTEN__ || __NETBSD__ 1095 #endif // __GLIBC__ || __NETBSD__ || __EMSCRIPTEN__ || defined(_LIBCPP_HAS_MUSL_ LIBC)
1092 1096
1093 // template <> class ctype_byname<char> 1097 // template <> class ctype_byname<char>
1094 1098
1095 ctype_byname<char>::ctype_byname(const char* name, size_t refs) 1099 ctype_byname<char>::ctype_byname(const char* name, size_t refs)
1096 : ctype<char>(0, false, refs), 1100 : ctype<char>(0, false, refs),
1097 __l(newlocale(LC_ALL_MASK, name, 0)) 1101 __l(newlocale(LC_ALL_MASK, name, 0))
1098 { 1102 {
1099 #ifndef _LIBCPP_NO_EXCEPTIONS 1103 #ifndef _LIBCPP_NO_EXCEPTIONS
1100 if (__l == 0) 1104 if (__l == 0)
1101 throw runtime_error("ctype_byname<char>::ctype_byname" 1105 throw runtime_error("ctype_byname<char>::ctype_byname"
(...skipping 5062 matching lines...) Expand 10 before | Expand all | Expand 10 after
6164 template class messages_byname<wchar_t>; 6168 template class messages_byname<wchar_t>;
6165 6169
6166 template class codecvt_byname<char, char, mbstate_t>; 6170 template class codecvt_byname<char, char, mbstate_t>;
6167 template class codecvt_byname<wchar_t, char, mbstate_t>; 6171 template class codecvt_byname<wchar_t, char, mbstate_t>;
6168 template class codecvt_byname<char16_t, char, mbstate_t>; 6172 template class codecvt_byname<char16_t, char, mbstate_t>;
6169 template class codecvt_byname<char32_t, char, mbstate_t>; 6173 template class codecvt_byname<char32_t, char, mbstate_t>;
6170 6174
6171 template class __vector_base_common<true>; 6175 template class __vector_base_common<true>;
6172 6176
6173 _LIBCPP_END_NAMESPACE_STD 6177 _LIBCPP_END_NAMESPACE_STD
OLDNEW
« no previous file with comments | « include/support/musl/xlocale.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698