add cwchar.hpp

rename decimal_to_int -> ascii_to_int
This commit is contained in:
bolero-MURAKAMI 2012-04-15 10:31:49 +09:00
parent 50fd5f33bf
commit 28f7c510a5
34 changed files with 576 additions and 92 deletions

View file

@ -2,6 +2,6 @@
#define SPROUT_CCTYPE_HPP #define SPROUT_CCTYPE_HPP
#include <sprout/config.hpp> #include <sprout/config.hpp>
#include <sprout/ctype.hpp> #include <sprout/ctype/ascii.hpp>
#endif // #ifndef SPROUT_CCTYPE_HPP #endif // #ifndef SPROUT_CCTYPE_HPP

View file

@ -0,0 +1,60 @@
#ifndef SPROUT_CSTDLIB_DECIMAL_TO_INT_HPP
#define SPROUT_CSTDLIB_DECIMAL_TO_INT_HPP
#include <iterator>
#include <limits>
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/iterator/operation.hpp>
#include <sprout/ctype/ascii.hpp>
#include <sprout/utility/enabler_if.hpp>
namespace sprout {
namespace detail {
// Copyright (c) 2011 osyo-manga : http://d.hatena.ne.jp/osyo-manga/
template<typename IntType, typename CStrIterator>
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<IntType>::max() - (*str - static_cast<typename std::iterator_traits<CStrIterator>::value_type>('0')) - (negative ? 1 : 0)) / 10
? (negative ? std::numeric_limits<IntType>::min() : std::numeric_limits<IntType>::max())
: sprout::detail::ascii_to_int_impl<IntType>(
sprout::next(str),
val * 10 + (*str - static_cast<typename std::iterator_traits<CStrIterator>::value_type>('0')),
negative
)
;
}
template<typename IntType, typename CStrIterator, typename sprout::enabler_if<std::is_unsigned<IntType>::value>::type = sprout::enabler>
inline SPROUT_CONSTEXPR IntType ascii_to_int(CStrIterator str) {
return sprout::ascii::isspace(*str)
? sprout::detail::ascii_to_int<IntType>(sprout::next(str))
: *str == static_cast<typename std::iterator_traits<CStrIterator>::value_type>('+')
? sprout::detail::ascii_to_int_impl<IntType>(sprout::next(str), IntType(), false)
: sprout::detail::ascii_to_int_impl<IntType>(str, IntType(), false)
;
}
template<typename IntType, typename CStrIterator, typename sprout::enabler_if<std::is_signed<IntType>::value>::type = sprout::enabler>
inline SPROUT_CONSTEXPR IntType ascii_to_int(CStrIterator str) {
return sprout::ascii::isspace(*str)
? sprout::detail::ascii_to_int<IntType>(sprout::next(str))
: *str == static_cast<typename std::iterator_traits<CStrIterator>::value_type>('-')
? sprout::detail::ascii_to_int_impl<IntType>(sprout::next(str), IntType(), true)
: *str == static_cast<typename std::iterator_traits<CStrIterator>::value_type>('+')
? sprout::detail::ascii_to_int_impl<IntType>(sprout::next(str), IntType(), false)
: sprout::detail::ascii_to_int_impl<IntType>(str, IntType(), false)
;
}
} // namespace detail
//
// ascii_to_int
//
template<typename IntType, typename Char, typename sprout::enabler_if<std::is_integral<IntType>::value>::type = sprout::enabler>
inline SPROUT_CONSTEXPR IntType ascii_to_int(Char const* str) {
return sprout::detail::ascii_to_int<IntType>(str);
}
} // namespace sprout
#endif // #ifndef SPROUT_CSTDLIB_DECIMAL_TO_INT_HPP

View file

