mirror of
https://github.com/bolero-MURAKAMI/Sprout
synced 2024-11-12 21:09:01 +00:00
fix char literal implementation
This commit is contained in:
parent
773855410b
commit
897d1e25b6
18 changed files with 325 additions and 95 deletions
|
@ -24,7 +24,7 @@ namespace sprout {
|
|||
inline SPROUT_CXX14_CONSTEXPR OutputIterator
|
||||
clamp_range(
|
||||
InputIterator first, InputIterator last, OutputIterator result,
|
||||
typename std::iterator_traits<InputIterator>::value_type const& low,
|
||||
typename std::iterator_traits<InputIterator>::value_type const& low,
|
||||
typename std::iterator_traits<InputIterator>::value_type const& high,
|
||||
Compare comp
|
||||
)
|
||||
|
@ -41,7 +41,7 @@ namespace sprout {
|
|||
inline SPROUT_CXX14_CONSTEXPR OutputIterator
|
||||
clamp_range(
|
||||
InputIterator first, InputIterator last, OutputIterator result,
|
||||
typename std::iterator_traits<InputIterator>::value_type const& low,
|
||||
typename std::iterator_traits<InputIterator>::value_type const& low,
|
||||
typename std::iterator_traits<InputIterator>::value_type const& high
|
||||
)
|
||||
{
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
#include <sprout/config.hpp>
|
||||
#include <sprout/workaround/std/cstddef.hpp>
|
||||
#include <sprout/detail/sizeof.hpp>
|
||||
#include <sprout/detail/char_literal.hpp>
|
||||
#include <sprout/container/traits.hpp>
|
||||
#include <sprout/iterator/index_iterator.hpp>
|
||||
#include <sprout/functional/hash.hpp>
|
||||
|
@ -1084,12 +1085,12 @@ namespace sprout {
|
|||
template<typename Char, typename Traits, typename Alloc>
|
||||
SPROUT_NON_CONSTEXPR void
|
||||
copy_from_string(std::basic_string<Char, Traits, Alloc> const& s, std::size_t pos, std::size_t n) {
|
||||
copy_from_string(s, pos, n, Char('0'), Char('1'));
|
||||
copy_from_string(s, pos, n, SPROUT_CHAR_LITERAL('0', Char), SPROUT_CHAR_LITERAL('1', Char));
|
||||
}
|
||||
template<typename Char, typename Traits, typename Alloc>
|
||||
SPROUT_NON_CONSTEXPR void
|
||||
copy_to_string(std::basic_string<Char, Traits, Alloc>& s) const {
|
||||
copy_to_string(s, Char('0'), Char('1'));
|
||||
copy_to_string(s, SPROUT_CHAR_LITERAL('0', Char), SPROUT_CHAR_LITERAL('1', Char));
|
||||
}
|
||||
|
||||
SPROUT_CONSTEXPR std::size_t to_hash() const {
|
||||
|
@ -1111,7 +1112,7 @@ namespace sprout {
|
|||
if (position > s.size()) {
|
||||
throw std::out_of_range("bitset::bitset initial position not valid");
|
||||
}
|
||||
copy_from_string(s, position, std::basic_string<Char, Traits, Alloc>::npos, Char('0'), Char('1'));
|
||||
copy_from_string(s, position, std::basic_string<Char, Traits, Alloc>::npos, SPROUT_CHAR_LITERAL('0', Char), SPROUT_CHAR_LITERAL('1', Char));
|
||||
}
|
||||
template<typename Char, typename Traits, typename Alloc>
|
||||
SPROUT_NON_CONSTEXPR bitset(std::basic_string<Char, Traits, Alloc> const& s, std::size_t position, std::size_t n)
|
||||
|
@ -1120,13 +1121,13 @@ namespace sprout {
|
|||
if (position > s.size()) {
|
||||
throw std::out_of_range("bitset::bitset initial position not valid");
|
||||
}
|
||||
copy_from_string(s, position, n, Char('0'), Char('1'));
|
||||
copy_from_string(s, position, n, SPROUT_CHAR_LITERAL('0', Char), SPROUT_CHAR_LITERAL('1', Char));
|
||||
}
|
||||
|
||||
template<typename Char, typename Traits, typename Alloc>
|
||||
SPROUT_NON_CONSTEXPR bitset(
|
||||
std::basic_string<Char, Traits, Alloc> const& s, std::size_t position, std::size_t n,
|
||||
Char zero, Char one = Char('1')
|
||||
Char zero, Char one = SPROUT_CHAR_LITERAL('1', Char)
|
||||
)
|
||||
: base_type()
|
||||
{
|
||||
|
@ -1138,7 +1139,7 @@ namespace sprout {
|
|||
template<typename Char>
|
||||
explicit SPROUT_NON_CONSTEXPR bitset(
|
||||
Char const* str, typename std::basic_string<Char>::std::size_type n = std::basic_string<Char>::npos,
|
||||
Char zero = Char('0'), Char one = Char('1')
|
||||
Char zero = SPROUT_CHAR_LITERAL('0', Char), Char one = SPROUT_CHAR_LITERAL('1', Char)
|
||||
)
|
||||
: base_type()
|
||||
{
|
||||
|
@ -1290,12 +1291,12 @@ namespace sprout {
|
|||
SPROUT_NON_CONSTEXPR std::basic_string<Char, Traits, Alloc>
|
||||
to_string() const {
|
||||
std::basic_string<Char, Traits, Alloc> result;
|
||||
copy_to_string(result, Char('0'), Char('1'));
|
||||
copy_to_string(result, SPROUT_CHAR_LITERAL('0', Char), SPROUT_CHAR_LITERAL('1', Char));
|
||||
return result;
|
||||
}
|
||||
template<typename Char, typename Traits, typename Alloc>
|
||||
SPROUT_NON_CONSTEXPR std::basic_string<Char, Traits, Alloc>
|
||||
to_string(Char zero, Char one = Char('1')) const {
|
||||
to_string(Char zero, Char one = SPROUT_CHAR_LITERAL('1', Char)) const {
|
||||
std::basic_string<Char, Traits, Alloc> result;
|
||||
copy_to_string(result, zero, one);
|
||||
return result;
|
||||
|
@ -1307,7 +1308,7 @@ namespace sprout {
|
|||
}
|
||||
template<typename Char, typename Traits>
|
||||
SPROUT_NON_CONSTEXPR std::basic_string<Char, Traits, std::allocator<Char> >
|
||||
to_string(Char zero, Char one = Char('1')) const {
|
||||
to_string(Char zero, Char one = SPROUT_CHAR_LITERAL('1', Char)) const {
|
||||
return to_string<Char, Traits, std::allocator<Char> >(zero, one);
|
||||
}
|
||||
template<typename Char>
|
||||
|
@ -1317,7 +1318,7 @@ namespace sprout {
|
|||
}
|
||||
template<typename Char>
|
||||
SPROUT_NON_CONSTEXPR std::basic_string<Char, std::char_traits<Char>, std::allocator<Char> >
|
||||
to_string(Char zero, Char one = Char('1')) const {
|
||||
to_string(Char zero, Char one = SPROUT_CHAR_LITERAL('1', Char)) const {
|
||||
return to_string<Char, std::char_traits<Char>, std::allocator<Char> >(zero, one);
|
||||
}
|
||||
SPROUT_NON_CONSTEXPR std::basic_string<char, std::char_traits<char>, std::allocator<char> >
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include <sprout/algorithm/fixed/results.hpp>
|
||||
#include <sprout/algorithm/fixed/copy.hpp>
|
||||
#include <sprout/operation/fixed/set.hpp>
|
||||
#include <sprout/detail/char_literal.hpp>
|
||||
#include HDR_ALGORITHM_MIN_MAX_SSCRISK_CEL_OR_SPROUT
|
||||
|
||||
namespace sprout {
|
||||
|
@ -30,8 +31,8 @@ namespace sprout {
|
|||
inline SPROUT_CONSTEXPR InputIterator
|
||||
find_scope_end(InputIterator first, std::size_t count = 0) {
|
||||
typedef typename std::iterator_traits<InputIterator>::value_type value_type;
|
||||
return *first == value_type('[') ? sprout::brainfuck::detail::find_scope_end(sprout::next(first), count + 1)
|
||||
: *first == value_type(']') ? count == 0
|
||||
return *first == SPROUT_CHAR_LITERAL('[', value_type) ? sprout::brainfuck::detail::find_scope_end(sprout::next(first), count + 1)
|
||||
: *first == SPROUT_CHAR_LITERAL(']', value_type) ? count == 0
|
||||
? first
|
||||
: sprout::brainfuck::detail::find_scope_end(sprout::next(first), count - 1)
|
||||
: sprout::brainfuck::detail::find_scope_end(sprout::next(first), count)
|
||||
|
@ -42,8 +43,8 @@ namespace sprout {
|
|||
inline SPROUT_CONSTEXPR BidirectionalIterator
|
||||
find_scope_start(BidirectionalIterator first, std::size_t count = 0) {
|
||||
typedef typename std::iterator_traits<BidirectionalIterator>::value_type value_type;
|
||||
return *first == value_type(']') ? sprout::brainfuck::detail::find_scope_start(sprout::prev(first), count + 1)
|
||||
: *first == value_type('[') ? count == 0
|
||||
return *first == SPROUT_CHAR_LITERAL(']', value_type) ? sprout::brainfuck::detail::find_scope_start(sprout::prev(first), count + 1)
|
||||
: *first == SPROUT_CHAR_LITERAL('[', value_type) ? count == 0
|
||||
? first
|
||||
: sprout::brainfuck::detail::find_scope_start(sprout::prev(first), count - 1)
|
||||
: sprout::brainfuck::detail::find_scope_start(sprout::prev(first), count)
|
||||
|
@ -55,9 +56,9 @@ namespace sprout {
|
|||
is_well_formed(InputIterator first, InputIterator last, std::size_t count = 0) {
|
||||
typedef typename std::iterator_traits<InputIterator>::value_type value_type;
|
||||
return first == last ? count == 0
|
||||
: *first == value_type('[')
|
||||
: *first == SPROUT_CHAR_LITERAL('[', value_type)
|
||||
? sprout::brainfuck::detail::is_well_formed(sprout::next(first), last, count + 1)
|
||||
: *first == value_type(']')
|
||||
: *first == SPROUT_CHAR_LITERAL(']', value_type)
|
||||
? count != 0 && sprout::brainfuck::detail::is_well_formed(sprout::next(first), last, count - 1)
|
||||
: sprout::brainfuck::detail::is_well_formed(sprout::next(first), last, count)
|
||||
;
|
||||
|
@ -82,39 +83,39 @@ namespace sprout {
|
|||
sprout::next(sprout::begin(out_buffer), NS_SSCRISK_CEL_OR_SPROUT::min(out_pos, sprout::size(out_buffer))),
|
||||
output
|
||||
)
|
||||
: *first == value_type('>')
|
||||
: *first == SPROUT_CHAR_LITERAL('>', value_type)
|
||||
? sprout::brainfuck::detail::exec_impl(
|
||||
sprout::next(first), last, output, in_first, in_last,
|
||||
buffer, out_buffer, pos + 1, out_pos
|
||||
)
|
||||
: *first == value_type('<')
|
||||
: *first == SPROUT_CHAR_LITERAL('<', value_type)
|
||||
? sprout::brainfuck::detail::exec_impl(
|
||||
sprout::next(first), last, output, in_first, in_last,
|
||||
buffer, out_buffer, pos - 1, out_pos
|
||||
)
|
||||
: *first == value_type('+')
|
||||
: *first == SPROUT_CHAR_LITERAL('+', value_type)
|
||||
? sprout::brainfuck::detail::exec_impl(
|
||||
sprout::next(first), last, output, in_first, in_last,
|
||||
sprout::fixed::set(buffer, pos, value_type(buffer.at(pos) + 1)), out_buffer, pos, out_pos
|
||||
)
|
||||
: *first == value_type('-')
|
||||
: *first == SPROUT_CHAR_LITERAL('+', value_type)
|
||||
? sprout::brainfuck::detail::exec_impl(
|
||||
sprout::next(first), last, output, in_first, in_last,
|
||||
sprout::fixed::set(buffer, pos, value_type(buffer.at(pos) - 1)), out_buffer, pos, out_pos
|
||||
)
|
||||
: *first == value_type('.') ? out_pos != out_buffer.size()
|
||||
: *first == SPROUT_CHAR_LITERAL('.', value_type) ? out_pos != out_buffer.size()
|
||||
? sprout::brainfuck::detail::exec_impl(
|
||||
sprout::next(first), last, output, in_first, in_last,
|
||||
buffer, sprout::fixed::set(out_buffer, out_pos, out_value_type(buffer.at(pos))), pos, out_pos + 1
|
||||
)
|
||||
: throw std::out_of_range("output out of range")
|
||||
: *first == value_type(',') ? in_first != in_last
|
||||
: *first == SPROUT_CHAR_LITERAL(',', value_type) ? in_first != in_last
|
||||
? sprout::brainfuck::detail::exec_impl(
|
||||
sprout::next(first), last, output, sprout::next(in_first), in_last,
|
||||
sprout::fixed::set(buffer, pos, value_type(*in_first)), out_buffer, pos, out_pos
|
||||
)
|
||||
: throw std::out_of_range("input out of range")
|
||||
: *first == value_type('[') ? buffer.at(pos) == 0
|
||||
: *first == SPROUT_CHAR_LITERAL('[', value_type) ? buffer.at(pos) == 0
|
||||
? sprout::brainfuck::detail::exec_impl(
|
||||
sprout::next(sprout::brainfuck::detail::find_scope_end(sprout::next(first))), last, output, in_first, in_last,
|
||||
buffer, out_buffer, pos, out_pos
|
||||
|
@ -123,7 +124,7 @@ namespace sprout {
|
|||
sprout::next(first), last, output, in_first, in_last,
|
||||
buffer, out_buffer, pos, out_pos
|
||||
)
|
||||
: *first == value_type(']') ? buffer.at(pos) != 0
|
||||
: *first == SPROUT_CHAR_LITERAL(']', value_type) ? buffer.at(pos) != 0
|
||||
? sprout::brainfuck::detail::exec_impl(
|
||||
sprout::next(sprout::brainfuck::detail::find_scope_start(sprout::prev(first))), last, output, in_first, in_last,
|
||||
buffer, out_buffer, pos, out_pos
|
||||
|
|
|
@ -14,6 +14,8 @@
|
|||
#include <sprout/limits.hpp>
|
||||
#include <sprout/iterator/operation.hpp>
|
||||
#include <sprout/ctype/ascii.hpp>
|
||||
#include <sprout/detail/char_literal.hpp>
|
||||
#include <sprout/detail/char_type_of_consecutive.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace detail {
|
||||
|
@ -22,13 +24,15 @@ namespace sprout {
|
|||
template<typename IntType, typename NullTerminatedIterator>
|
||||
inline SPROUT_CONSTEXPR IntType
|
||||
ascii_to_int_impl(NullTerminatedIterator str, IntType val, bool negative) {
|
||||
typedef typename std::iterator_traits<NullTerminatedIterator>::value_type value_type;
|
||||
SPROUT_STATIC_ASSERT(sprout::detail::is_char_type_of_consecutive_digits<value_type>::value);
|
||||
return !sprout::ascii::isdigit(*str)
|
||||
? negative ? -val : val
|
||||
: val > (sprout::numeric_limits<IntType>::max() - (*str - static_cast<typename std::iterator_traits<NullTerminatedIterator>::value_type>('0')) - (negative ? 1 : 0)) / 10
|
||||
: val > (sprout::numeric_limits<IntType>::max() - (*str - SPROUT_CHAR_LITERAL('0', value_type)) - (negative ? 1 : 0)) / 10
|
||||
? (negative ? sprout::numeric_limits<IntType>::min() : sprout::numeric_limits<IntType>::max())
|
||||
: sprout::detail::ascii_to_int_impl<IntType>(
|
||||
sprout::next(str),
|
||||
val * 10 + (*str - static_cast<typename std::iterator_traits<NullTerminatedIterator>::value_type>('0')),
|
||||
val * 10 + (*str - SPROUT_CHAR_LITERAL('0', value_type)),
|
||||
negative
|
||||
)
|
||||
;
|
||||
|
@ -39,9 +43,10 @@ namespace sprout {
|
|||
IntType
|
||||
>::type
|
||||
ascii_to_int(NullTerminatedIterator str) {
|
||||
typedef typename std::iterator_traits<NullTerminatedIterator>::value_type value_type;
|
||||
return sprout::ascii::isspace(*str)
|
||||
? sprout::detail::ascii_to_int<IntType>(sprout::next(str))
|
||||
: *str == static_cast<typename std::iterator_traits<NullTerminatedIterator>::value_type>('+')
|
||||
: *str == SPROUT_CHAR_LITERAL('+', value_type)
|
||||
? sprout::detail::ascii_to_int_impl<IntType>(sprout::next(str), IntType(), false)
|
||||
: sprout::detail::ascii_to_int_impl<IntType>(str, IntType(), false)
|
||||
;
|
||||
|
@ -52,11 +57,12 @@ namespace sprout {
|
|||
IntType
|
||||
>::type
|
||||
ascii_to_int(NullTerminatedIterator str) {
|
||||
typedef typename std::iterator_traits<NullTerminatedIterator>::value_type value_type;
|
||||
return sprout::ascii::isspace(*str)
|
||||
? sprout::detail::ascii_to_int<IntType>(sprout::next(str))
|
||||
: *str == static_cast<typename std::iterator_traits<NullTerminatedIterator>::value_type>('-')
|
||||
: *str == SPROUT_CHAR_LITERAL('-', value_type)
|
||||
? sprout::detail::ascii_to_int_impl<IntType>(sprout::next(str), IntType(), true)
|
||||
: *str == static_cast<typename std::iterator_traits<NullTerminatedIterator>::value_type>('+')
|
||||
: *str == SPROUT_CHAR_LITERAL('+', value_type)
|
||||
? sprout::detail::ascii_to_int_impl<IntType>(sprout::next(str), IntType(), false)
|
||||
: sprout::detail::ascii_to_int_impl<IntType>(str, IntType(), false)
|
||||
;
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
#include <sprout/limits.hpp>
|
||||
#include <sprout/iterator/operation.hpp>
|
||||
#include <sprout/ctype/ascii.hpp>
|
||||
#include <sprout/detail/char_literal.hpp>
|
||||
#include <sprout/detail/char_type_of_consecutive.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace detail {
|
||||
|
@ -83,6 +85,7 @@ namespace sprout {
|
|||
)
|
||||
{
|
||||
typedef typename std::iterator_traits<NullTerminatedIterator>::value_type char_type;
|
||||
SPROUT_STATIC_ASSERT(sprout::detail::is_char_type_of_consecutive_digits<char_type>::value);
|
||||
return sprout::ascii::isdigit(*str) ? sprout::detail::str_to_float_impl_exponent_1<FloatType>(
|
||||
sprout::next(str),
|
||||
negative,
|
||||
|
@ -90,7 +93,7 @@ namespace sprout {
|
|||
num_digits,
|
||||
num_decimals,
|
||||
exponent,
|
||||
n * 10 + (*str - static_cast<char_type>('0'))
|
||||
n * 10 + (*str - SPROUT_CHAR_LITERAL('0', char_type))
|
||||
)
|
||||
: sprout::detail::str_to_float_impl_exponent_2<FloatType>(
|
||||
str,
|
||||
|
@ -114,8 +117,8 @@ namespace sprout {
|
|||
)
|
||||
{
|
||||
typedef typename std::iterator_traits<NullTerminatedIterator>::value_type char_type;
|
||||
return (*str == static_cast<char_type>('e') || *str == static_cast<char_type>('E'))
|
||||
? *sprout::next(str) == static_cast<char_type>('-')
|
||||
return (*str == SPROUT_CHAR_LITERAL('e', char_type) || *str == SPROUT_CHAR_LITERAL('E', char_type))
|
||||
? *sprout::next(str) == SPROUT_CHAR_LITERAL('-', char_type)
|
||||
? sprout::detail::str_to_float_impl_exponent_1<FloatType>(
|
||||
sprout::next(str, 2),
|
||||
true,
|
||||
|
@ -176,10 +179,11 @@ namespace sprout {
|
|||
)
|
||||
{
|
||||
typedef typename std::iterator_traits<NullTerminatedIterator>::value_type char_type;
|
||||
SPROUT_STATIC_ASSERT(sprout::detail::is_char_type_of_consecutive_digits<char_type>::value);
|
||||
return sprout::ascii::isdigit(*str) ? sprout::detail::str_to_float_impl_decimal<FloatType>(
|
||||
sprout::next(str),
|
||||
negative,
|
||||
number * 10 + (*str - static_cast<char_type>('0')),
|
||||
number * 10 + (*str - SPROUT_CHAR_LITERAL('0', char_type)),
|
||||
num_digits + 1,
|
||||
num_decimals + 1,
|
||||
exponent
|
||||
|
@ -205,13 +209,14 @@ namespace sprout {
|
|||
)
|
||||
{
|
||||
typedef typename std::iterator_traits<NullTerminatedIterator>::value_type char_type;
|
||||
SPROUT_STATIC_ASSERT(sprout::detail::is_char_type_of_consecutive_digits<char_type>::value);
|
||||
return sprout::ascii::isdigit(*str) ? sprout::detail::str_to_float_impl<FloatType>(
|
||||
sprout::next(str),
|
||||
negative,
|
||||
number * 10 + (*str - static_cast<char_type>('0')),
|
||||
number * 10 + (*str - SPROUT_CHAR_LITERAL('0', char_type)),
|
||||
num_digits + 1
|
||||
)
|
||||
: *str == static_cast<char_type>('.') ? sprout::detail::str_to_float_impl_decimal<FloatType>(
|
||||
: *str == SPROUT_CHAR_LITERAL('.', char_type) ? sprout::detail::str_to_float_impl_decimal<FloatType>(
|
||||
sprout::next(str),
|
||||
negative,
|
||||
number,
|
||||
|
@ -228,11 +233,12 @@ namespace sprout {
|
|||
template<typename FloatType, typename NullTerminatedIterator>
|
||||
inline SPROUT_CONSTEXPR FloatType
|
||||
str_to_float(NullTerminatedIterator str) {
|
||||
typedef typename std::iterator_traits<NullTerminatedIterator>::value_type char_type;
|
||||
return sprout::ascii::isspace(*str)
|
||||
? sprout::detail::str_to_float<FloatType>(sprout::next(str))
|
||||
: *str == static_cast<typename std::iterator_traits<NullTerminatedIterator>::value_type>('-')
|
||||
: *str == SPROUT_CHAR_LITERAL('-', char_type)
|
||||
? sprout::detail::str_to_float_impl<FloatType>(sprout::next(str), true)
|
||||
: *str == static_cast<typename std::iterator_traits<NullTerminatedIterator>::value_type>('+')
|
||||
: *str == SPROUT_CHAR_LITERAL('+', char_type)
|
||||
? sprout::detail::str_to_float_impl<FloatType>(sprout::next(str), false)
|
||||
: sprout::detail::str_to_float_impl<FloatType>(str, false)
|
||||
;
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
#include <sprout/limits.hpp>
|
||||
#include <sprout/iterator/operation.hpp>
|
||||
#include <sprout/ctype/ascii.hpp>
|
||||
#include <sprout/detail/char_literal.hpp>
|
||||
#include <sprout/detail/char_conversion.hpp>
|
||||
#if !defined(_MSC_VER)
|
||||
# include <cinttypes>
|
||||
|
@ -42,9 +43,10 @@ namespace sprout {
|
|||
template<typename IntType, typename NullTerminatedIterator>
|
||||
inline SPROUT_CONSTEXPR IntType
|
||||
str_to_int_impl(NullTerminatedIterator str, int base, bool negative) {
|
||||
return *str == static_cast<typename std::iterator_traits<NullTerminatedIterator>::value_type>('0')
|
||||
? *sprout::next(str) == static_cast<typename std::iterator_traits<NullTerminatedIterator>::value_type>('x')
|
||||
|| *sprout::next(str) == static_cast<typename std::iterator_traits<NullTerminatedIterator>::value_type>('X')
|
||||
typedef typename std::iterator_traits<NullTerminatedIterator>::value_type char_type;
|
||||
return *str == SPROUT_CHAR_LITERAL('0', char_type)
|
||||
? *sprout::next(str) == SPROUT_CHAR_LITERAL('x', char_type)
|
||||
|| *sprout::next(str) == SPROUT_CHAR_LITERAL('X', char_type)
|
||||
? sprout::detail::str_to_int_impl_1<IntType>(
|
||||
sprout::next(str, 2),
|
||||
base ? base : 16,
|
||||
|
@ -74,9 +76,10 @@ namespace sprout {
|
|||
IntType
|
||||
>::type
|
||||
str_to_int(NullTerminatedIterator str, int base) {
|
||||
typedef typename std::iterator_traits<NullTerminatedIterator>::value_type char_type;
|
||||
return sprout::ascii::isspace(*str)
|
||||
? sprout::detail::str_to_int<IntType>(sprout::next(str), base)
|
||||
: *str == static_cast<typename std::iterator_traits<NullTerminatedIterator>::value_type>('+')
|
||||
: *str == SPROUT_CHAR_LITERAL('+', char_type)
|
||||
? sprout::detail::str_to_int_impl<IntType>(sprout::next(str), base, false)
|
||||
: sprout::detail::str_to_int_impl<IntType>(str, base, false)
|
||||
;
|
||||
|
@ -87,11 +90,12 @@ namespace sprout {
|
|||
IntType
|
||||
>::type
|
||||
str_to_int(NullTerminatedIterator str, int base) {
|
||||
typedef typename std::iterator_traits<NullTerminatedIterator>::value_type char_type;
|
||||
return sprout::ascii::isspace(*str)
|
||||
? sprout::detail::str_to_int<IntType>(sprout::next(str), base)
|
||||
: *str == static_cast<typename std::iterator_traits<NullTerminatedIterator>::value_type>('-')
|
||||
: *str == SPROUT_CHAR_LITERAL('-', char_type)
|
||||
? sprout::detail::str_to_int_impl<IntType>(sprout::next(str), base, true)
|
||||
: *str == static_cast<typename std::iterator_traits<NullTerminatedIterator>::value_type>('+')
|
||||
: *str == SPROUT_CHAR_LITERAL('+', char_type)
|
||||
? sprout::detail::str_to_int_impl<IntType>(sprout::next(str), base, false)
|
||||
: sprout::detail::str_to_int_impl<IntType>(str, base, false)
|
||||
;
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include <sprout/ctype/ascii.hpp>
|
||||
#include <sprout/algorithm/equal.hpp>
|
||||
#include <sprout/iterator/ptr_index_iterator.hpp>
|
||||
#include <sprout/detail/char_conversion.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace detail {
|
||||
|
@ -44,9 +45,9 @@ namespace sprout {
|
|||
namespace detail {
|
||||
template<typename Elem>
|
||||
inline SPROUT_CONSTEXPR int
|
||||
get_num(Elem e) {
|
||||
return !sprout::isdigit(e) ? 0
|
||||
: e - static_cast<Elem>('0')
|
||||
get_num(Elem c) {
|
||||
return !sprout::isdigit(c) ? 0
|
||||
: sprout::detail::char_to_int(c)
|
||||
;
|
||||
}
|
||||
template<typename InputIterator>
|
||||
|
|
|
@ -13,38 +13,48 @@
|
|||
#include <sprout/workaround/std/cstddef.hpp>
|
||||
#include <sprout/ctype/ascii.hpp>
|
||||
#include <sprout/assert.hpp>
|
||||
#include <sprout/static_assert.hpp>
|
||||
#include <sprout/detail/char_literal.hpp>
|
||||
#include <sprout/detail/char_type_of_consecutive.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace detail {
|
||||
template<typename Elem, typename IntType>
|
||||
inline SPROUT_CONSTEXPR Elem
|
||||
int_to_char(IntType val, int base) {
|
||||
SPROUT_STATIC_ASSERT(sprout::detail::is_char_type_of_consecutive_digits<Elem>::value);
|
||||
SPROUT_STATIC_ASSERT(sprout::detail::is_char_type_of_consecutive_lower_alphabet<Elem>::value);
|
||||
return SPROUT_ASSERT(2 <= base && base <= 36), SPROUT_ASSERT(IntType(0) <= val && val < static_cast<IntType>(base)),
|
||||
val < 10 ? static_cast<Elem>('0') + val
|
||||
: static_cast<Elem>('a') + (val - 10)
|
||||
val < 10 ? SPROUT_CHAR_LITERAL('0', Elem) + val
|
||||
: SPROUT_CHAR_LITERAL('a', Elem) + (val - 10)
|
||||
;
|
||||
}
|
||||
template<typename Elem, typename IntType>
|
||||
inline SPROUT_CONSTEXPR Elem
|
||||
int_to_char(IntType val) {
|
||||
SPROUT_STATIC_ASSERT(sprout::detail::is_char_type_of_consecutive_digits<Elem>::value);
|
||||
return SPROUT_ASSERT(IntType(0) <= val && val < IntType(10)),
|
||||
static_cast<Elem>('0') + val
|
||||
SPROUT_CHAR_LITERAL('0', Elem) + val
|
||||
;
|
||||
}
|
||||
|
||||
template<typename IntType, typename Elem>
|
||||
inline SPROUT_CONSTEXPR IntType
|
||||
char_to_int(Elem c, int base) {
|
||||
return sprout::ascii::isdigit(c) && c - static_cast<Elem>('0') < base ? c - static_cast<Elem>('0')
|
||||
: sprout::ascii::islower(c) && c - static_cast<Elem>('a') + 10 < base ? c - static_cast<Elem>('a') + 10
|
||||
: sprout::ascii::isupper(c) && c - static_cast<Elem>('A') + 10 < base ? c - static_cast<Elem>('A') + 10
|
||||
SPROUT_STATIC_ASSERT(sprout::detail::is_char_type_of_consecutive_digits<Elem>::value);
|
||||
SPROUT_STATIC_ASSERT(sprout::detail::is_char_type_of_consecutive_lower_alphabet<Elem>::value);
|
||||
SPROUT_STATIC_ASSERT(sprout::detail::is_char_type_of_consecutive_upper_alphabet<Elem>::value);
|
||||
return sprout::ascii::isdigit(c) && c - SPROUT_CHAR_LITERAL('0', Elem) < base ? c - SPROUT_CHAR_LITERAL('0', Elem)
|
||||
: sprout::ascii::islower(c) && c - SPROUT_CHAR_LITERAL('a', Elem) + 10 < base ? c - SPROUT_CHAR_LITERAL('a', Elem) + 10
|
||||
: sprout::ascii::isupper(c) && c - SPROUT_CHAR_LITERAL('A', Elem) + 10 < base ? c - SPROUT_CHAR_LITERAL('A', Elem) + 10
|
||||
: static_cast<IntType>(-1)
|
||||
;
|
||||
}
|
||||
template<typename IntType, typename Elem>
|
||||
inline SPROUT_CONSTEXPR IntType
|
||||
char_to_int(Elem c) {
|
||||
return sprout::ascii::isdigit(c) ? c - static_cast<Elem>('0')
|
||||
SPROUT_STATIC_ASSERT(sprout::detail::is_char_type_of_consecutive_digits<Elem>::value);
|
||||
return sprout::ascii::isdigit(c) ? c - SPROUT_CHAR_LITERAL('0', Elem)
|
||||
: static_cast<IntType>(-1)
|
||||
;
|
||||
}
|
||||
|
|
62
sprout/detail/char_literal.hpp
Normal file
62
sprout/detail/char_literal.hpp
Normal file
|
@ -0,0 +1,62 @@
|
|||
/*=============================================================================
|
||||
Copyright (c) 2011-2014 Bolero MURAKAMI
|
||||
https://github.com/bolero-MURAKAMI/Sprout
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
=============================================================================*/
|
||||
#ifndef SPROUT_DETAIL_CHAR_LITERAL_HPP
|
||||
#define SPROUT_DETAIL_CHAR_LITERAL_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/type_traits/integral_constant.hpp>
|
||||
#include <sprout/preprocessor/cat.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace detail {
|
||||
#if SPROUT_USE_UNICODE_LITERALS
|
||||
template<typename Elem, char C, wchar_t WC, char16_t C16, char32_t C32>
|
||||
struct char_literal_of;
|
||||
template<char C, wchar_t WC, char16_t C16, char32_t C32>
|
||||
struct char_literal_of<char, C, WC, C16, C32>
|
||||
: public sprout::integral_constant<char, C>
|
||||
{};
|
||||
template<char C, wchar_t WC, char16_t C16, char32_t C32>
|
||||
struct char_literal_of<wchar_t, C, WC, C16, C32>
|
||||
: public sprout::integral_constant<wchar_t, WC>
|
||||
{};
|
||||
template<char C, wchar_t WC, char16_t C16, char32_t C32>
|
||||
struct char_literal_of<char16_t, C, WC, C16, C32>
|
||||
: public sprout::integral_constant<char16_t, C16>
|
||||
{};
|
||||
template<char C, wchar_t WC, char16_t C16, char32_t C32>
|
||||
struct char_literal_of<char32_t, C, WC, C16, C32>
|
||||
: public sprout::integral_constant<char32_t, C32>
|
||||
{};
|
||||
#else
|
||||
template<typename Elem, char C, wchar_t WC>
|
||||
struct char_literal_of;
|
||||
template<char C, wchar_t WC>
|
||||
struct char_literal_of<char, C, WC>
|
||||
: public sprout::integral_constant<char, C>
|
||||
{};
|
||||
template<char C, wchar_t WC>
|
||||
struct char_literal_of<wchar_t, C, WC>
|
||||
: public sprout::integral_constant<wchar_t, WC>
|
||||
{};
|
||||
#endif
|
||||
} // namespace detail
|
||||
} // namespace sprout
|
||||
|
||||
//
|
||||
// SPROUT_CHAR_LITERAL
|
||||
//
|
||||
#if SPROUT_USE_UNICODE_LITERALS
|
||||
# define SPROUT_CHAR_LITERAL(CHAR, TYPE) \
|
||||
(sprout::detail::char_literal_of<TYPE, CHAR, SPROUT_PP_CAT(L, CHAR), SPROUT_PP_CAT(u, CHAR), SPROUT_PP_CAT(U, CHAR)>::value)
|
||||
#else
|
||||
# define SPROUT_CHAR_LITERAL(CHAR, TYPE) \
|
||||
(sprout::detail::char_literal_of<TYPE, CHAR, SPROUT_PP_CAT(L, CHAR)>::value)
|
||||
#endif
|
||||
|
||||
#endif // #ifndef SPROUT_DETAIL_CHAR_LITERAL_HPP
|
135
sprout/detail/char_type_of_consecutive.hpp
Normal file
135
sprout/detail/char_type_of_consecutive.hpp
Normal file
|
@ -0,0 +1,135 @@
|
|||
/*=============================================================================
|
||||
Copyright (c) 2011-2014 Bolero MURAKAMI
|
||||
https://github.com/bolero-MURAKAMI/Sprout
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
=============================================================================*/
|
||||
#ifndef SPROUT_DETAIL_CHAR_TYPE_OF_CONSECUTIVE_HPP
|
||||
#define SPROUT_DETAIL_CHAR_TYPE_OF_CONSECUTIVE_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/type_traits/integral_constant.hpp>
|
||||
#include <sprout/detail/char_literal.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace detail {
|
||||
template<typename CharType>
|
||||
struct is_char_type_of_consecutive_digits
|
||||
: public sprout::integral_constant<
|
||||
bool,
|
||||
SPROUT_CHAR_LITERAL('0', CharType) + 1 == SPROUT_CHAR_LITERAL('1', CharType)
|
||||
&& SPROUT_CHAR_LITERAL('1', CharType) + 1 == SPROUT_CHAR_LITERAL('2', CharType)
|
||||
&& SPROUT_CHAR_LITERAL('2', CharType) + 1 == SPROUT_CHAR_LITERAL('3', CharType)
|
||||
&& SPROUT_CHAR_LITERAL('3', CharType) + 1 == SPROUT_CHAR_LITERAL('4', CharType)
|
||||
&& SPROUT_CHAR_LITERAL('4', CharType) + 1 == SPROUT_CHAR_LITERAL('5', CharType)
|
||||
&& SPROUT_CHAR_LITERAL('5', CharType) + 1 == SPROUT_CHAR_LITERAL('6', CharType)
|
||||
&& SPROUT_CHAR_LITERAL('6', CharType) + 1 == SPROUT_CHAR_LITERAL('7', CharType)
|
||||
&& SPROUT_CHAR_LITERAL('7', CharType) + 1 == SPROUT_CHAR_LITERAL('8', CharType)
|
||||
&& SPROUT_CHAR_LITERAL('8', CharType) + 1 == SPROUT_CHAR_LITERAL('9', CharType)
|
||||
>
|
||||
{};
|
||||
template<typename CharType>
|
||||
struct is_char_type_of_consecutive_digits<CharType const>
|
||||
: public sprout::detail::is_char_type_of_consecutive_digits<CharType>
|
||||
{};
|
||||
template<typename CharType>
|
||||
struct is_char_type_of_consecutive_digits<CharType volatile>
|
||||
: public sprout::detail::is_char_type_of_consecutive_digits<CharType>
|
||||
{};
|
||||
template<typename CharType>
|
||||
struct is_char_type_of_consecutive_digits<CharType const volatile>
|
||||
: public sprout::detail::is_char_type_of_consecutive_digits<CharType>
|
||||
{};
|
||||
|
||||
template<typename CharType>
|
||||
struct is_char_type_of_consecutive_lower_alphabet
|
||||
: public sprout::integral_constant<
|
||||
bool,
|
||||
SPROUT_CHAR_LITERAL('a', CharType) + 1 == SPROUT_CHAR_LITERAL('b', CharType)
|
||||
&& SPROUT_CHAR_LITERAL('b', CharType) + 1 == SPROUT_CHAR_LITERAL('c', CharType)
|
||||
&& SPROUT_CHAR_LITERAL('c', CharType) + 1 == SPROUT_CHAR_LITERAL('d', CharType)
|
||||
&& SPROUT_CHAR_LITERAL('d', CharType) + 1 == SPROUT_CHAR_LITERAL('e', CharType)
|
||||
&& SPROUT_CHAR_LITERAL('e', CharType) + 1 == SPROUT_CHAR_LITERAL('f', CharType)
|
||||
&& SPROUT_CHAR_LITERAL('f', CharType) + 1 == SPROUT_CHAR_LITERAL('g', CharType)
|
||||
&& SPROUT_CHAR_LITERAL('g', CharType) + 1 == SPROUT_CHAR_LITERAL('h', CharType)
|
||||
&& SPROUT_CHAR_LITERAL('h', CharType) + 1 == SPROUT_CHAR_LITERAL('i', CharType)
|
||||
&& SPROUT_CHAR_LITERAL('i', CharType) + 1 == SPROUT_CHAR_LITERAL('j', CharType)
|
||||
&& SPROUT_CHAR_LITERAL('j', CharType) + 1 == SPROUT_CHAR_LITERAL('k', CharType)
|
||||
&& SPROUT_CHAR_LITERAL('k', CharType) + 1 == SPROUT_CHAR_LITERAL('l', CharType)
|
||||
&& SPROUT_CHAR_LITERAL('l', CharType) + 1 == SPROUT_CHAR_LITERAL('m', CharType)
|
||||
&& SPROUT_CHAR_LITERAL('m', CharType) + 1 == SPROUT_CHAR_LITERAL('n', CharType)
|
||||
&& SPROUT_CHAR_LITERAL('n', CharType) + 1 == SPROUT_CHAR_LITERAL('o', CharType)
|
||||
&& SPROUT_CHAR_LITERAL('o', CharType) + 1 == SPROUT_CHAR_LITERAL('p', CharType)
|
||||
&& SPROUT_CHAR_LITERAL('p', CharType) + 1 == SPROUT_CHAR_LITERAL('q', CharType)
|
||||
&& SPROUT_CHAR_LITERAL('q', CharType) + 1 == SPROUT_CHAR_LITERAL('r', CharType)
|
||||
&& SPROUT_CHAR_LITERAL('r', CharType) + 1 == SPROUT_CHAR_LITERAL('s', CharType)
|
||||
&& SPROUT_CHAR_LITERAL('s', CharType) + 1 == SPROUT_CHAR_LITERAL('t', CharType)
|
||||
&& SPROUT_CHAR_LITERAL('t', CharType) + 1 == SPROUT_CHAR_LITERAL('u', CharType)
|
||||
&& SPROUT_CHAR_LITERAL('u', CharType) + 1 == SPROUT_CHAR_LITERAL('v', CharType)
|
||||
&& SPROUT_CHAR_LITERAL('v', CharType) + 1 == SPROUT_CHAR_LITERAL('w', CharType)
|
||||
&& SPROUT_CHAR_LITERAL('w', CharType) + 1 == SPROUT_CHAR_LITERAL('x', CharType)
|
||||
&& SPROUT_CHAR_LITERAL('x', CharType) + 1 == SPROUT_CHAR_LITERAL('y', CharType)
|
||||
&& SPROUT_CHAR_LITERAL('y', CharType) + 1 == SPROUT_CHAR_LITERAL('z', CharType)
|
||||
>
|
||||
{};
|
||||
template<typename CharType>
|
||||
struct is_char_type_of_consecutive_lower_alphabet<CharType const>
|
||||
: public sprout::detail::is_char_type_of_consecutive_lower_alphabet<CharType>
|
||||
{};
|
||||
template<typename CharType>
|
||||
struct is_char_type_of_consecutive_lower_alphabet<CharType volatile>
|
||||
: public sprout::detail::is_char_type_of_consecutive_lower_alphabet<CharType>
|
||||
{};
|
||||
template<typename CharType>
|
||||
struct is_char_type_of_consecutive_lower_alphabet<CharType const volatile>
|
||||
: public sprout::detail::is_char_type_of_consecutive_lower_alphabet<CharType>
|
||||
{};
|
||||
|
||||
template<typename CharType>
|
||||
struct is_char_type_of_consecutive_upper_alphabet
|
||||
: public sprout::integral_constant<
|
||||
bool,
|
||||
SPROUT_CHAR_LITERAL('A', CharType) + 1 == SPROUT_CHAR_LITERAL('B', CharType)
|
||||
&& SPROUT_CHAR_LITERAL('B', CharType) + 1 == SPROUT_CHAR_LITERAL('C', CharType)
|
||||
&& SPROUT_CHAR_LITERAL('C', CharType) + 1 == SPROUT_CHAR_LITERAL('D', CharType)
|
||||
&& SPROUT_CHAR_LITERAL('D', CharType) + 1 == SPROUT_CHAR_LITERAL('E', CharType)
|
||||
&& SPROUT_CHAR_LITERAL('E', CharType) + 1 == SPROUT_CHAR_LITERAL('F', CharType)
|
||||
&& SPROUT_CHAR_LITERAL('F', CharType) + 1 == SPROUT_CHAR_LITERAL('G', CharType)
|
||||
&& SPROUT_CHAR_LITERAL('G', CharType) + 1 == SPROUT_CHAR_LITERAL('H', CharType)
|
||||
&& SPROUT_CHAR_LITERAL('H', CharType) + 1 == SPROUT_CHAR_LITERAL('I', CharType)
|
||||
&& SPROUT_CHAR_LITERAL('I', CharType) + 1 == SPROUT_CHAR_LITERAL('J', CharType)
|
||||
&& SPROUT_CHAR_LITERAL('J', CharType) + 1 == SPROUT_CHAR_LITERAL('K', CharType)
|
||||
&& SPROUT_CHAR_LITERAL('K', CharType) + 1 == SPROUT_CHAR_LITERAL('L', CharType)
|
||||
&& SPROUT_CHAR_LITERAL('L', CharType) + 1 == SPROUT_CHAR_LITERAL('M', CharType)
|
||||
&& SPROUT_CHAR_LITERAL('M', CharType) + 1 == SPROUT_CHAR_LITERAL('N', CharType)
|
||||
&& SPROUT_CHAR_LITERAL('N', CharType) + 1 == SPROUT_CHAR_LITERAL('O', CharType)
|
||||
&& SPROUT_CHAR_LITERAL('O', CharType) + 1 == SPROUT_CHAR_LITERAL('P', CharType)
|
||||
&& SPROUT_CHAR_LITERAL('P', CharType) + 1 == SPROUT_CHAR_LITERAL('Q', CharType)
|
||||
&& SPROUT_CHAR_LITERAL('Q', CharType) + 1 == SPROUT_CHAR_LITERAL('R', CharType)
|
||||
&& SPROUT_CHAR_LITERAL('R', CharType) + 1 == SPROUT_CHAR_LITERAL('S', CharType)
|
||||
&& SPROUT_CHAR_LITERAL('S', CharType) + 1 == SPROUT_CHAR_LITERAL('T', CharType)
|
||||
&& SPROUT_CHAR_LITERAL('T', CharType) + 1 == SPROUT_CHAR_LITERAL('U', CharType)
|
||||
&& SPROUT_CHAR_LITERAL('U', CharType) + 1 == SPROUT_CHAR_LITERAL('V', CharType)
|
||||
&& SPROUT_CHAR_LITERAL('V', CharType) + 1 == SPROUT_CHAR_LITERAL('W', CharType)
|
||||
&& SPROUT_CHAR_LITERAL('W', CharType) + 1 == SPROUT_CHAR_LITERAL('X', CharType)
|
||||
&& SPROUT_CHAR_LITERAL('X', CharType) + 1 == SPROUT_CHAR_LITERAL('Y', CharType)
|
||||
&& SPROUT_CHAR_LITERAL('Y', CharType) + 1 == SPROUT_CHAR_LITERAL('Z', CharType)
|
||||
>
|
||||
{};
|
||||
template<typename CharType>
|
||||
struct is_char_type_of_consecutive_upper_alphabet<CharType const>
|
||||
: public sprout::detail::is_char_type_of_consecutive_upper_alphabet<CharType>
|
||||
{};
|
||||
template<typename CharType>
|
||||
struct is_char_type_of_consecutive_upper_alphabet<CharType volatile>
|
||||
: public sprout::detail::is_char_type_of_consecutive_upper_alphabet<CharType>
|
||||
{};
|
||||
template<typename CharType>
|
||||
struct is_char_type_of_consecutive_upper_alphabet<CharType const volatile>
|
||||
: public sprout::detail::is_char_type_of_consecutive_upper_alphabet<CharType>
|
||||
{};
|
||||
} // namespace detail
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_DETAIL_CHAR_TYPE_OF_CONSECUTIVE_HPP
|
|
@ -10,6 +10,7 @@
|
|||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/string.hpp>
|
||||
#include <sprout/type_traits/integral_constant.hpp>
|
||||
#include <sprout/preprocessor/cat.hpp>
|
||||
|
||||
//
|
||||
|
@ -69,10 +70,8 @@
|
|||
#endif
|
||||
#define SPROUT_LITERAL_CHAR_DEF_IMPL(NAME, CHAR, ELEM) \
|
||||
template<> \
|
||||
struct NAME<ELEM> { \
|
||||
public: \
|
||||
SPROUT_STATIC_CONSTEXPR ELEM value = CHAR; \
|
||||
}; \
|
||||
SPROUT_CONSTEXPR_OR_CONST ELEM NAME<ELEM>::value
|
||||
struct NAME<ELEM> \
|
||||
: public sprout::integral_constant<ELEM, CHAR> \
|
||||
{}
|
||||
|
||||
#endif // #ifndef SPROUT_DETAIL_LITERAL_DEF_HPP
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include <sprout/math/isnan.hpp>
|
||||
#include <sprout/math/signbit.hpp>
|
||||
#include <sprout/math/floor.hpp>
|
||||
#include <sprout/detail/char_literal.hpp>
|
||||
#include <sprout/detail/char_conversion.hpp>
|
||||
#include <sprout/detail/math/int.hpp>
|
||||
#include <sprout/detail/math/float.hpp>
|
||||
|
@ -49,9 +50,9 @@ namespace sprout {
|
|||
return negative
|
||||
? access_type::raw_construct(
|
||||
static_cast<std::size_t>(digits + 2 + sprout::detail::decimal_places_length),
|
||||
static_cast<Elem>('-'),
|
||||
SPROUT_CHAR_LITERAL('-', Elem),
|
||||
(Indexes < digits ? sprout::detail::int_to_char<Elem>(sprout::detail::float_digit_at(val, digits - 1 - Indexes))
|
||||
: Indexes == digits ? static_cast<Elem>('.')
|
||||
: Indexes == digits ? SPROUT_CHAR_LITERAL('.', Elem)
|
||||
: Indexes < digits + 1 + sprout::detail::decimal_places_length
|
||||
? sprout::detail::int_to_char<Elem>(sprout::detail::int_digit_at(v, digits + sprout::detail::decimal_places_length - Indexes))
|
||||
: Elem()
|
||||
|
@ -60,7 +61,7 @@ namespace sprout {
|
|||
: access_type::raw_construct(
|
||||
static_cast<std::size_t>(digits + 1 + sprout::detail::decimal_places_length),
|
||||
(Indexes < digits ? sprout::detail::int_to_char<Elem>(sprout::detail::float_digit_at(val, digits - 1 - Indexes))
|
||||
: Indexes == digits ? static_cast<Elem>('.')
|
||||
: Indexes == digits ? SPROUT_CHAR_LITERAL('.', Elem)
|
||||
: Indexes < digits + 1 + sprout::detail::decimal_places_length
|
||||
? sprout::detail::int_to_char<Elem>(sprout::detail::int_digit_at(v, digits + sprout::detail::decimal_places_length - Indexes))
|
||||
: Elem()
|
||||
|
@ -89,11 +90,11 @@ namespace sprout {
|
|||
float_to_string(FloatType val) {
|
||||
typedef sprout::detail::string_construct_access<Elem, sprout::printed_float_digits<FloatType>::value> access_type;
|
||||
return sprout::math::isinf(val) ? sprout::math::signbit(val)
|
||||
? access_type::raw_construct(4, static_cast<Elem>('-'), static_cast<Elem>('i'), static_cast<Elem>('n'), static_cast<Elem>('f'))
|
||||
: access_type::raw_construct(3, static_cast<Elem>('i'), static_cast<Elem>('n'), static_cast<Elem>('f'))
|
||||
? access_type::raw_construct(4, SPROUT_CHAR_LITERAL('-', Elem), SPROUT_CHAR_LITERAL('i', Elem), SPROUT_CHAR_LITERAL('n', Elem), SPROUT_CHAR_LITERAL('f', Elem))
|
||||
: access_type::raw_construct(3, SPROUT_CHAR_LITERAL('i', Elem), SPROUT_CHAR_LITERAL('n', Elem), SPROUT_CHAR_LITERAL('f', Elem))
|
||||
: sprout::math::isnan(val) ? sprout::math::signbit(val)
|
||||
? access_type::raw_construct(4, static_cast<Elem>('-'), static_cast<Elem>('n'), static_cast<Elem>('a'), static_cast<Elem>('n'))
|
||||
: access_type::raw_construct(3, static_cast<Elem>('n'), static_cast<Elem>('a'), static_cast<Elem>('n'))
|
||||
? access_type::raw_construct(4, SPROUT_CHAR_LITERAL('-', Elem), SPROUT_CHAR_LITERAL('n', Elem), SPROUT_CHAR_LITERAL('a', Elem), SPROUT_CHAR_LITERAL('n', Elem))
|
||||
: access_type::raw_construct(3, SPROUT_CHAR_LITERAL('n', Elem), SPROUT_CHAR_LITERAL('a', Elem), SPROUT_CHAR_LITERAL('n', Elem))
|
||||
: sprout::detail::float_to_string<Elem>(
|
||||
sprout::detail::float_round_at(val < 0 ? -val : val, sprout::detail::decimal_places_length),
|
||||
sprout::math::signbit(val),
|
||||
|
@ -131,13 +132,13 @@ namespace sprout {
|
|||
return negative
|
||||
? access_type::raw_construct(
|
||||
static_cast<std::size_t>(5 + sprout::detail::decimal_places_length + e10_digits),
|
||||
static_cast<Elem>('-'),
|
||||
SPROUT_CHAR_LITERAL('-', Elem),
|
||||
(Indexes == 0 ? sprout::detail::int_to_char<Elem>(sprout::detail::float_digit_at(val, 0))
|
||||
: Indexes == 1 ? static_cast<Elem>('.')
|
||||
: Indexes == 1 ? SPROUT_CHAR_LITERAL('.', Elem)
|
||||
: Indexes < 2 + sprout::detail::decimal_places_length
|
||||
? sprout::detail::int_to_char<Elem>(sprout::detail::float_digit_at(val, 1 - Indexes))
|
||||
: Indexes == 2 + sprout::detail::decimal_places_length ? static_cast<Elem>('e')
|
||||
: Indexes == 3 + sprout::detail::decimal_places_length ? static_cast<Elem>(exponent10 < 0 ? '-' : '+')
|
||||
: Indexes == 2 + sprout::detail::decimal_places_length ? SPROUT_CHAR_LITERAL('e', Elem)
|
||||
: Indexes == 3 + sprout::detail::decimal_places_length ? (exponent10 < 0 ? SPROUT_CHAR_LITERAL('-', Elem) : SPROUT_CHAR_LITERAL('+', Elem))
|
||||
: Indexes < 4 + sprout::detail::decimal_places_length + e10_digits
|
||||
? sprout::detail::int_to_char<Elem>(sprout::detail::int_digit_at(exponent10, 3 + sprout::detail::decimal_places_length + e10_digits - Indexes))
|
||||
: Elem()
|
||||
|
@ -146,11 +147,11 @@ namespace sprout {
|
|||
: access_type::raw_construct(
|
||||
static_cast<std::size_t>(4 + sprout::detail::decimal_places_length + e10_digits),
|
||||
(Indexes == 0 ? sprout::detail::int_to_char<Elem>(sprout::detail::float_digit_at(val, 0))
|
||||
: Indexes == 1 ? static_cast<Elem>('.')
|
||||
: Indexes == 1 ? SPROUT_CHAR_LITERAL('.', Elem)
|
||||
: Indexes < 2 + sprout::detail::decimal_places_length
|
||||
? sprout::detail::int_to_char<Elem>(sprout::detail::float_digit_at(val, 1 - Indexes))
|
||||
: Indexes == 2 + sprout::detail::decimal_places_length ? static_cast<Elem>('e')
|
||||
: Indexes == 3 + sprout::detail::decimal_places_length ? static_cast<Elem>(exponent10 < 0 ? '-' : '+')
|
||||
: Indexes == 2 + sprout::detail::decimal_places_length ? SPROUT_CHAR_LITERAL('e', Elem)
|
||||
: Indexes == 3 + sprout::detail::decimal_places_length ? (exponent10 < 0 ? SPROUT_CHAR_LITERAL('-', Elem) : SPROUT_CHAR_LITERAL('+', Elem))
|
||||
: Indexes < 4 + sprout::detail::decimal_places_length + e10_digits
|
||||
? sprout::detail::int_to_char<Elem>(sprout::detail::int_digit_at(exponent10, 3 + sprout::detail::decimal_places_length + e10_digits - Indexes))
|
||||
: Elem()
|
||||
|
@ -171,11 +172,11 @@ namespace sprout {
|
|||
float_to_string_exp(FloatType val) {
|
||||
typedef sprout::detail::string_construct_access<Elem, sprout::printed_float_exp_digits<FloatType>::value> access_type;
|
||||
return sprout::math::isinf(val) ? sprout::math::signbit(val)
|
||||
? access_type::raw_construct(4, static_cast<Elem>('-'), static_cast<Elem>('i'), static_cast<Elem>('n'), static_cast<Elem>('f'))
|
||||
: access_type::raw_construct(3, static_cast<Elem>('i'), static_cast<Elem>('n'), static_cast<Elem>('f'))
|
||||
? access_type::raw_construct(4, SPROUT_CHAR_LITERAL('-', Elem), SPROUT_CHAR_LITERAL('i', Elem), SPROUT_CHAR_LITERAL('n', Elem), SPROUT_CHAR_LITERAL('f', Elem))
|
||||
: access_type::raw_construct(3, SPROUT_CHAR_LITERAL('i', Elem), SPROUT_CHAR_LITERAL('n', Elem), SPROUT_CHAR_LITERAL('f', Elem))
|
||||
: sprout::math::isnan(val) ? sprout::math::signbit(val)
|
||||
? access_type::raw_construct(4, static_cast<Elem>('-'), static_cast<Elem>('n'), static_cast<Elem>('a'), static_cast<Elem>('n'))
|
||||
: access_type::raw_construct(3, static_cast<Elem>('n'), static_cast<Elem>('a'), static_cast<Elem>('n'))
|
||||
? access_type::raw_construct(4, SPROUT_CHAR_LITERAL('-', Elem), SPROUT_CHAR_LITERAL('n', Elem), SPROUT_CHAR_LITERAL('a', Elem), SPROUT_CHAR_LITERAL('n', Elem))
|
||||
: access_type::raw_construct(3, SPROUT_CHAR_LITERAL('n', Elem), SPROUT_CHAR_LITERAL('a', Elem), SPROUT_CHAR_LITERAL('n', Elem))
|
||||
: sprout::detail::float_to_string_exp<Elem>(
|
||||
sprout::detail::float_round_at(
|
||||
(val < 0 ? -val : val) / sprout::detail::float_pow10<FloatType>(sprout::detail::float_exponent10(val)),
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#include <sprout/integer/integer_digits.hpp>
|
||||
#include <sprout/type_traits/integral_constant.hpp>
|
||||
#include <sprout/type_traits/enabler_if.hpp>
|
||||
#include <sprout/detail/char_literal.hpp>
|
||||
#include <sprout/detail/char_conversion.hpp>
|
||||
#include <sprout/detail/math/int.hpp>
|
||||
|
||||
|
@ -42,7 +43,7 @@ namespace sprout {
|
|||
typedef sprout::detail::string_construct_access<Elem, sprout::printed_integer_digits<IntType, Base>::value> access_type;
|
||||
return val < 0 ? access_type::raw_construct(
|
||||
static_cast<std::size_t>(digits + 1),
|
||||
static_cast<Elem>('-'),
|
||||
SPROUT_CHAR_LITERAL('-', Elem),
|
||||
(Indexes < digits ? sprout::detail::int_to_char<Elem>(sprout::detail::int_digit_at<Base>(val, digits - 1 - Indexes))
|
||||
: Elem()
|
||||
)...
|
||||
|
|
|
@ -30,7 +30,7 @@ namespace sprout {
|
|||
static unsigned const value = 1;
|
||||
};
|
||||
#endif
|
||||
} // namespace detail
|
||||
} // namespace detail
|
||||
|
||||
//
|
||||
// print
|
||||
|
@ -65,7 +65,7 @@ namespace sprout {
|
|||
#elif defined(__MWERKS__)
|
||||
# pragma warn_hidevirtual reset
|
||||
#endif
|
||||
} // namespace types
|
||||
} // namespace sprout
|
||||
} // namespace types
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_TYPE_PRINT_HPP
|
||||
|
|
|
@ -15,25 +15,25 @@ namespace sprout {
|
|||
//
|
||||
// integral_constant
|
||||
//
|
||||
template<typename T, T v>
|
||||
template<typename T, T V>
|
||||
struct integral_constant
|
||||
: public std::integral_constant<T, v>
|
||||
: public std::integral_constant<T, V>
|
||||
{
|
||||
public:
|
||||
typedef typename std::integral_constant<T, v>::value_type value_type;
|
||||
typedef typename std::integral_constant<T, V>::value_type value_type;
|
||||
typedef integral_constant type;
|
||||
public:
|
||||
SPROUT_CONSTEXPR
|
||||
operator value_type() const SPROUT_NOEXCEPT {
|
||||
return std::integral_constant<T, v>::value;
|
||||
return std::integral_constant<T, V>::value;
|
||||
}
|
||||
SPROUT_CONSTEXPR bool
|
||||
operator!() const SPROUT_NOEXCEPT {
|
||||
return !std::integral_constant<T, v>::value;
|
||||
return !std::integral_constant<T, V>::value;
|
||||
}
|
||||
SPROUT_CONSTEXPR value_type
|
||||
operator()() const SPROUT_NOEXCEPT {
|
||||
return std::integral_constant<T, v>::value;
|
||||
return std::integral_constant<T, V>::value;
|
||||
}
|
||||
};
|
||||
//
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#include <sprout/iterator/operation.hpp>
|
||||
#include <sprout/iterator/type_traits/category.hpp>
|
||||
#include <sprout/utility/pair/pair.hpp>
|
||||
#include <sprout/detail/char_literal.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace weed {
|
||||
|
@ -27,7 +28,7 @@ namespace sprout {
|
|||
{
|
||||
return found != first ? found
|
||||
: pivot == 0 ? (
|
||||
*first == T('-') ? *sprout::prev(first) <= value && *sprout::next(first) >= value
|
||||
*first == SPROUT_CHAR_LITERAL('-', T) ? *sprout::prev(first) <= value && *sprout::next(first) >= value
|
||||
: *first == value
|
||||
) ? first : last
|
||||
: sprout::weed::detail::find_character_set_impl_ra(
|
||||
|
@ -66,7 +67,7 @@ namespace sprout {
|
|||
typedef sprout::pair<BidirectionalIterator, bool> type;
|
||||
return current.second || current.first == last ? current
|
||||
: n == 1 ? (
|
||||
*current.first == T('-') ? *sprout::prev(current.first) <= value && *sprout::next(current.first) >= value
|
||||
*current.first == SPROUT_CHAR_LITERAL('-', T) ? *sprout::prev(current.first) <= value && *sprout::next(current.first) >= value
|
||||
: *current.first == value
|
||||
) ? type(current.first, true) : type(sprout::next(current.first), false)
|
||||
: sprout::weed::detail::find_character_set_impl_1(
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
#include <sprout/weed/unused.hpp>
|
||||
#include <sprout/weed/parser_result.hpp>
|
||||
#include <sprout/weed/parser/parser_base.hpp>
|
||||
#include <sprout/detail/char_literal.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace weed {
|
||||
|
@ -45,13 +46,13 @@ namespace sprout {
|
|||
typedef typename attribute<Context, Iterator>::type attribute_type;
|
||||
typedef typename std::iterator_traits<Iterator>::value_type elem_type;
|
||||
return first != last
|
||||
? *first == elem_type('\r')
|
||||
? *first == SPROUT_CHAR_LITERAL('\r', elem_type)
|
||||
? sprout::next(first) != last
|
||||
? *sprout::next(first) == elem_type('\n')
|
||||
? *sprout::next(first) == SPROUT_CHAR_LITERAL('\n', elem_type)
|
||||
? result_type(true, sprout::next(sprout::next(first)), attribute_type())
|
||||
: result_type(true, sprout::next(first), attribute_type())
|
||||
: result_type(true, sprout::next(first), attribute_type())
|
||||
: *first == elem_type('\n')
|
||||
: *first == SPROUT_CHAR_LITERAL('\n', elem_type)
|
||||
? result_type(true, sprout::next(first), attribute_type())
|
||||
: result_type(false, first, attribute_type())
|
||||
: result_type(false, first, attribute_type())
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#include <sprout/weed/parser_result.hpp>
|
||||
#include <sprout/weed/parser/parser_base.hpp>
|
||||
#include <sprout/weed/detail/ndigits.hpp>
|
||||
#include <sprout/detail/char_literal.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace weed {
|
||||
|
@ -203,14 +204,14 @@ namespace sprout {
|
|||
typedef typename result<Context, Iterator>::type result_type;
|
||||
typedef typename attribute<Context, Iterator>::type attribute_type;
|
||||
return first != last
|
||||
? *first == elem_type('+')
|
||||
? *first == SPROUT_CHAR_LITERAL('+', elem_type)
|
||||
? call<Context>(
|
||||
sprout::next(first),
|
||||
last,
|
||||
first,
|
||||
1
|
||||
)
|
||||
: *first == elem_type('-')
|
||||
: *first == SPROUT_CHAR_LITERAL('-', elem_type)
|
||||
? call<Context>(
|
||||
sprout::next(first),
|
||||
last,
|
||||
|
|
Loading…
Reference in a new issue