[Patch] libc++: Add a default rune table

Joerg Sonnenberger joerg at britannica.bec.de
Thu Dec 11 03:40:10 PST 2014


On Thu, Dec 11, 2014 at 11:21:50AM +0100, Ed Schouten wrote:
> Index: src/locale.cpp
> ===================================================================
> --- src/locale.cpp	(revision 224007)
> +++ src/locale.cpp	(working copy)
> @@ -808,13 +808,7 @@
>  wchar_t
>  ctype<wchar_t>::do_toupper(char_type c) const
>  {
> -#ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
> -    return isascii(c) ? _DefaultRuneLocale.__mapupper[c] : c;
> -#elif defined(__GLIBC__) || defined(__EMSCRIPTEN__) || defined(__NetBSD__)
> -    return isascii(c) ? ctype<char>::__classic_upper_table()[c] : c;
> -#else
> -    return (isascii(c) && iswlower_l(c, __cloc())) ? c-L'a'+L'A' : c;
> -#endif
> +    return (c >= L'a' && c <= L'z') ? c - L'a' + L'A' : c;

Regression?

> @@ -835,13 +822,7 @@
>  wchar_t
>  ctype<wchar_t>::do_tolower(char_type c) const
>  {
> -#ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
> -    return isascii(c) ? _DefaultRuneLocale.__maplower[c] : c;
> -#elif defined(__GLIBC__) || defined(__EMSCRIPTEN__) || defined(__NetBSD__)
> -    return isascii(c) ? ctype<char>::__classic_lower_table()[c] : c;
> -#else
> -    return (isascii(c) && isupper_l(c, __cloc())) ? c-L'A'+'a' : c;
> -#endif
> +    return (c >= L'A' && c <= L'Z') ? c - L'A' + L'a' : c;
>  }

Same.

> @@ -914,17 +885,7 @@
>  char
>  ctype<char>::do_toupper(char_type c) const
>  {
> -#ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
> -    return isascii(c) ?
> -      static_cast<char>(_DefaultRuneLocale.__mapupper[static_cast<ptrdiff_t>(c)]) : c;
> -#elif defined(__NetBSD__)
> -    return static_cast<char>(__classic_upper_table()[static_cast<unsigned char>(c)]);
> -#elif defined(__GLIBC__) || defined(__EMSCRIPTEN__)
> -    return isascii(c) ? 
> -      static_cast<char>(__classic_upper_table()[static_cast<unsigned char>(c)]) : c;
> -#else
> -    return (isascii(c) && islower_l(c, __cloc())) ? c-'a'+'A' : c;
> -#endif
> +    return (c >= 'a' && c <= 'z') ? c - 'a' + 'A' : c;
>  }

Same.

> @@ -948,17 +899,7 @@
>  char
>  ctype<char>::do_tolower(char_type c) const
>  {
> -#ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
> -    return isascii(c) ?
> -      static_cast<char>(_DefaultRuneLocale.__maplower[static_cast<ptrdiff_t>(c)]) : c;
> -#elif defined(__NetBSD__)
> -    return static_cast<char>(__classic_lower_table()[static_cast<unsigned char>(c)]);
> -#elif defined(__GLIBC__) || defined(__EMSCRIPTEN__) || defined(__NetBSD__)
> -    return isascii(c) ?
> -      static_cast<char>(__classic_lower_table()[static_cast<size_t>(c)]) : c;
> -#else
> -    return (isascii(c) && isupper_l(c, __cloc())) ? c-'A'+'a' : c;
> -#endif
> +    return (c >= 'A' && c <= 'Z') ? c - 'A' + 'a' : c;
>  }

Same.

> @@ -1019,73 +949,76 @@
>  const ctype<char>::mask*
>  ctype<char>::classic_table()  _NOEXCEPT
>  {
> -#if defined(__APPLE__) || defined(__FreeBSD__)
> -    return _DefaultRuneLocale.__runetype;
> -#elif defined(__NetBSD__)
> -    return _C_ctype_tab_ + 1;
> -#elif defined(__GLIBC__)
> -    return __cloc()->__ctype_b;
> -#elif __sun__
> -    return __ctype_mask;
> -#elif defined(_LIBCPP_MSVCRT) || defined(__MINGW32__)
> -    return _ctype+1; // internal ctype mask table defined in msvcrt.dll
> -// This is assumed to be safe, which is a nonsense assumption because we're
> -// going to end up dereferencing it later...
> -#elif defined(__EMSCRIPTEN__)
> -    return *__ctype_b_loc();
> -#elif defined(_AIX)
> -    return (const unsigned int *)__lc_ctype_ptr->obj->mask;
> -#elif defined(__ANDROID__)
> -    return reinterpret_cast<const unsigned char*>(_ctype_) + 1;
> -#else
> -    // Platform not supported: abort so the person doing the port knows what to
> -    // fix
> -# warning  ctype<char>::classic_table() is not implemented
> -    printf("ctype<char>::classic_table() is not implemented\n");
> -    abort();
> -    return NULL;
> -#endif
> +    // Character type information for US-ASCII.
> +    static const ctype<char>::mask builtin_table[table_size] = {
> +        cntrl,                          cntrl,
> +        cntrl,                          cntrl,
> +        cntrl,                          cntrl,
> +        cntrl,                          cntrl,
> +        cntrl,                          cntrl | space | blank,
> +        cntrl | space,                  cntrl | space,
> +        cntrl | space,                  cntrl | space,
> +        cntrl,                          cntrl,
> +        cntrl,                          cntrl,
> +        cntrl,                          cntrl,
> +        cntrl,                          cntrl,
> +        cntrl,                          cntrl,
> +        cntrl,                          cntrl,
> +        cntrl,                          cntrl,
> +        cntrl,                          cntrl,
> +        cntrl,                          cntrl,
> +        space | blank | print,          punct | print,
> +        punct | print,                  punct | print,
> +        punct | print,                  punct | print,
> +        punct | print,                  punct | print,
> +        punct | print,                  punct | print,
> +        punct | print,                  punct | print,
> +        punct | print,                  punct | print,
> +        punct | print,                  punct | print,
> +        digit | print | xdigit,         digit | print | xdigit,
> +        digit | print | xdigit,         digit | print | xdigit,
> +        digit | print | xdigit,         digit | print | xdigit,
> +        digit | print | xdigit,         digit | print | xdigit,
> +        digit | print | xdigit,         digit | print | xdigit,
> +        punct | print,                  punct | print,
> +        punct | print,                  punct | print,
> +        punct | print,                  punct | print,
> +        punct | print,                  upper | xdigit | print | alpha,
> +        upper | xdigit | print | alpha, upper | xdigit | print | alpha,
> +        upper | xdigit | print | alpha, upper | xdigit | print | alpha,
> +        upper | xdigit | print | alpha, upper | print | alpha,
> +        upper | print | alpha,          upper | print | alpha,
> +        upper | print | alpha,          upper | print | alpha,
> +        upper | print | alpha,          upper | print | alpha,
> +        upper | print | alpha,          upper | print | alpha,
> +        upper | print | alpha,          upper | print | alpha,
> +        upper | print | alpha,          upper | print | alpha,
> +        upper | print | alpha,          upper | print | alpha,
> +        upper | print | alpha,          upper | print | alpha,
> +        upper | print | alpha,          upper | print | alpha,
> +        upper | print | alpha,          punct | print,
> +        punct | print,                  punct | print,
> +        punct | print,                  punct | print,
> +        punct | print,                  lower | xdigit | print | alpha,
> +        lower | xdigit | print | alpha, lower | xdigit | print | alpha,
> +        lower | xdigit | print | alpha, lower | xdigit | print | alpha,
> +        lower | xdigit | print | alpha, lower | print | alpha,
> +        lower | print | alpha,          lower | print | alpha,
> +        lower | print | alpha,          lower | print | alpha,
> +        lower | print | alpha,          lower | print | alpha,
> +        lower | print | alpha,          lower | print | alpha,
> +        lower | print | alpha,          lower | print | alpha,
> +        lower | print | alpha,          lower | print | alpha,
> +        lower | print | alpha,          lower | print | alpha,
> +        lower | print | alpha,          lower | print | alpha,
> +        lower | print | alpha,          lower | print | alpha,
> +        lower | print | alpha,          punct | print,
> +        punct | print,                  punct | print,
> +        punct | print,                  cntrl,
> +    };
> +    return builtin_table;
>  }

Please properly use the system table, no need to waste space.

Joerg



More information about the cfe-commits mailing list