@ -2,18 +2,18 @@
#define SPROUT_CSTDLIB_ATOI_HPP #define SPROUT_CSTDLIB_ATOI_HPP
#include <sprout/config.hpp> #include <sprout/config.hpp>
#include <sprout/cstdlib/decimal_to_int.hpp> #include <sprout/cstdlib/ascii_to_int.hpp>
namespace sprout { namespace sprout {
// //
// atoi // atoi
// //
inline SPROUT_CONSTEXPR int atoi(char const* str) { inline SPROUT_CONSTEXPR int atoi(char const* str) {
return sprout::decimal_to_int<int>(str); return sprout::ascii_to_int<int>(str);
} }
template<typename Char> template<typename Char>
inline SPROUT_CONSTEXPR int atoi(Char const* str) { inline SPROUT_CONSTEXPR int atoi(Char const* str) {
return sprout::decimal_to_int<int>(str); return sprout::ascii_to_int<int>(str);
} }
} // namespace sprout } // namespace sprout

View file

@ -2,18 +2,18 @@
#define SPROUT_CSTDLIB_ATOL_HPP #define SPROUT_CSTDLIB_ATOL_HPP
#include <sprout/config.hpp> #include <sprout/config.hpp>
#include <sprout/cstdlib/decimal_to_int.hpp> #include <sprout/cstdlib/ascii_to_int.hpp>
namespace sprout { namespace sprout {
// //
// atol // atol
// //
inline SPROUT_CONSTEXPR long atol(char const* str) { inline SPROUT_CONSTEXPR long atol(char const* str) {
return sprout::decimal_to_int<long>(str); return sprout::ascii_to_int<long>(str);
} }
template<typename Char> template<typename Char>
inline SPROUT_CONSTEXPR int atol(Char const* str) { inline SPROUT_CONSTEXPR long atol(Char const* str) {
return sprout::decimal_to_int<int>(str); return sprout::ascii_to_int<long>(str);
} }
} // namespace sprout } // namespace sprout

20
sprout/cstdlib/atoll.hpp Normal file
View file

@ -0,0 +1,20 @@
#ifndef SPROUT_CSTDLIB_ATOLL_HPP
#define SPROUT_CSTDLIB_ATOLL_HPP
#include <sprout/config.hpp>
#include <sprout/cstdlib/ascii_to_int.hpp>
namespace sprout {
//
// atoll
//
inline SPROUT_CONSTEXPR long long atoll(char const* str) {
return sprout::ascii_to_int<long long>(str);
}
template<typename Char>
inline SPROUT_CONSTEXPR long long atoll(Char const* str) {
return sprout::ascii_to_int<long long>(str);
}
} // namespace sprout
#endif // #ifndef SPROUT_CSTDLIB_ATOLL_HPP

View file

@ -2,10 +2,14 @@
#define SPROUT_CSTDLIB_CONVERSION_HPP #define SPROUT_CSTDLIB_CONVERSION_HPP
#include <sprout/config.hpp> #include <sprout/config.hpp>
#include <sprout/cstdlib/decimal_to_int.hpp> #include <sprout/cstdlib/ascii_to_int.hpp>
#include <sprout/cstdlib/str_to_int.hpp> #include <sprout/cstdlib/str_to_int.hpp>
#include <sprout/cstdlib/atoi.hpp> #include <sprout/cstdlib/atoi.hpp>
#include <sprout/cstdlib/atol.hpp> #include <sprout/cstdlib/atol.hpp>
#include <sprout/cstdlib/atoll.hpp>
#include <sprout/cstdlib/strtol.hpp> #include <sprout/cstdlib/strtol.hpp>
#include <sprout/cstdlib/strtoul.hpp>
#include <sprout/cstdlib/strtoll.hpp>
#include <sprout/cstdlib/strtoull.hpp>
#endif // #ifndef SPROUT_CSTDLIB_CONVERSION_HPP #endif // #ifndef SPROUT_CSTDLIB_CONVERSION_HPP

View file

@ -1,51 +0,0 @@
#ifndef SPROUT_CSTDLIB_DECIMAL_TO_INT_HPP
#define SPROUT_CSTDLIB_DECIMAL_TO_INT_HPP
#include <iterator>
#include <limits>
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/iterator/operation.hpp>
#include <sprout/ctype/ascii.hpp>
#include <sprout/utility/enabler_if.hpp>
namespace sprout {
namespace detail {
// Copyright (c) 2011 osyo-manga : http://d.hatena.ne.jp/osyo-manga/
template<typename IntType, typename CStrIterator>
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<IntType>::max() - (*str - static_cast<typename std::iterator_traits<CStrIterator>::value_type>('0')) - (negative ? 1 : 0)) / 10
? (negative ? std::numeric_limits<IntType>::min() : std::numeric_limits<IntType>::max())
: sprout::detail::decimal_to_int_impl<IntType>(
sprout::next(str),
val * 10 + (*str - static_cast<typename std::iterator_traits<CStrIterator>::value_type>('0')),
negative
)
;
}
template<typename IntType, typename CStrIterator>
inline SPROUT_CONSTEXPR IntType decimal_to_int(CStrIterator str) {
return sprout::ascii::isspace(*str)
? sprout::detail::decimal_to_int<IntType>(sprout::next(str))
: *str == static_cast<typename std::iterator_traits<CStrIterator>::value_type>('-')
? sprout::detail::decimal_to_int_impl<IntType>(sprout::next(str), IntType(), true)
: *str == static_cast<typename std::iterator_traits<CStrIterator>::value_type>('+')
? sprout::detail::decimal_to_int_impl<IntType>(sprout::next(str), IntType(), false)
: sprout::detail::decimal_to_int_impl<IntType>(str, IntType(), false)
;
}
} // namespace detail
//
// decimal_to_int
//
template<typename IntType, typename Char, typename sprout::enabler_if<std::is_integral<IntType>::value>::type = sprout::enabler>
inline SPROUT_CONSTEXPR IntType decimal_to_int(Char const* str) {
return sprout::detail::decimal_to_int<IntType>(str);
}
} // namespace sprout
#endif // #ifndef SPROUT_CSTDLIB_DECIMAL_TO_INT_HPP

