From 28f7c510a52113a3d65302ee3d8c390ef5b8e0da Mon Sep 17 00:00:00 2001 From: bolero-MURAKAMI Date: Sun, 15 Apr 2012 10:31:49 +0900 Subject: [PATCH] add cwchar.hpp rename decimal_to_int -> ascii_to_int --- sprout/cctype.hpp | 2 +- sprout/cstdlib/ascii_to_int.hpp | 60 +++++++++++++++++++++++++++++++ sprout/cstdlib/atoi.hpp | 6 ++-- sprout/cstdlib/atol.hpp | 8 ++--- sprout/cstdlib/atoll.hpp | 20 +++++++++++ sprout/cstdlib/conversion.hpp | 6 +++- sprout/cstdlib/decimal_to_int.hpp | 51 -------------------------- sprout/cstdlib/str_to_int.hpp | 11 +++++- sprout/cstdlib/strtoll.hpp | 29 +++++++++++++++ sprout/cstdlib/strtoul.hpp | 29 +++++++++++++++ sprout/cstdlib/strtoull.hpp | 29 +++++++++++++++ sprout/cstring/memchr.hpp | 2 +- sprout/cstring/memcmp.hpp | 2 +- sprout/ctype.hpp | 1 + sprout/ctype/ascii.hpp | 46 ++++++++++++------------ sprout/ctype/wascii.hpp | 44 +++++++++++++++++++++++ sprout/cwchar.hpp | 18 ++++++++++ sprout/cwchar/wcschr.hpp | 22 ++++++++++++ sprout/cwchar/wcscmp.hpp | 19 ++++++++++ sprout/cwchar/wcscoll.hpp | 15 ++++++++ sprout/cwchar/wcscspn.hpp | 24 +++++++++++++ sprout/cwchar/wcslen.hpp | 23 ++++++++++++ sprout/cwchar/wcsncmp.hpp | 20 +++++++++++ sprout/cwchar/wcspbrk.hpp | 23 ++++++++++++ sprout/cwchar/wcsrchr.hpp | 22 ++++++++++++ sprout/cwchar/wcsspn.hpp | 24 +++++++++++++ sprout/cwchar/wcsstr.hpp | 22 ++++++++++++ sprout/cwchar/wmemchr.hpp | 30 ++++++++++++++++ sprout/cwchar/wmemcmp.hpp | 28 +++++++++++++++ sprout/cwctype.hpp | 7 ++++ sprout/detail/char_conversion.hpp | 9 ++--- sprout/preprocessor.hpp | 1 + sprout/preprocessor/cat.hpp | 3 +- sprout/preprocessor/empty.hpp | 12 +++++++ 34 files changed, 576 insertions(+), 92 deletions(-) create mode 100644 sprout/cstdlib/ascii_to_int.hpp create mode 100644 sprout/cstdlib/atoll.hpp delete mode 100644 sprout/cstdlib/decimal_to_int.hpp create mode 100644 sprout/cstdlib/strtoll.hpp create mode 100644 sprout/cstdlib/strtoul.hpp create mode 100644 sprout/cstdlib/strtoull.hpp create mode 100644 sprout/ctype/wascii.hpp create mode 100644 sprout/cwchar.hpp create mode 100644 sprout/cwchar/wcschr.hpp create mode 100644 sprout/cwchar/wcscmp.hpp create mode 100644 sprout/cwchar/wcscoll.hpp create mode 100644 sprout/cwchar/wcscspn.hpp create mode 100644 sprout/cwchar/wcslen.hpp create mode 100644 sprout/cwchar/wcsncmp.hpp create mode 100644 sprout/cwchar/wcspbrk.hpp create mode 100644 sprout/cwchar/wcsrchr.hpp create mode 100644 sprout/cwchar/wcsspn.hpp create mode 100644 sprout/cwchar/wcsstr.hpp create mode 100644 sprout/cwchar/wmemchr.hpp create mode 100644 sprout/cwchar/wmemcmp.hpp create mode 100644 sprout/cwctype.hpp create mode 100644 sprout/preprocessor/empty.hpp diff --git a/sprout/cctype.hpp b/sprout/cctype.hpp index 56fd9235..20ff9742 100644 --- a/sprout/cctype.hpp +++ b/sprout/cctype.hpp @@ -2,6 +2,6 @@ #define SPROUT_CCTYPE_HPP #include -#include +#include #endif // #ifndef SPROUT_CCTYPE_HPP diff --git a/sprout/cstdlib/ascii_to_int.hpp b/sprout/cstdlib/ascii_to_int.hpp new file mode 100644 index 00000000..3b96f246 --- /dev/null +++ b/sprout/cstdlib/ascii_to_int.hpp @@ -0,0 +1,60 @@ +#ifndef SPROUT_CSTDLIB_DECIMAL_TO_INT_HPP +#define SPROUT_CSTDLIB_DECIMAL_TO_INT_HPP + +#include +#include +#include +#include +#include +#include +#include + +namespace sprout { + namespace detail { + // Copyright (c) 2011 osyo-manga : http://d.hatena.ne.jp/osyo-manga/ + + template + inline SPROUT_CONSTEXPR IntType ascii_to_int_impl(CStrIterator str, IntType val, bool negative) { + return !sprout::ascii::isdigit(*str) + ? negative ? -val : val + : val > (std::numeric_limits::max() - (*str - static_cast::value_type>('0')) - (negative ? 1 : 0)) / 10 + ? (negative ? std::numeric_limits::min() : std::numeric_limits::max()) + : sprout::detail::ascii_to_int_impl( + sprout::next(str), + val * 10 + (*str - static_cast::value_type>('0')), + negative + ) + ; + } + template::value>::type = sprout::enabler> + inline SPROUT_CONSTEXPR IntType ascii_to_int(CStrIterator str) { + return sprout::ascii::isspace(*str) + ? sprout::detail::ascii_to_int(sprout::next(str)) + : *str == static_cast::value_type>('+') + ? sprout::detail::ascii_to_int_impl(sprout::next(str), IntType(), false) + : sprout::detail::ascii_to_int_impl(str, IntType(), false) + ; + } + template::value>::type = sprout::enabler> + inline SPROUT_CONSTEXPR IntType ascii_to_int(CStrIterator str) { + return sprout::ascii::isspace(*str) + ? sprout::detail::ascii_to_int(sprout::next(str)) + : *str == static_cast::value_type>('-') + ? sprout::detail::ascii_to_int_impl(sprout::next(str), IntType(), true) + : *str == static_cast::value_type>('+') + ? sprout::detail::ascii_to_int_impl(sprout::next(str), IntType(), false) + : sprout::detail::ascii_to_int_impl(str, IntType(), false) + ; + } + } // namespace detail + + // + // ascii_to_int + // + template::value>::type = sprout::enabler> + inline SPROUT_CONSTEXPR IntType ascii_to_int(Char const* str) { + return sprout::detail::ascii_to_int(str); + } +} // namespace sprout + +#endif // #ifndef SPROUT_CSTDLIB_DECIMAL_TO_INT_HPP diff --git a/sprout/cstdlib/atoi.hpp b/sprout/cstdlib/atoi.hpp index d8745310..f0906d11 100644 --- a/sprout/cstdlib/atoi.hpp +++ b/sprout/cstdlib/atoi.hpp @@ -2,18 +2,18 @@ #define SPROUT_CSTDLIB_ATOI_HPP #include -#include +#include namespace sprout { // // atoi // inline SPROUT_CONSTEXPR int atoi(char const* str) { - return sprout::decimal_to_int(str); + return sprout::ascii_to_int(str); } template inline SPROUT_CONSTEXPR int atoi(Char const* str) { - return sprout::decimal_to_int(str); + return sprout::ascii_to_int(str); } } // namespace sprout diff --git a/sprout/cstdlib/atol.hpp b/sprout/cstdlib/atol.hpp index 81cbf6bd..8210ed0c 100644 --- a/sprout/cstdlib/atol.hpp +++ b/sprout/cstdlib/atol.hpp @@ -2,18 +2,18 @@ #define SPROUT_CSTDLIB_ATOL_HPP #include -#include +#include namespace sprout { // // atol // inline SPROUT_CONSTEXPR long atol(char const* str) { - return sprout::decimal_to_int(str); + return sprout::ascii_to_int(str); } template - inline SPROUT_CONSTEXPR int atol(Char const* str) { - return sprout::decimal_to_int(str); + inline SPROUT_CONSTEXPR long atol(Char const* str) { + return sprout::ascii_to_int(str); } } // namespace sprout diff --git a/sprout/cstdlib/atoll.hpp b/sprout/cstdlib/atoll.hpp new file mode 100644 index 00000000..a54dcdbc --- /dev/null +++ b/sprout/cstdlib/atoll.hpp @@ -0,0 +1,20 @@ +#ifndef SPROUT_CSTDLIB_ATOLL_HPP +#define SPROUT_CSTDLIB_ATOLL_HPP + +#include +#include + +namespace sprout { + // + // atoll + // + inline SPROUT_CONSTEXPR long long atoll(char const* str) { + return sprout::ascii_to_int(str); + } + template + inline SPROUT_CONSTEXPR long long atoll(Char const* str) { + return sprout::ascii_to_int(str); + } +} // namespace sprout + +#endif // #ifndef SPROUT_CSTDLIB_ATOLL_HPP diff --git a/sprout/cstdlib/conversion.hpp b/sprout/cstdlib/conversion.hpp index a4ad07a5..acde2a35 100644 --- a/sprout/cstdlib/conversion.hpp +++ b/sprout/cstdlib/conversion.hpp @@ -2,10 +2,14 @@ #define SPROUT_CSTDLIB_CONVERSION_HPP #include -#include +#include #include #include #include +#include #include +#include +#include +#include #endif // #ifndef SPROUT_CSTDLIB_CONVERSION_HPP diff --git a/sprout/cstdlib/decimal_to_int.hpp b/sprout/cstdlib/decimal_to_int.hpp deleted file mode 100644 index 7ef60f27..00000000 --- a/sprout/cstdlib/decimal_to_int.hpp +++ /dev/null @@ -1,51 +0,0 @@ -#ifndef SPROUT_CSTDLIB_DECIMAL_TO_INT_HPP -#define SPROUT_CSTDLIB_DECIMAL_TO_INT_HPP - -#include -#include -#include -#include -#include -#include -#include - -namespace sprout { - namespace detail { - // Copyright (c) 2011 osyo-manga : http://d.hatena.ne.jp/osyo-manga/ - - template - inline SPROUT_CONSTEXPR IntType decimal_to_int_impl(CStrIterator str, IntType val, bool negative) { - return !sprout::ascii::isdigit(*str) - ? negative ? -val : val - : val > (std::numeric_limits::max() - (*str - static_cast::value_type>('0')) - (negative ? 1 : 0)) / 10 - ? (negative ? std::numeric_limits::min() : std::numeric_limits::max()) - : sprout::detail::decimal_to_int_impl( - sprout::next(str), - val * 10 + (*str - static_cast::value_type>('0')), - negative - ) - ; - } - template - inline SPROUT_CONSTEXPR IntType decimal_to_int(CStrIterator str) { - return sprout::ascii::isspace(*str) - ? sprout::detail::decimal_to_int(sprout::next(str)) - : *str == static_cast::value_type>('-') - ? sprout::detail::decimal_to_int_impl(sprout::next(str), IntType(), true) - : *str == static_cast::value_type>('+') - ? sprout::detail::decimal_to_int_impl(sprout::next(str), IntType(), false) - : sprout::detail::decimal_to_int_impl(str, IntType(), false) - ; - } - } // namespace detail - - // - // decimal_to_int - // - template::value>::type = sprout::enabler> - inline SPROUT_CONSTEXPR IntType decimal_to_int(Char const* str) { - return sprout::detail::decimal_to_int(str); - } -} // namespace sprout - -#endif // #ifndef SPROUT_CSTDLIB_DECIMAL_TO_INT_HPP diff --git a/sprout/cstdlib/str_to_int.hpp b/sprout/cstdlib/str_to_int.hpp index 3f899b51..784be7c0 100644 --- a/sprout/cstdlib/str_to_int.hpp +++ b/sprout/cstdlib/str_to_int.hpp @@ -56,7 +56,16 @@ namespace sprout { ) ; } - template + template::value>::type = sprout::enabler> + inline SPROUT_CONSTEXPR IntType str_to_int(CStrIterator str, int base) { + return sprout::ascii::isspace(*str) + ? sprout::detail::str_to_int(sprout::next(str), base) + : *str == static_cast::value_type>('+') + ? sprout::detail::str_to_int_impl(sprout::next(str), base, false) + : sprout::detail::str_to_int_impl(str, base, false) + ; + } + template::value>::type = sprout::enabler> inline SPROUT_CONSTEXPR IntType str_to_int(CStrIterator str, int base) { return sprout::ascii::isspace(*str) ? sprout::detail::str_to_int(sprout::next(str), base) diff --git a/sprout/cstdlib/strtoll.hpp b/sprout/cstdlib/strtoll.hpp new file mode 100644 index 00000000..32782f03 --- /dev/null +++ b/sprout/cstdlib/strtoll.hpp @@ -0,0 +1,29 @@ +#ifndef SPROUT_CSTDLIB_STRTOLL_HPP +#define SPROUT_CSTDLIB_STRTOLL_HPP + +#include +#include +#include + +namespace sprout { + // + // strtol + // + inline SPROUT_CONSTEXPR long long strtoll(char const* str, char** endptr, int base = 10){ + return sprout::str_to_int(str, endptr, base); + } + template + inline SPROUT_CONSTEXPR long long strtoll(Char const* str, Char** endptr, int base = 10){ + return sprout::str_to_int(str, endptr, base); + } + template + inline SPROUT_CONSTEXPR long long strtoll(Char const* str, std::nullptr_t endptr, int base = 10){ + return sprout::str_to_int(str, base); + } + template + inline SPROUT_CONSTEXPR long long strtoll(Char const* str, int base = 10){ + return sprout::str_to_int(str, base); + } +} // namespace sprout + +#endif // #ifndef SPROUT_CSTDLIB_STRTOLL_HPP diff --git a/sprout/cstdlib/strtoul.hpp b/sprout/cstdlib/strtoul.hpp new file mode 100644 index 00000000..b1e6990f --- /dev/null +++ b/sprout/cstdlib/strtoul.hpp @@ -0,0 +1,29 @@ +#ifndef SPROUT_CSTDLIB_STRTOUL_HPP +#define SPROUT_CSTDLIB_STRTOUL_HPP + +#include +#include +#include + +namespace sprout { + // + // strtoul + // + inline SPROUT_CONSTEXPR unsigned long strtoul(char const* str, char** endptr, int base = 10){ + return sprout::str_to_int(str, endptr, base); + } + template + inline SPROUT_CONSTEXPR unsigned long strtoul(Char const* str, Char** endptr, int base = 10){ + return sprout::str_to_int(str, endptr, base); + } + template + inline SPROUT_CONSTEXPR unsigned long strtoul(Char const* str, std::nullptr_t endptr, int base = 10){ + return sprout::str_to_int(str, base); + } + template + inline SPROUT_CONSTEXPR unsigned long strtoul(Char const* str, int base = 10){ + return sprout::str_to_int(str, base); + } +} // namespace sprout + +#endif // #ifndef SPROUT_CSTDLIB_STRTOUL_HPP diff --git a/sprout/cstdlib/strtoull.hpp b/sprout/cstdlib/strtoull.hpp new file mode 100644 index 00000000..f0c78f20 --- /dev/null +++ b/sprout/cstdlib/strtoull.hpp @@ -0,0 +1,29 @@ +#ifndef SPROUT_CSTDLIB_STRTTOULL_HPP +#define SPROUT_CSTDLIB_STRTTOULL_HPP + +#include +#include +#include + +namespace sprout { + // + // strtoul + // + inline SPROUT_CONSTEXPR unsigned long long strtoull(char const* str, char** endptr, int base = 10){ + return sprout::str_to_int(str, endptr, base); + } + template + inline SPROUT_CONSTEXPR unsigned long long strtoull(Char const* str, Char** endptr, int base = 10){ + return sprout::str_to_int(str, endptr, base); + } + template + inline SPROUT_CONSTEXPR unsigned long long strtoull(Char const* str, std::nullptr_t endptr, int base = 10){ + return sprout::str_to_int(str, base); + } + template + inline SPROUT_CONSTEXPR unsigned long long strtoull(Char const* str, int base = 10){ + return sprout::str_to_int(str, base); + } +} // namespace sprout + +#endif // #ifndef SPROUT_CSTDLIB_STRTTOULL_HPP diff --git a/sprout/cstring/memchr.hpp b/sprout/cstring/memchr.hpp index 089c59b7..1abff2d8 100644 --- a/sprout/cstring/memchr.hpp +++ b/sprout/cstring/memchr.hpp @@ -8,7 +8,7 @@ namespace sprout { // Copyright (C) 2011 RiSK (sscrisk) namespace detail { - inline SPROUT_CONSTEXPR void const* memchr_impl(unsigned char const* s, char c, std::size_t n) { + inline SPROUT_CONSTEXPR void const* memchr_impl(unsigned char const* s, unsigned char c, std::size_t n) { return !n ? 0 : *s == c ? s : sprout::detail::memchr_impl(s + 1, c, n - 1) diff --git a/sprout/cstring/memcmp.hpp b/sprout/cstring/memcmp.hpp index c9f40a67..766ba1dc 100644 --- a/sprout/cstring/memcmp.hpp +++ b/sprout/cstring/memcmp.hpp @@ -17,7 +17,7 @@ namespace sprout { } // namespace detail // 7.21.4.1 memcmp ֐ - inline SPROUT_CONSTEXPR int memcmp(void const * s1, void const * s2, std::size_t n) { + inline SPROUT_CONSTEXPR int memcmp(void const* s1, void const* s2, std::size_t n) { return sprout::detail::memcmp_impl( static_cast(s1), static_cast(s2), diff --git a/sprout/ctype.hpp b/sprout/ctype.hpp index 4412f4bd..d619e144 100644 --- a/sprout/ctype.hpp +++ b/sprout/ctype.hpp @@ -3,5 +3,6 @@ #include #include +#include #endif // #ifndef SPROUT_CTYPE_HPP diff --git a/sprout/ctype/ascii.hpp b/sprout/ctype/ascii.hpp index be629ced..e598c63e 100644 --- a/sprout/ctype/ascii.hpp +++ b/sprout/ctype/ascii.hpp @@ -3,6 +3,8 @@ #include #include +#include +#include namespace sprout { namespace ascii { @@ -177,48 +179,48 @@ namespace sprout { } } // namespace detail -#define SPROUT_CTYPE_DEFINE_ASCII(CHAR_TYPE) \ - SPROUT_CONSTEXPR bool isalnum(CHAR_TYPE c) { \ +#define SPROUT_CTYPE_ASCII_DECL(CHAR_TYPE, PREFIX) \ + SPROUT_CONSTEXPR bool SPROUT_PP_CAT(is, SPROUT_PP_CAT(PREFIX, alnum))(CHAR_TYPE c) { \ return sprout::ascii::detail::get_value(c) & (sprout::ascii::detail::alpha | sprout::ascii::detail::digit); \ } \ - SPROUT_CONSTEXPR bool isalpha(CHAR_TYPE c) { \ + SPROUT_CONSTEXPR bool SPROUT_PP_CAT(is, SPROUT_PP_CAT(PREFIX, alpha))(CHAR_TYPE c) { \ return sprout::ascii::detail::get_value(c) & sprout::ascii::detail::alpha; \ } \ - SPROUT_CONSTEXPR bool isblank(CHAR_TYPE c) { \ + SPROUT_CONSTEXPR bool SPROUT_PP_CAT(is, SPROUT_PP_CAT(PREFIX, blank))(CHAR_TYPE c) { \ return sprout::ascii::detail::get_value(c) & sprout::ascii::detail::blank; \ } \ - SPROUT_CONSTEXPR bool iscntrl(CHAR_TYPE c) { \ + SPROUT_CONSTEXPR bool SPROUT_PP_CAT(is, SPROUT_PP_CAT(PREFIX, cntrl))(CHAR_TYPE c) { \ return sprout::ascii::detail::get_value(c) & sprout::ascii::detail::cntrl; \ } \ - SPROUT_CONSTEXPR bool isdigit(CHAR_TYPE c) { \ + SPROUT_CONSTEXPR bool SPROUT_PP_CAT(is, SPROUT_PP_CAT(PREFIX, digit))(CHAR_TYPE c) { \ return sprout::ascii::detail::get_value(c) & sprout::ascii::detail::digit; \ } \ - SPROUT_CONSTEXPR bool isgraph(CHAR_TYPE c) { \ + SPROUT_CONSTEXPR bool SPROUT_PP_CAT(is, SPROUT_PP_CAT(PREFIX, graph))(CHAR_TYPE c) { \ return sprout::ascii::detail::get_value(c) & sprout::ascii::detail::graph; \ } \ - SPROUT_CONSTEXPR bool islower(CHAR_TYPE c) { \ + SPROUT_CONSTEXPR bool SPROUT_PP_CAT(is, SPROUT_PP_CAT(PREFIX, lower))(CHAR_TYPE c) { \ return sprout::ascii::detail::get_value(c) & sprout::ascii::detail::lower; \ } \ - SPROUT_CONSTEXPR bool isprint(CHAR_TYPE c) { \ + SPROUT_CONSTEXPR bool SPROUT_PP_CAT(is, SPROUT_PP_CAT(PREFIX, print))(CHAR_TYPE c) { \ return sprout::ascii::detail::get_value(c) & sprout::ascii::detail::print; \ } \ - SPROUT_CONSTEXPR bool ispunct(CHAR_TYPE c) { \ + SPROUT_CONSTEXPR bool SPROUT_PP_CAT(is, SPROUT_PP_CAT(PREFIX, punct))(CHAR_TYPE c) { \ return sprout::ascii::detail::get_value(c) & sprout::ascii::detail::punct; \ } \ - SPROUT_CONSTEXPR bool isspace(CHAR_TYPE c) { \ + SPROUT_CONSTEXPR bool SPROUT_PP_CAT(is, SPROUT_PP_CAT(PREFIX, space))(CHAR_TYPE c) { \ return sprout::ascii::detail::get_value(c) & sprout::ascii::detail::space; \ } \ - SPROUT_CONSTEXPR bool isupper(CHAR_TYPE c) { \ + SPROUT_CONSTEXPR bool SPROUT_PP_CAT(is, SPROUT_PP_CAT(PREFIX, upper))(CHAR_TYPE c) { \ return sprout::ascii::detail::get_value(c) & sprout::ascii::detail::upper; \ } \ - SPROUT_CONSTEXPR bool isxdigit(CHAR_TYPE c) { \ + SPROUT_CONSTEXPR bool SPROUT_PP_CAT(is, SPROUT_PP_CAT(PREFIX, xdigit))(CHAR_TYPE c) { \ return sprout::ascii::detail::get_value(c) & sprout::ascii::detail::xdigit; \ } \ - SPROUT_CONSTEXPR CHAR_TYPE tolower(CHAR_TYPE c) { \ - return sprout::ascii::isupper(c) ? c + (0x61 - 0x41) : c; \ + SPROUT_CONSTEXPR CHAR_TYPE SPROUT_PP_CAT(to, SPROUT_PP_CAT(PREFIX, lower))(CHAR_TYPE c) { \ + return sprout::ascii::detail::get_value(c) & sprout::ascii::detail::lower ? c + (0x61 - 0x41) : c; \ } \ - SPROUT_CONSTEXPR CHAR_TYPE toupper(CHAR_TYPE c) { \ - return sprout::ascii::islower(c) ? c - (0x61 - 0x41) : c; \ + SPROUT_CONSTEXPR CHAR_TYPE SPROUT_PP_CAT(to, SPROUT_PP_CAT(PREFIX, upper))(CHAR_TYPE c) { \ + return sprout::ascii::detail::get_value(c) & sprout::ascii::detail::upper ? c - (0x61 - 0x41) : c; \ } // @@ -237,12 +239,10 @@ namespace sprout { // tolower // toupper // - SPROUT_CTYPE_DEFINE_ASCII(char); - SPROUT_CTYPE_DEFINE_ASCII(wchar_t); - SPROUT_CTYPE_DEFINE_ASCII(char16_t); - SPROUT_CTYPE_DEFINE_ASCII(char32_t); - -#undef SPROUT_CTYPE_DEFINE_ASCII + SPROUT_CTYPE_ASCII_DECL(char, SPROUT_PP_EMPTY()); + SPROUT_CTYPE_ASCII_DECL(wchar_t, SPROUT_PP_EMPTY()); + SPROUT_CTYPE_ASCII_DECL(char16_t, SPROUT_PP_EMPTY()); + SPROUT_CTYPE_ASCII_DECL(char32_t, SPROUT_PP_EMPTY()); } // namespace ascii using sprout::ascii::isalnum; diff --git a/sprout/ctype/wascii.hpp b/sprout/ctype/wascii.hpp new file mode 100644 index 00000000..df0f1ca7 --- /dev/null +++ b/sprout/ctype/wascii.hpp @@ -0,0 +1,44 @@ +#ifndef SPROUT_CTYPE_WASCII_HPP +#define SPROUT_CTYPE_WASCII_HPP + +#include +#include + +namespace sprout { + namespace ascii { + // + // iswalnum + // iswalpha + // iswblank + // iswcntrl + // iswdigit + // iswgraph + // iswlower + // iswprint + // iswpunct + // iswspace + // iswupper + // iswxdigit + // towlower + // towupper + // + SPROUT_CTYPE_ASCII_DECL(wchar_t, w); + } // namespace ascii + + using sprout::ascii::iswalnum; + using sprout::ascii::iswalpha; + using sprout::ascii::iswblank; + using sprout::ascii::iswcntrl; + using sprout::ascii::iswdigit; + using sprout::ascii::iswgraph; + using sprout::ascii::iswlower; + using sprout::ascii::iswprint; + using sprout::ascii::iswpunct; + using sprout::ascii::iswspace; + using sprout::ascii::iswupper; + using sprout::ascii::iswxdigit; + using sprout::ascii::towlower; + using sprout::ascii::towupper; +} // namespace sprout + +#endif // #ifndef SPROUT_CTYPE_WASCII_HPP diff --git a/sprout/cwchar.hpp b/sprout/cwchar.hpp new file mode 100644 index 00000000..9edcadb9 --- /dev/null +++ b/sprout/cwchar.hpp @@ -0,0 +1,18 @@ +#ifndef SPROUT_CWCHER_HPP +#define SPROUT_CWCHER_HPP + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#endif // #ifndef SPROUT_CWCHER_HPP diff --git a/sprout/cwchar/wcschr.hpp b/sprout/cwchar/wcschr.hpp new file mode 100644 index 00000000..9d5192c9 --- /dev/null +++ b/sprout/cwchar/wcschr.hpp @@ -0,0 +1,22 @@ +#ifndef SPROUT_CWCHAR_WCSCHR_HPP +#define SPROUT_CWCHAR_WCSCHR_HPP + +#include +#include + +namespace sprout { + // Copyright (C) 2011 RiSK (sscrisk) + + inline SPROUT_CONSTEXPR wchar_t const* wcschr(wchar_t const* s, int c) { + return *s == static_cast(c) ? s + : !*s ? nullptr + : sprout::wcschr(s + 1, c) + ; + } + + inline SPROUT_CONSTEXPR wchar_t* wcschr(wchar_t* s, int c) { + return const_cast(sprout::wcschr(const_cast(s), c)); + } +} // namespace sprout + +#endif // #ifndef SPROUT_CWCHAR_WCSCHR_HPP diff --git a/sprout/cwchar/wcscmp.hpp b/sprout/cwchar/wcscmp.hpp new file mode 100644 index 00000000..67050b6b --- /dev/null +++ b/sprout/cwchar/wcscmp.hpp @@ -0,0 +1,19 @@ +#ifndef SPROUT_CWCHAR_WCSCMP_HPP +#define SPROUT_CWCHAR_WCSCMP_HPP + +#include + +namespace sprout { + // Copyright (C) 2011 RiSK (sscrisk) + + inline SPROUT_CONSTEXPR int wcscmp(wchar_t const* s1, wchar_t const* s2) { + return !*s1 && !*s2 ? 0 + : !*s1 ? -1 + : !*s2 ? 1 + : *s1 == *s2 ? sprout::wcscmp(s1 + 1, s2 + 1) + : static_cast(*s1) - static_cast(*s2) + ; + } +} // namespace sprout + +#endif // #ifndef SPROUT_CWCHAR_WCSCMP_HPP diff --git a/sprout/cwchar/wcscoll.hpp b/sprout/cwchar/wcscoll.hpp new file mode 100644 index 00000000..7cb45bb5 --- /dev/null +++ b/sprout/cwchar/wcscoll.hpp @@ -0,0 +1,15 @@ +#ifndef SPROUT_CWCHAR_WCSCOLL_HPP +#define SPROUT_CWCHAR_WCSCOLL_HPP + +#include +#include + +namespace sprout { + // Copyright (C) 2011 RiSK (sscrisk) + + inline SPROUT_CONSTEXPR int wcscoll(wchar_t const* s1, wchar_t const* s2) { + return sprout::wcscmp(s1, s2); + } +} // namespace sprout + +#endif // #ifndef SPROUT_CWCHAR_WCSCOLL_HPP diff --git a/sprout/cwchar/wcscspn.hpp b/sprout/cwchar/wcscspn.hpp new file mode 100644 index 00000000..fe5ab9e9 --- /dev/null +++ b/sprout/cwchar/wcscspn.hpp @@ -0,0 +1,24 @@ +#ifndef SPROUT_CWCHAR_WCSCSPN_HPP +#define SPROUT_CWCHAR_WCSCSPN_HPP + +#include +#include +#include + +namespace sprout { + // Copyright (C) 2011 RiSK (sscrisk) + + namespace detail { + inline SPROUT_CONSTEXPR std::size_t wcscspn_impl(wchar_t const* s1, wchar_t const* s2, std::size_t n) { + return !*s1 || sprout::wcschr(s2, *s1) ? n + : sprout::detail::wcscspn_impl(s1 + 1, s2, n + 1) + ; + } + } // amespace detail + + inline SPROUT_CONSTEXPR std::size_t wcscspn(wchar_t const* s1, wchar_t const* s2) { + return sprout::detail::wcscspn_impl(s1, s2, 0); + } +} // namespace sprout + +#endif // #ifndef SPROUT_CWCHAR_WCSCSPN_HPP diff --git a/sprout/cwchar/wcslen.hpp b/sprout/cwchar/wcslen.hpp new file mode 100644 index 00000000..e44cf245 --- /dev/null +++ b/sprout/cwchar/wcslen.hpp @@ -0,0 +1,23 @@ +#ifndef SPROUT_CWCHAR_WCSLEN_HPP +#define SPROUT_CWCHAR_WCSLEN_HPP + +#include +#include + +namespace sprout { + // Copyright (C) 2011 RiSK (sscrisk) + + namespace detail { + inline SPROUT_CONSTEXPR std::size_t wcslen_impl(wchar_t const* s, std::size_t n) { + return !*s ? n : + sprout::detail::wcslen_impl(s + 1, n + 1) + ; + } + } // namespace detail + + inline SPROUT_CONSTEXPR std::size_t wcslen(wchar_t const* s) { + return sprout::detail::wcslen_impl(s, 0); + } +} // namespace sprout + +#endif // #ifndef SPROUT_CWCHAR_WCSLEN_HPP diff --git a/sprout/cwchar/wcsncmp.hpp b/sprout/cwchar/wcsncmp.hpp new file mode 100644 index 00000000..403c99c7 --- /dev/null +++ b/sprout/cwchar/wcsncmp.hpp @@ -0,0 +1,20 @@ +#ifndef SPROUT_CWCHAR_WCSNCMP_HPP +#define SPROUT_CWCHAR_WCSNCMP_HPP + +#include +#include + +namespace sprout { + // Copyright (C) 2011 RiSK (sscrisk) + + inline SPROUT_CONSTEXPR int wcsncmp(wchar_t const* s1, wchar_t const* s2, std::size_t n) { + return !n || (!*s1 && !*s2) ? 0 + : !*s1 ? -1 + : !*s2 ? 1 + : *s1 == *s2 ? sprout::wcsncmp(s1 + 1, s2 + 1, n - 1) + : static_cast(*s1) - static_cast(*s2) + ; + } +} // namespace sprout + +#endif // #ifndef SPROUT_CWCHAR_WCSNCMP_HPP diff --git a/sprout/cwchar/wcspbrk.hpp b/sprout/cwchar/wcspbrk.hpp new file mode 100644 index 00000000..f082b398 --- /dev/null +++ b/sprout/cwchar/wcspbrk.hpp @@ -0,0 +1,23 @@ +#ifndef SPROUT_CWCHAR_WCSPBRK_HPP +#define SPROUT_CWCHAR_WCSPBRK_HPP + +#include +#include +#include + +namespace sprout { + // Copyright (C) 2011 RiSK (sscrisk) + + inline SPROUT_CONSTEXPR wchar_t const* wcspbrk(wchar_t const* s1, wchar_t const* s2) { + return !*s1 ? nullptr + : sprout::wcschr(s2, *s1) ? s1 + : sprout::wcspbrk(s1 + 1, s2) + ; + } + + inline SPROUT_CONSTEXPR wchar_t* wcspbrk(wchar_t* s1, wchar_t const* s2) { + return const_cast(sprout::wcspbrk(const_cast(s1), s2)); + } +} // namespace sprout + +#endif // #ifndef SPROUT_CWCHAR_WCSPBRK_HPP diff --git a/sprout/cwchar/wcsrchr.hpp b/sprout/cwchar/wcsrchr.hpp new file mode 100644 index 00000000..ab069e95 --- /dev/null +++ b/sprout/cwchar/wcsrchr.hpp @@ -0,0 +1,22 @@ +#ifndef SPROUT_CWCHAR_WCSRCHR_HPP +#define SPROUT_CWCHAR_WCSRCHR_HPP + +#include +#include + +namespace sprout { + // Copyright (C) 2011 RiSK (sscrisk) + + inline SPROUT_CONSTEXPR wchar_t const* wcsrchr(wchar_t const* s, int c) { + return *s == static_cast(c) && (!*s || !sprout::wcsrchr(s + 1, c))? s + : !*s ? nullptr + : sprout::wcsrchr(s + 1, c) + ; + } + + inline SPROUT_CONSTEXPR wchar_t* wcsrchr(wchar_t* s, int c) { + return const_cast(sprout::wcsrchr(const_cast(s), c)); + } +} // namespace sprout + +#endif // #ifndef SPROUT_CWCHAR_WCSRCHR_HPP diff --git a/sprout/cwchar/wcsspn.hpp b/sprout/cwchar/wcsspn.hpp new file mode 100644 index 00000000..fbab327d --- /dev/null +++ b/sprout/cwchar/wcsspn.hpp @@ -0,0 +1,24 @@ +#ifndef SPROUT_CWCHAR_WCSSPN_HPP +#define SPROUT_CWCHAR_XXX_HPP + +#include +#include +#include + +namespace sprout { + // Copyright (C) 2011 RiSK (sscrisk) + + namespace detail { + inline SPROUT_CONSTEXPR std::size_t wcsspn_impl(wchar_t const* s1, wchar_t const* s2, std::size_t n) { + return !*s1 || !sprout::wcschr(s2, *s1) ? n + : sprout::detail::wcsspn_impl(s1 + 1, s2, n + 1) + ; + } + } // namespace detail + + inline SPROUT_CONSTEXPR std::size_t wcsspn(wchar_t const* s1, wchar_t const* s2) { + return sprout::detail::wcsspn_impl(s1, s2, 0); + } +} // namespace sprout + +#endif // #ifndef SPROUT_CWCHAR_XXX_HPP diff --git a/sprout/cwchar/wcsstr.hpp b/sprout/cwchar/wcsstr.hpp new file mode 100644 index 00000000..6f55241b --- /dev/null +++ b/sprout/cwchar/wcsstr.hpp @@ -0,0 +1,22 @@ +#ifndef SPROUT_CWCHAR_WCSSTR_HPP +#define SPROUT_CWCHAR_WCSSTR_HPP + +#include + +namespace sprout { + // Copyright (C) 2011 RiSK (sscrisk) + + inline SPROUT_CONSTEXPR wchar_t const* wcsstr(wchar_t const* s1, wchar_t const* s2) { + return !*s2 ? s1 + : !*s1 ? nullptr + : *s1 == *s2 && sprout::wcsstr(s1 + 1, s2 + 1) ? s1 + : sprout::wcsstr(s1 + 1, s2) + ; + } + + inline SPROUT_CONSTEXPR wchar_t* wcsstr(wchar_t* s1, wchar_t const* s2) { + return const_cast(sprout::wcsstr(const_cast(s1), s2)); + } +} // namespace sprout + +#endif // #ifndef SPROUT_CWCHAR_WCSSTR_HPP diff --git a/sprout/cwchar/wmemchr.hpp b/sprout/cwchar/wmemchr.hpp new file mode 100644 index 00000000..85aad0ae --- /dev/null +++ b/sprout/cwchar/wmemchr.hpp @@ -0,0 +1,30 @@ +#ifndef SPROUT_CWCHAR_WMEMCHR_HPP +#define SPROUT_CWCHAR_WMEMCHR_HPP + +#include +#include + +namespace sprout { + // Copyright (C) 2011 RiSK (sscrisk) + + namespace detail { + inline SPROUT_CONSTEXPR wchar_t const* wmemchr_impl(wchar_t const* s, wchar_t c, std::size_t n) { + return !n ? 0 + : *s == c ? s + : sprout::detail::wmemchr_impl(s + 1, c, n - 1) + ; + } + } // namespace detail + + inline SPROUT_CONSTEXPR wchar_t const* wmemchr(wchar_t const* s, wchar_t c, size_t n) { + return sprout::detail::wmemchr_impl(s, c, n); + } + + inline SPROUT_CONSTEXPR wchar_t* wmemchr(wchar_t* s, wchar_t c, size_t n) { + return const_cast( + sprout::detail::wmemchr_impl(s, c, n) + ); + } +} // namespace sprout + +#endif // #ifndef SPROUT_CWCHAR_WMEMCHR_HPP diff --git a/sprout/cwchar/wmemcmp.hpp b/sprout/cwchar/wmemcmp.hpp new file mode 100644 index 00000000..b34679b7 --- /dev/null +++ b/sprout/cwchar/wmemcmp.hpp @@ -0,0 +1,28 @@ +#ifndef SPROUT_CWCHAR_WMEMCMP_HPP +#define SPROUT_CWCHAR_WMEMCMP_HPP + +#include +#include + +namespace sprout { + // Copyright (C) 2011 RiSK (sscrisk) + + namespace detail { + inline SPROUT_CONSTEXPR int wmemcmp_impl(wchar_t const* s1, wchar_t const* s2, std::size_t n) { + return !n ? 0 + : *s1 == *s2 ? sprout::detail::wmemcmp_impl(s1 + 1, s2 + 1, n - 1) + : *s1 - *s2 + ; + } + } // namespace detail + + inline SPROUT_CONSTEXPR int wmemcmp(wchar_t const* s1, wchar_t const* s2, std::size_t n) { + return sprout::detail::wmemcmp_impl( + s1, + s2, + n + ); + } +} // namespace sprout + +#endif // #ifndef SPROUT_CWCHAR_WMEMCMP_HPP diff --git a/sprout/cwctype.hpp b/sprout/cwctype.hpp new file mode 100644 index 00000000..add8c60a --- /dev/null +++ b/sprout/cwctype.hpp @@ -0,0 +1,7 @@ +#ifndef SPROUT_CCTYPE_HPP +#define SPROUT_CCTYPE_HPP + +#include +#include + +#endif // #ifndef SPROUT_CCTYPE_HPP diff --git a/sprout/detail/char_conversion.hpp b/sprout/detail/char_conversion.hpp index de4b64d6..b831139c 100644 --- a/sprout/detail/char_conversion.hpp +++ b/sprout/detail/char_conversion.hpp @@ -4,6 +4,7 @@ #include #include #include +#include namespace sprout { namespace detail { @@ -23,15 +24,15 @@ namespace sprout { template inline SPROUT_CONSTEXPR IntType char_to_int(Elem c, std::size_t base){ - return c >= static_cast('0') && c <= static_cast('9') ? c - static_cast('0') - : c >= static_cast('a') && c <= static_cast('a' + (base - 11)) ? c - static_cast('a') + 10 - : c >= static_cast('A') && c <= static_cast('A' + (base - 11)) ? c - static_cast('A') + 10 + return sprout::ascii::isdigit(c) && static_cast(c - static_cast('0')) < base ? c - static_cast('0') + : sprout::ascii::islower(c) && static_cast(c - static_cast('a') + 10) < base ? c - static_cast('a') + 10 + : sprout::ascii::isupper(c) && static_cast(c - static_cast('A') + 10) < base ? c - static_cast('A') + 10 : static_cast(-1) ; } template inline SPROUT_CONSTEXPR IntType char_to_int(Elem c){ - return c >= static_cast('0') && c <= static_cast('9') ? c - static_cast('0') + return sprout::ascii::isdigit(c) ? c - static_cast('0') : static_cast(-1) ; } diff --git a/sprout/preprocessor.hpp b/sprout/preprocessor.hpp index 4b64a3cc..355738bc 100644 --- a/sprout/preprocessor.hpp +++ b/sprout/preprocessor.hpp @@ -6,5 +6,6 @@ #include #include #include +#include #endif // #ifndef SPROUT_PREPROCESSOR_HPP diff --git a/sprout/preprocessor/cat.hpp b/sprout/preprocessor/cat.hpp index 8835d23c..5407673c 100644 --- a/sprout/preprocessor/cat.hpp +++ b/sprout/preprocessor/cat.hpp @@ -3,12 +3,11 @@ #include -#define SPROUT_PP_CAT_I(a, b) a ## b - // // SPROUT_PP_CAT // #define SPROUT_PP_CAT(a, b) SPROUT_PP_CAT_I(a, b) +#define SPROUT_PP_CAT_I(a, b) a ## b #endif // #ifndef SPROUT_PREPROCESSOR_CAT_HPP diff --git a/sprout/preprocessor/empty.hpp b/sprout/preprocessor/empty.hpp new file mode 100644 index 00000000..5a2b87e1 --- /dev/null +++ b/sprout/preprocessor/empty.hpp @@ -0,0 +1,12 @@ +#ifndef SPROUT_PREPROCESSOR_EMPTY_HPP +#define SPROUT_PREPROCESSOR_EMPTY_HPP + +#include + +// +// SPROUT_PP_EMPTY +// +#define SPROUT_PP_EMPTY() + +#endif // #ifndef SPROUT_PREPROCESSOR_EMPTY_HPP +