@@ -786,7 +786,7 @@ ctype<wchar_t>::do_toupper(char_type c) const
786786{
787787#ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
788788 return isascii (c) ? _DefaultRuneLocale.__mapupper [c] : c;
789- #elif defined(__GLIBC__)
789+ #elif defined(__GLIBC__) || defined(EMSCRIPTEN)
790790 return isascii (c) ? ctype<char >::__classic_upper_table ()[c] : c;
791791#else
792792 return (isascii (c) && iswlower_l (c, __cloc ())) ? c-L' a' +L' A' : c;
@@ -799,7 +799,7 @@ ctype<wchar_t>::do_toupper(char_type* low, const char_type* high) const
799799 for (; low != high; ++low)
800800#ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
801801 *low = isascii (*low) ? _DefaultRuneLocale.__mapupper [*low] : *low;
802- #elif defined(__GLIBC__)
802+ #elif defined(__GLIBC__) || defined(EMSCRIPTEN)
803803 *low = isascii (*low) ? ctype<char >::__classic_upper_table ()[*low]
804804 : *low;
805805#else
@@ -813,7 +813,7 @@ ctype<wchar_t>::do_tolower(char_type c) const
813813{
814814#ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
815815 return isascii (c) ? _DefaultRuneLocale.__maplower [c] : c;
816- #elif defined(__GLIBC__)
816+ #elif defined(__GLIBC__) || defined(EMSCRIPTEN)
817817 return isascii (c) ? ctype<char >::__classic_lower_table ()[c] : c;
818818#else
819819 return (isascii (c) && isupper_l (c, __cloc ())) ? c-L' A' +' a' : c;
@@ -826,7 +826,7 @@ ctype<wchar_t>::do_tolower(char_type* low, const char_type* high) const
826826 for (; low != high; ++low)
827827#ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
828828 *low = isascii (*low) ? _DefaultRuneLocale.__maplower [*low] : *low;
829- #elif defined(__GLIBC__)
829+ #elif defined(__GLIBC__) || defined(EMSCRIPTEN)
830830 *low = isascii (*low) ? ctype<char >::__classic_lower_table ()[*low]
831831 : *low;
832832#else
@@ -893,7 +893,7 @@ ctype<char>::do_toupper(char_type c) const
893893#ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
894894 return isascii (c) ?
895895 static_cast <char >(_DefaultRuneLocale.__mapupper [static_cast <ptrdiff_t >(c)]) : c;
896- #elif defined(__GLIBC__)
896+ #elif defined(__GLIBC__) || defined(EMSCRIPTEN)
897897 return isascii (c) ?
898898 static_cast <char >(__classic_upper_table ()[static_cast <size_t >(c)]) : c;
899899#else
@@ -908,7 +908,7 @@ ctype<char>::do_toupper(char_type* low, const char_type* high) const
908908#ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
909909 *low = isascii (*low) ?
910910 static_cast <char >(_DefaultRuneLocale.__mapupper [static_cast <ptrdiff_t >(*low)]) : *low;
911- #elif defined(__GLIBC__)
911+ #elif defined(__GLIBC__) || defined(EMSCRIPTEN)
912912 *low = isascii (*low) ?
913913 static_cast <char >(__classic_upper_table ()[static_cast <size_t >(*low)]) : *low;
914914#else
@@ -923,7 +923,7 @@ ctype<char>::do_tolower(char_type c) const
923923#ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
924924 return isascii (c) ?
925925 static_cast <char >(_DefaultRuneLocale.__maplower [static_cast <ptrdiff_t >(c)]) : c;
926- #elif defined(__GLIBC__)
926+ #elif defined(__GLIBC__) || defined(EMSCRIPTEN)
927927 return isascii (c) ?
928928 static_cast <char >(__classic_lower_table ()[static_cast <size_t >(c)]) : c;
929929#else
@@ -937,7 +937,7 @@ ctype<char>::do_tolower(char_type* low, const char_type* high) const
937937 for (; low != high; ++low)
938938#ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
939939 *low = isascii (*low) ? static_cast <char >(_DefaultRuneLocale.__maplower [static_cast <ptrdiff_t >(*low)]) : *low;
940- #elif defined(__GLIBC__)
940+ #elif defined(__GLIBC__) || defined(EMSCRIPTEN)
941941 *low = isascii (*low) ? static_cast <char >(__classic_lower_table ()[static_cast <size_t >(*low)]) : *low;
942942#else
943943 *low = (isascii (*low) && isupper_l (*low, __cloc ())) ? *low-' A' +' a' : *low;
@@ -978,6 +978,12 @@ ctype<char>::do_narrow(const char_type* low, const char_type* high, char dfault,
978978 return low;
979979}
980980
981+ #ifdef EMSCRIPTEN
982+ extern " C" const unsigned short ** __ctype_b_loc ();
983+ extern " C" const int ** __ctype_tolower_loc ();
984+ extern " C" const int ** __ctype_toupper_loc ();
985+ #endif
986+
981987const ctype<char >::mask*
982988ctype<char >::classic_table () _NOEXCEPT
983989{
@@ -991,6 +997,8 @@ ctype<char>::classic_table() _NOEXCEPT
991997 return _ctype+1 ; // internal ctype mask table defined in msvcrt.dll
992998// This is assumed to be safe, which is a nonsense assumption because we're
993999// going to end up dereferencing it later...
1000+ #elif defined(EMSCRIPTEN)
1001+ return *__ctype_b_loc ();
9941002#else
9951003 // Platform not supported: abort so the person doing the port knows what to
9961004 // fix
@@ -1014,6 +1022,20 @@ ctype<char>::__classic_upper_table() _NOEXCEPT
10141022}
10151023#endif // __GLIBC__
10161024
1025+ #if defined(EMSCRIPTEN)
1026+ const int *
1027+ ctype<char >::__classic_lower_table () _NOEXCEPT
1028+ {
1029+ return *__ctype_tolower_loc ();
1030+ }
1031+
1032+ const int *
1033+ ctype<char >::__classic_upper_table () _NOEXCEPT
1034+ {
1035+ return *__ctype_toupper_loc ();
1036+ }
1037+ #endif // EMSCRIPTEN
1038+
10171039// template <> class ctype_byname<char>
10181040
10191041ctype_byname<char >::ctype_byname (const char * name, size_t refs)
0 commit comments