View file

@ -56,7 +56,16 @@ namespace sprout {
) )
; ;
} }
template<typename IntType, typename CStrIterator> template<typename IntType, typename CStrIterator, typename sprout::enabler_if<std::is_unsigned<IntType>::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<IntType>(sprout::next(str), base)
: *str == static_cast<typename std::iterator_traits<CStrIterator>::value_type>('+')
? sprout::detail::str_to_int_impl<IntType>(sprout::next(str), base, false)
: sprout::detail::str_to_int_impl<IntType>(str, base, false)
;
}
template<typename IntType, typename CStrIterator, typename sprout::enabler_if<std::is_signed<IntType>::value>::type = sprout::enabler>
inline SPROUT_CONSTEXPR IntType str_to_int(CStrIterator str, int base) { inline SPROUT_CONSTEXPR IntType str_to_int(CStrIterator str, int base) {
return sprout::ascii::isspace(*str) return sprout::ascii::isspace(*str)
? sprout::detail::str_to_int<IntType>(sprout::next(str), base) ? sprout::detail::str_to_int<IntType>(sprout::next(str), base)

View file

@ -0,0 +1,29 @@
#ifndef SPROUT_CSTDLIB_STRTOLL_HPP
#define SPROUT_CSTDLIB_STRTOLL_HPP
#include <cstddef>
#include <sprout/config.hpp>
#include <sprout/cstdlib/str_to_int.hpp>
namespace sprout {
//
// strtol
//
inline SPROUT_CONSTEXPR long long strtoll(char const* str, char** endptr, int base = 10){
return sprout::str_to_int<long long>(str, endptr, base);
}
template<typename Char>
inline SPROUT_CONSTEXPR long long strtoll(Char const* str, Char** endptr, int base = 10){
return sprout::str_to_int<long long>(str, endptr, base);
}
template<typename Char>
inline SPROUT_CONSTEXPR long long strtoll(Char const* str, std::nullptr_t endptr, int base = 10){
return sprout::str_to_int<long long>(str, base);
}
template<typename Char>
inline SPROUT_CONSTEXPR long long strtoll(Char const* str, int base = 10){
return sprout::str_to_int<long long>(str, base);
}
} // namespace sprout
#endif // #ifndef SPROUT_CSTDLIB_STRTOLL_HPP

View file

@ -0,0 +1,29 @@
#ifndef SPROUT_CSTDLIB_STRTOUL_HPP
#define SPROUT_CSTDLIB_STRTOUL_HPP
#include <cstddef>
#include <sprout/config.hpp>
#include <sprout/cstdlib/str_to_int.hpp>
namespace sprout {
//
// strtoul
//
inline SPROUT_CONSTEXPR unsigned long strtoul(char const* str, char** endptr, int base = 10){
return sprout::str_to_int<unsigned long>(str, endptr, base);
}
template<typename Char>
inline SPROUT_CONSTEXPR unsigned long strtoul(Char const* str, Char** endptr, int base = 10){
return sprout::str_to_int<unsigned long>(str, endptr, base);
}
template<typename Char>
inline SPROUT_CONSTEXPR unsigned long strtoul(Char const* str, std::nullptr_t endptr, int base = 10){
return sprout::str_to_int<unsigned long>(str, base);
}
template<typename Char>
inline SPROUT_CONSTEXPR unsigned long strtoul(Char const* str, int base = 10){
return sprout::str_to_int<unsigned long>(str, base);
}
} // namespace sprout
#endif // #ifndef SPROUT_CSTDLIB_STRTOUL_HPP

View file

@ -0,0 +1,29 @@
#ifndef SPROUT_CSTDLIB_STRTTOULL_HPP
#define SPROUT_CSTDLIB_STRTTOULL_HPP
#include <cstddef>
#include <sprout/config.hpp>
#include <sprout/cstdlib/str_to_int.hpp>
namespace sprout {
//
// strtoul
//
inline SPROUT_CONSTEXPR unsigned long long strtoull(char const* str, char** endptr, int base = 10){
return sprout::str_to_int<unsigned long long>(str, endptr, base);
}
template<typename Char>
inline SPROUT_CONSTEXPR unsigned long long strtoull(Char const* str, Char** endptr, int base = 10){
return sprout::str_to_int<unsigned long long>(str, endptr, base);
}
template<typename Char>
inline SPROUT_CONSTEXPR unsigned long long strtoull(Char const* str, std::nullptr_t endptr, int base = 10){
return sprout::str_to_int<unsigned long long>(str, base);
}
template<typename Char>
inline SPROUT_CONSTEXPR unsigned long long strtoull(Char const* str, int base = 10){
return sprout::str_to_int<unsigned long long>(str, base);
}
} // namespace sprout
#endif // #ifndef SPROUT_CSTDLIB_STRTTOULL_HPP

View file

@ -8,7 +8,7 @@ namespace sprout {
// Copyright (C) 2011 RiSK (sscrisk) // Copyright (C) 2011 RiSK (sscrisk)
namespace detail { 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 return !n ? 0
: *s == c ? s : *s == c ? s
: sprout::detail::memchr_impl(s + 1, c, n - 1) : sprout::detail::memchr_impl(s + 1, c, n - 1)

View file

@ -17,7 +17,7 @@ namespace sprout {
} // namespace detail } // namespace detail
// 7.21.4.1 memcmp ŠÖ<C5A0> // 7.21.4.1 memcmp ŠÖ<C5A0>
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( return sprout::detail::memcmp_impl(
static_cast<unsigned char const*>(s1), static_cast<unsigned char const*>(s1),
static_cast<unsigned char const*>(s2), static_cast<unsigned char const*>(s2),

View file

@ -3,5 +3,6 @@
#include <sprout/config.hpp> #include <sprout/config.hpp>
#include <sprout/ctype/ascii.hpp> #include <sprout/ctype/ascii.hpp>
#include <sprout/ctype/wascii.hpp>
#endif // #ifndef SPROUT_CTYPE_HPP #endif // #ifndef SPROUT_CTYPE_HPP

View file

@ -3,6 +3,8 @@
#include <cstddef> #include <cstddef>
#include <sprout/config.hpp> #include <sprout/config.hpp>
#include <sprout/preprocessor/cat.hpp>
#include <sprout/preprocessor/empty.hpp>
namespace sprout { namespace sprout {
namespace ascii { namespace ascii {
@ -177,48 +179,48 @@ namespace sprout {
} }
} // namespace detail } // namespace detail
#define SPROUT_CTYPE_DEFINE_ASCII(CHAR_TYPE) \ #define SPROUT_CTYPE_ASCII_DECL(CHAR_TYPE, PREFIX) \
SPROUT_CONSTEXPR bool isalnum(CHAR_TYPE c) { \ 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); \ 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; \ 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; \ 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; \ 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; \ 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; \ 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; \ 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; \ 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; \ 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; \ 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; \ 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; \ return sprout::ascii::detail::get_value(c) & sprout::ascii::detail::xdigit; \
} \ } \
SPROUT_CONSTEXPR CHAR_TYPE tolower(CHAR_TYPE c) { \ SPROUT_CONSTEXPR CHAR_TYPE SPROUT_PP_CAT(to, SPROUT_PP_CAT(PREFIX, lower))(CHAR_TYPE c) { \
return sprout::ascii::isupper(c) ? c + (0x61 - 0x41) : c; \ return sprout::ascii::detail::get_value(c) & sprout::ascii::detail::lower ? c + (0x61 - 0x41) : c; \
} \ } \
SPROUT_CONSTEXPR CHAR_TYPE toupper(CHAR_TYPE c) { \ SPROUT_CONSTEXPR CHAR_TYPE SPROUT_PP_CAT(to, SPROUT_PP_CAT(PREFIX, upper))(CHAR_TYPE c) { \
return sprout::ascii::islower(c) ? c - (0x61 - 0x41) : c; \ return sprout::ascii::detail::get_value(c) & sprout::ascii::detail::upper ? c - (0x61 - 0x41) : c; \
} }
// //
@ -237,12 +239,10 @@ namespace sprout {
// tolower // tolower
// toupper // toupper
// //
SPROUT_CTYPE_DEFINE_ASCII(char); SPROUT_CTYPE_ASCII_DECL(char, SPROUT_PP_EMPTY());
SPROUT_CTYPE_DEFINE_ASCII(wchar_t); SPROUT_CTYPE_ASCII_DECL(wchar_t, SPROUT_PP_EMPTY());
SPROUT_CTYPE_DEFINE_ASCII(char16_t); SPROUT_CTYPE_ASCII_DECL(char16_t, SPROUT_PP_EMPTY());
SPROUT_CTYPE_DEFINE_ASCII(char32_t); SPROUT_CTYPE_ASCII_DECL(char32_t, SPROUT_PP_EMPTY());
#undef SPROUT_CTYPE_DEFINE_ASCII
} // namespace ascii } // namespace ascii
using sprout::ascii::isalnum; using sprout::ascii::isalnum;

44
sprout/ctype/wascii.hpp Normal file
View file

@ -0,0 +1,44 @@
#ifndef SPROUT_CTYPE_WASCII_HPP
#define SPROUT_CTYPE_WASCII_HPP
#include <sprout/config.hpp>
#include <sprout/ctype/ascii.hpp>
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

18
sprout/cwchar.hpp Normal file
View file

@ -0,0 +1,18 @@
#ifndef SPROUT_CWCHER_HPP
#define SPROUT_CWCHER_HPP
#include <sprout/config.hpp>
#include <sprout/cwchar/wmemcmp.hpp>
#include <sprout/cwchar/wcscmp.hpp>
#include <sprout/cwchar/wcscoll.hpp>
#include <sprout/cwchar/wcsncmp.hpp>
#include <sprout/cwchar/wmemchr.hpp>
#include <sprout/cwchar/wcschr.hpp>
#include <sprout/cwchar/wcscspn.hpp>
#include <sprout/cwchar/wcspbrk.hpp>
#include <sprout/cwchar/wcsrchr.hpp>
#include <sprout/cwchar/wcsspn.hpp>
#include <sprout/cwchar/wcsstr.hpp>
#include <sprout/cwchar/wcslen.hpp>
#endif // #ifndef SPROUT_CWCHER_HPP

22
sprout/cwchar/wcschr.hpp Normal file
View file

@ -0,0 +1,22 @@
#ifndef SPROUT_CWCHAR_WCSCHR_HPP
#define SPROUT_CWCHAR_WCSCHR_HPP
#include <cstddef>
#include <sprout/config.hpp>
namespace sprout {
// Copyright (C) 2011 RiSK (sscrisk)
inline SPROUT_CONSTEXPR wchar_t const* wcschr(wchar_t const* s, int c) {
return *s == static_cast<wchar_t>(c) ? s
: !*s ? nullptr
: sprout::wcschr(s + 1, c)
;
}
inline SPROUT_CONSTEXPR wchar_t* wcschr(wchar_t* s, int c) {
return const_cast<wchar_t*>(sprout::wcschr(const_cast<wchar_t const*>(s), c));
}
} // namespace sprout
#endif // #ifndef SPROUT_CWCHAR_WCSCHR_HPP

19
sprout/cwchar/wcscmp.hpp Normal file
View file

@ -0,0 +1,19 @@
#ifndef SPROUT_CWCHAR_WCSCMP_HPP
#define SPROUT_CWCHAR_WCSCMP_HPP
#include <sprout/config.hpp>
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<unsigned wchar_t>(*s1) - static_cast<unsigned wchar_t>(*s2)
;
}
} // namespace sprout
#endif // #ifndef SPROUT_CWCHAR_WCSCMP_HPP

15
sprout/cwchar/wcscoll.hpp Normal file
View file

@ -0,0 +1,15 @@
#ifndef SPROUT_CWCHAR_WCSCOLL_HPP
#define SPROUT_CWCHAR_WCSCOLL_HPP
#include <sprout/config.hpp>
#include <sprout/cstring/strcmp.hpp>
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

24
sprout/cwchar/wcscspn.hpp Normal file
View file

@ -0,0 +1,24 @@
#ifndef SPROUT_CWCHAR_WCSCSPN_HPP
#define SPROUT_CWCHAR_WCSCSPN_HPP
#include <cstddef>
#include <sprout/config.hpp>
#include <sprout/cstring/strchr.hpp>
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

23
sprout/cwchar/wcslen.hpp Normal file
View file

@ -0,0 +1,23 @@
#ifndef SPROUT_CWCHAR_WCSLEN_HPP
#define SPROUT_CWCHAR_WCSLEN_HPP
#include <cstddef>
#include <sprout/config.hpp>
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

20
sprout/cwchar/wcsncmp.hpp Normal file
View file

@ -0,0 +1,20 @@
#ifndef SPROUT_CWCHAR_WCSNCMP_HPP
#define SPROUT_CWCHAR_WCSNCMP_HPP
#include <cstddef>
#include <sprout/config.hpp>
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<unsigned wchar_t>(*s1) - static_cast<unsigned wchar_t>(*s2)
;
}
} // namespace sprout
#endif // #ifndef SPROUT_CWCHAR_WCSNCMP_HPP

23
sprout/cwchar/wcspbrk.hpp Normal file
View file

@ -0,0 +1,23 @@
#ifndef SPROUT_CWCHAR_WCSPBRK_HPP
#define SPROUT_CWCHAR_WCSPBRK_HPP
#include <cstddef>
#include <sprout/config.hpp>
#include <sprout/cstring/strchr.hpp>
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<wchar_t*>(sprout::wcspbrk(const_cast<wchar_t const*>(s1), s2));
}
} // namespace sprout
#endif // #ifndef SPROUT_CWCHAR_WCSPBRK_HPP

22
sprout/cwchar/wcsrchr.hpp Normal file
View file

@ -0,0 +1,22 @@
#ifndef SPROUT_CWCHAR_WCSRCHR_HPP
#define SPROUT_CWCHAR_WCSRCHR_HPP
#include <cstddef>
#include <sprout/config.hpp>
namespace sprout {
// Copyright (C) 2011 RiSK (sscrisk)
inline SPROUT_CONSTEXPR wchar_t const* wcsrchr(wchar_t const* s, int c) {
return *s == static_cast<wchar_t>(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<wchar_t*>(sprout::wcsrchr(const_cast<wchar_t const*>(s), c));
}
} // namespace sprout
#endif // #ifndef SPROUT_CWCHAR_WCSRCHR_HPP

24
sprout/cwchar/wcsspn.hpp Normal file
View file

@ -0,0 +1,24 @@
#ifndef SPROUT_CWCHAR_WCSSPN_HPP
#define SPROUT_CWCHAR_XXX_HPP
#include <cstddef>
#include <sprout/config.hpp>
#include <sprout/cstring/strchr.hpp>
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

22
sprout/cwchar/wcsstr.hpp Normal file
View file

@ -0,0 +1,22 @@
#ifndef SPROUT_CWCHAR_WCSSTR_HPP
#define SPROUT_CWCHAR_WCSSTR_HPP
#include <sprout/config.hpp>
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<wchar_t*>(sprout::wcsstr(const_cast<wchar_t const*>(s1), s2));
}
} // namespace sprout
#endif // #ifndef SPROUT_CWCHAR_WCSSTR_HPP

30
sprout/cwchar/wmemchr.hpp Normal file
View file

@ -0,0 +1,30 @@
#ifndef SPROUT_CWCHAR_WMEMCHR_HPP
#define SPROUT_CWCHAR_WMEMCHR_HPP
#include <cstddef>
#include <sprout/config.hpp>
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<wchar_t*>(
sprout::detail::wmemchr_impl(s, c, n)
);
}
} // namespace sprout
#endif // #ifndef SPROUT_CWCHAR_WMEMCHR_HPP

28
sprout/cwchar/wmemcmp.hpp Normal file
View file

@ -0,0 +1,28 @@
#ifndef SPROUT_CWCHAR_WMEMCMP_HPP
#define SPROUT_CWCHAR_WMEMCMP_HPP
#include <cstddef>
#include <sprout/config.hpp>
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

7
sprout/cwctype.hpp Normal file
View file

@ -0,0 +1,7 @@
#ifndef SPROUT_CCTYPE_HPP
#define SPROUT_CCTYPE_HPP
#include <sprout/config.hpp>
#include <sprout/ctype/wascii.hpp>
#endif // #ifndef SPROUT_CCTYPE_HPP

View file

@ -4,6 +4,7 @@
#include <cstddef> #include <cstddef>
#include <stdexcept> #include <stdexcept>
#include <sprout/config.hpp> #include <sprout/config.hpp>
#include <sprout/ctype/ascii.hpp>
namespace sprout { namespace sprout {
namespace detail { namespace detail {
@ -23,15 +24,15 @@ namespace sprout {
template<typename IntType, typename Elem> template<typename IntType, typename Elem>
inline SPROUT_CONSTEXPR IntType char_to_int(Elem c, std::size_t base){ inline SPROUT_CONSTEXPR IntType char_to_int(Elem c, std::size_t base){
return c >= static_cast<Elem>('0') && c <= static_cast<Elem>('9') ? c - static_cast<Elem>('0') return sprout::ascii::isdigit(c) && static_cast<std::size_t>(c - static_cast<Elem>('0')) < base ? c - static_cast<Elem>('0')
: c >= static_cast<Elem>('a') && c <= static_cast<Elem>('a' + (base - 11)) ? c - static_cast<Elem>('a') + 10 : sprout::ascii::islower(c) && static_cast<std::size_t>(c - static_cast<Elem>('a') + 10) < base ? c - static_cast<Elem>('a') + 10
: c >= static_cast<Elem>('A') && c <= static_cast<Elem>('A' + (base - 11)) ? c - static_cast<Elem>('A') + 10 : sprout::ascii::isupper(c) && static_cast<std::size_t>(c - static_cast<Elem>('A') + 10) < base ? c - static_cast<Elem>('A') + 10
: static_cast<IntType>(-1) : static_cast<IntType>(-1)
; ;
} }
template<typename IntType, typename Elem> template<typename IntType, typename Elem>
inline SPROUT_CONSTEXPR IntType char_to_int(Elem c){ inline SPROUT_CONSTEXPR IntType char_to_int(Elem c){
return c >= static_cast<Elem>('0') && c <= static_cast<Elem>('9') ? c - static_cast<Elem>('0') return sprout::ascii::isdigit(c) ? c - static_cast<Elem>('0')
: static_cast<IntType>(-1) : static_cast<IntType>(-1)
; ;
} }

View file

@ -6,5 +6,6 @@
#include <sprout/preprocessor/stringize_all.hpp> #include <sprout/preprocessor/stringize_all.hpp>
#include <sprout/preprocessor/str_all.hpp> #include <sprout/preprocessor/str_all.hpp>
#include <sprout/preprocessor/unique_string.hpp> #include <sprout/preprocessor/unique_string.hpp>
#include <sprout/preprocessor/empty.hpp>
#endif // #ifndef SPROUT_PREPROCESSOR_HPP #endif // #ifndef SPROUT_PREPROCESSOR_HPP

View file

@ -3,12 +3,11 @@
#include <sprout/config.hpp> #include <sprout/config.hpp>
#define SPROUT_PP_CAT_I(a, b) a ## b
// //
// SPROUT_PP_CAT // SPROUT_PP_CAT
// //
#define SPROUT_PP_CAT(a, b) SPROUT_PP_CAT_I(a, b) #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 #endif // #ifndef SPROUT_PREPROCESSOR_CAT_HPP

View file

@ -0,0 +1,12 @@
#ifndef SPROUT_PREPROCESSOR_EMPTY_HPP
#define SPROUT_PREPROCESSOR_EMPTY_HPP
#include <sprout/config.hpp>
//
// SPROUT_PP_EMPTY
//
#define SPROUT_PP_EMPTY()
#endif // #ifndef SPROUT_PREPROCESSOR_EMPTY_HPP