mirror of
https://github.com/bolero-MURAKAMI/Sprout
synced 2024-11-12 21:09:01 +00:00
sprout/weed/parser/numeric/* 更新
This commit is contained in:
parent
34e2c4d45a
commit
ad94c0b247
11 changed files with 603 additions and 107 deletions
88
sprout/weed/detail/bdigits.hpp
Normal file
88
sprout/weed/detail/bdigits.hpp
Normal file
|
@ -0,0 +1,88 @@
|
|||
#ifndef SPROUT_WEED_DETAIL_BDIGITS_HPP
|
||||
#define SPROUT_WEED_DETAIL_BDIGITS_HPP
|
||||
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/string.hpp>
|
||||
#include <sprout/array.hpp>
|
||||
#include <sprout/tuple/tuple.hpp>
|
||||
#include HDR_ALGORITHM_SSCRISK_CEL_OR_SPROUT_DETAIL
|
||||
#include HDR_ITERATOR_SSCRISK_CEL_OR_SPROUT_DETAIL
|
||||
|
||||
namespace sprout {
|
||||
namespace weed {
|
||||
namespace detail {
|
||||
template<typename Elem>
|
||||
struct bdigits;
|
||||
|
||||
template<>
|
||||
struct bdigits<char> {
|
||||
public:
|
||||
SPROUT_STATIC_CONSTEXPR sprout::basic_string<char, 2> table = sprout::to_string("01");
|
||||
};
|
||||
SPROUT_CONSTEXPR sprout::basic_string<char, 2> sprout::weed::detail::bdigits<char>::table;
|
||||
|
||||
template<>
|
||||
struct bdigits<wchar_t> {
|
||||
public:
|
||||
SPROUT_STATIC_CONSTEXPR sprout::basic_string<wchar_t, 2> table = sprout::to_string(L"01");
|
||||
};
|
||||
SPROUT_CONSTEXPR sprout::basic_string<wchar_t, 2> sprout::weed::detail::bdigits<wchar_t>::table;
|
||||
|
||||
template<>
|
||||
struct bdigits<char16_t> {
|
||||
public:
|
||||
SPROUT_STATIC_CONSTEXPR sprout::basic_string<char16_t, 2> table = sprout::to_string(u"01");
|
||||
};
|
||||
SPROUT_CONSTEXPR sprout::basic_string<char16_t, 2> sprout::weed::detail::bdigits<char16_t>::table;
|
||||
|
||||
template<>
|
||||
struct bdigits<char32_t> {
|
||||
public:
|
||||
SPROUT_STATIC_CONSTEXPR sprout::basic_string<char32_t, 2> table = sprout::to_string(U"01");
|
||||
};
|
||||
SPROUT_CONSTEXPR sprout::basic_string<char32_t, 2> sprout::weed::detail::bdigits<char32_t>::table;
|
||||
|
||||
template<typename Dummy>
|
||||
struct bvalues;
|
||||
|
||||
template<>
|
||||
struct bvalues<void> {
|
||||
public:
|
||||
SPROUT_STATIC_CONSTEXPR sprout::array<std::uint8_t, 2> table = sprout::array<std::uint8_t, 2>{
|
||||
{0, 1}
|
||||
};
|
||||
};
|
||||
SPROUT_CONSTEXPR sprout::array<std::uint8_t, 2> sprout::weed::detail::bvalues<void>::table;
|
||||
|
||||
template<typename IntType>
|
||||
SPROUT_CONSTEXPR sprout::tuples::tuple<IntType, bool> bvalue_at(std::size_t i) {
|
||||
return i < 2
|
||||
? sprout::tuples::tuple<IntType, bool>(
|
||||
static_cast<IntType>(sprout::weed::detail::bvalues<void>::table[i]),
|
||||
true
|
||||
)
|
||||
: sprout::tuples::tuple<IntType, bool>(
|
||||
IntType(),
|
||||
false
|
||||
)
|
||||
;
|
||||
}
|
||||
template<typename IntType, typename Elem>
|
||||
SPROUT_CONSTEXPR sprout::tuples::tuple<IntType, bool> from_bdigit(Elem c) {
|
||||
return sprout::weed::detail::bvalue_at<IntType>(
|
||||
NS_SSCRISK_CEL_OR_SPROUT_DETAIL::distance(
|
||||
sprout::weed::detail::bdigits<Elem>::table.begin(),
|
||||
NS_SSCRISK_CEL_OR_SPROUT_DETAIL::find(
|
||||
sprout::weed::detail::bdigits<Elem>::table.begin(),
|
||||
sprout::weed::detail::bdigits<Elem>::table.end(),
|
||||
c
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
} // namespace detail
|
||||
} // namespace weed
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_WEED_DETAIL_BDIGITS_HPP
|
88
sprout/weed/detail/digits.hpp
Normal file
88
sprout/weed/detail/digits.hpp
Normal file
|
@ -0,0 +1,88 @@
|
|||
#ifndef SPROUT_WEED_DETAIL_DIGITS_HPP
|
||||
#define SPROUT_WEED_DETAIL_DIGITS_HPP
|
||||
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/string.hpp>
|
||||
#include <sprout/array.hpp>
|
||||
#include <sprout/tuple/tuple.hpp>
|
||||
#include HDR_ALGORITHM_SSCRISK_CEL_OR_SPROUT_DETAIL
|
||||
#include HDR_ITERATOR_SSCRISK_CEL_OR_SPROUT_DETAIL
|
||||
|
||||
namespace sprout {
|
||||
namespace weed {
|
||||
namespace detail {
|
||||
template<typename Elem>
|
||||
struct digits;
|
||||
|
||||
template<>
|
||||
struct digits<char> {
|
||||
public:
|
||||
SPROUT_STATIC_CONSTEXPR sprout::basic_string<char, 10> table = sprout::to_string("0123456789");
|
||||
};
|
||||
SPROUT_CONSTEXPR sprout::basic_string<char, 10> sprout::weed::detail::digits<char>::table;
|
||||
|
||||
template<>
|
||||
struct digits<wchar_t> {
|
||||
public:
|
||||
SPROUT_STATIC_CONSTEXPR sprout::basic_string<wchar_t, 10> table = sprout::to_string(L"0123456789");
|
||||
};
|
||||
SPROUT_CONSTEXPR sprout::basic_string<wchar_t, 10> sprout::weed::detail::digits<wchar_t>::table;
|
||||
|
||||
template<>
|
||||
struct digits<char16_t> {
|
||||
public:
|
||||
SPROUT_STATIC_CONSTEXPR sprout::basic_string<char16_t, 10> table = sprout::to_string(u"0123456789");
|
||||
};
|
||||
SPROUT_CONSTEXPR sprout::basic_string<char16_t, 10> sprout::weed::detail::digits<char16_t>::table;
|
||||
|
||||
template<>
|
||||
struct digits<char32_t> {
|
||||
public:
|
||||
SPROUT_STATIC_CONSTEXPR sprout::basic_string<char32_t, 10> table = sprout::to_string(U"0123456789");
|
||||
};
|
||||
SPROUT_CONSTEXPR sprout::basic_string<char32_t, 10> sprout::weed::detail::digits<char32_t>::table;
|
||||
|
||||
template<typename Dummy>
|
||||
struct values;
|
||||
|
||||
template<>
|
||||
struct values<void> {
|
||||
public:
|
||||
SPROUT_STATIC_CONSTEXPR sprout::array<std::uint8_t, 10> table = sprout::array<std::uint8_t, 10>{
|
||||
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
|
||||
};
|
||||
};
|
||||
SPROUT_CONSTEXPR sprout::array<std::uint8_t, 10> sprout::weed::detail::values<void>::table;
|
||||
|
||||
template<typename IntType>
|
||||
SPROUT_CONSTEXPR sprout::tuples::tuple<IntType, bool> value_at(std::size_t i) {
|
||||
return i < 10
|
||||
? sprout::tuples::tuple<IntType, bool>(
|
||||
static_cast<IntType>(sprout::weed::detail::values<void>::table[i]),
|
||||
true
|
||||
)
|
||||
: sprout::tuples::tuple<IntType, bool>(
|
||||
IntType(),
|
||||
false
|
||||
)
|
||||
;
|
||||
}
|
||||
template<typename IntType, typename Elem>
|
||||
SPROUT_CONSTEXPR sprout::tuples::tuple<IntType, bool> from_digit(Elem c) {
|
||||
return sprout::weed::detail::value_at<IntType>(
|
||||
NS_SSCRISK_CEL_OR_SPROUT_DETAIL::distance(
|
||||
sprout::weed::detail::digits<Elem>::table.begin(),
|
||||
NS_SSCRISK_CEL_OR_SPROUT_DETAIL::find(
|
||||
sprout::weed::detail::digits<Elem>::table.begin(),
|
||||
sprout::weed::detail::digits<Elem>::table.end(),
|
||||
c
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
} // namespace detail
|
||||
} // namespace weed
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_WEED_DETAIL_DIGITS_HPP
|
52
sprout/weed/detail/ndigits.hpp
Normal file
52
sprout/weed/detail/ndigits.hpp
Normal file
|
@ -0,0 +1,52 @@
|
|||
#ifndef SPROUT_WEED_DETAIL_NDIGITS_HPP
|
||||
#define SPROUT_WEED_DETAIL_NDIGITS_HPP
|
||||
|
||||
#include <cstddef>
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/tuple/tuple.hpp>
|
||||
#include <sprout/weed/detail/digits.hpp>
|
||||
#include <sprout/weed/detail/bdigits.hpp>
|
||||
#include <sprout/weed/detail/odigits.hpp>
|
||||
#include <sprout/weed/detail/xdigits.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace weed {
|
||||
namespace detail {
|
||||
template<std::size_t Radix, typename IntType, typename Elem>
|
||||
SPROUT_CONSTEXPR sprout::tuples::tuple<IntType, bool> from_ndigit(
|
||||
Elem c,
|
||||
typename std::enable_if<Radix == 10>::type* = 0
|
||||
)
|
||||
{
|
||||
return sprout::weed::detail::from_digit<IntType>(c);
|
||||
}
|
||||
template<std::size_t Radix, typename IntType, typename Elem>
|
||||
SPROUT_CONSTEXPR sprout::tuples::tuple<IntType, bool> from_ndigit(
|
||||
Elem c,
|
||||
typename std::enable_if<Radix == 2>::type* = 0
|
||||
)
|
||||
{
|
||||
return sprout::weed::detail::from_bdigit<IntType>(c);
|
||||
}
|
||||
template<std::size_t Radix, typename IntType, typename Elem>
|
||||
SPROUT_CONSTEXPR sprout::tuples::tuple<IntType, bool> from_ndigit(
|
||||
Elem c,
|
||||
typename std::enable_if<Radix == 8>::type* = 0
|
||||
)
|
||||
{
|
||||
return sprout::weed::detail::from_odigit<IntType>(c);
|
||||
}
|
||||
template<std::size_t Radix, typename IntType, typename Elem>
|
||||
SPROUT_CONSTEXPR sprout::tuples::tuple<IntType, bool> from_ndigit(
|
||||
Elem c,
|
||||
typename std::enable_if<Radix == 16>::type* = 0
|
||||
)
|
||||
{
|
||||
return sprout::weed::detail::from_xdigit<IntType>(c);
|
||||
}
|
||||
} // namespace detail
|
||||
} // namespace weed
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_WEED_DETAIL_NDIGITS_HPP
|
88
sprout/weed/detail/odigits.hpp
Normal file
88
sprout/weed/detail/odigits.hpp
Normal file
|
@ -0,0 +1,88 @@
|
|||
#ifndef SPROUT_WEED_DETAIL_ODIGITS_HPP
|
||||
#define SPROUT_WEED_DETAIL_ODIGITS_HPP
|
||||
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/string.hpp>
|
||||
#include <sprout/array.hpp>
|
||||
#include <sprout/tuple/tuple.hpp>
|
||||
#include HDR_ALGORITHM_SSCRISK_CEL_OR_SPROUT_DETAIL
|
||||
#include HDR_ITERATOR_SSCRISK_CEL_OR_SPROUT_DETAIL
|
||||
|
||||
namespace sprout {
|
||||
namespace weed {
|
||||
namespace detail {
|
||||
template<typename Elem>
|
||||
struct odigits;
|
||||
|
||||
template<>
|
||||
struct odigits<char> {
|
||||
public:
|
||||
SPROUT_STATIC_CONSTEXPR sprout::basic_string<char, 8> table = sprout::to_string("01234567");
|
||||
};
|
||||
SPROUT_CONSTEXPR sprout::basic_string<char, 8> sprout::weed::detail::odigits<char>::table;
|
||||
|
||||
template<>
|
||||
struct odigits<wchar_t> {
|
||||
public:
|
||||
SPROUT_STATIC_CONSTEXPR sprout::basic_string<wchar_t, 8> table = sprout::to_string(L"01234567");
|
||||
};
|
||||
SPROUT_CONSTEXPR sprout::basic_string<wchar_t, 8> sprout::weed::detail::odigits<wchar_t>::table;
|
||||
|
||||
template<>
|
||||
struct odigits<char16_t> {
|
||||
public:
|
||||
SPROUT_STATIC_CONSTEXPR sprout::basic_string<char16_t, 8> table = sprout::to_string(u"01234567");
|
||||
};
|
||||
SPROUT_CONSTEXPR sprout::basic_string<char16_t, 8> sprout::weed::detail::odigits<char16_t>::table;
|
||||
|
||||
template<>
|
||||
struct odigits<char32_t> {
|
||||
public:
|
||||
SPROUT_STATIC_CONSTEXPR sprout::basic_string<char32_t, 8> table = sprout::to_string(U"01234567");
|
||||
};
|
||||
SPROUT_CONSTEXPR sprout::basic_string<char32_t, 8> sprout::weed::detail::odigits<char32_t>::table;
|
||||
|
||||
template<typename Dummy>
|
||||
struct ovalues;
|
||||
|
||||
template<>
|
||||
struct ovalues<void> {
|
||||
public:
|
||||
SPROUT_STATIC_CONSTEXPR sprout::array<std::uint8_t, 8> table = sprout::array<std::uint8_t, 8>{
|
||||
{0, 1, 2, 3, 4, 5, 6, 7}
|
||||
};
|
||||
};
|
||||
SPROUT_CONSTEXPR sprout::array<std::uint8_t, 8> sprout::weed::detail::ovalues<void>::table;
|
||||
|
||||
template<typename IntType>
|
||||
SPROUT_CONSTEXPR sprout::tuples::tuple<IntType, bool> ovalue_at(std::size_t i) {
|
||||
return i < 8
|
||||
? sprout::tuples::tuple<IntType, bool>(
|
||||
static_cast<IntType>(sprout::weed::detail::ovalues<void>::table[i]),
|
||||
true
|
||||
)
|
||||
: sprout::tuples::tuple<IntType, bool>(
|
||||
IntType(),
|
||||
false
|
||||
)
|
||||
;
|
||||
}
|
||||
template<typename IntType, typename Elem>
|
||||
SPROUT_CONSTEXPR sprout::tuples::tuple<IntType, bool> from_odigit(Elem c) {
|
||||
return sprout::weed::detail::ovalue_at<IntType>(
|
||||
NS_SSCRISK_CEL_OR_SPROUT_DETAIL::distance(
|
||||
sprout::weed::detail::odigits<Elem>::table.begin(),
|
||||
NS_SSCRISK_CEL_OR_SPROUT_DETAIL::find(
|
||||
sprout::weed::detail::odigits<Elem>::table.begin(),
|
||||
sprout::weed::detail::odigits<Elem>::table.end(),
|
||||
c
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
} // namespace detail
|
||||
} // namespace weed
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_WEED_DETAIL_ODIGITS_HPP
|
|
@ -6,6 +6,8 @@
|
|||
#include <sprout/string.hpp>
|
||||
#include <sprout/array.hpp>
|
||||
#include <sprout/tuple/tuple.hpp>
|
||||
#include HDR_ALGORITHM_SSCRISK_CEL_OR_SPROUT_DETAIL
|
||||
#include HDR_ITERATOR_SSCRISK_CEL_OR_SPROUT_DETAIL
|
||||
|
||||
namespace sprout {
|
||||
namespace weed {
|
||||
|
|
|
@ -2,6 +2,10 @@
|
|||
#define SPROUT_WEED_PARSER_NUMERIC_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/weed/parser/numeric/uint_p.hpp>
|
||||
#include <sprout/weed/parser/numeric/uint.hpp>
|
||||
#include <sprout/weed/parser/numeric/bin.hpp>
|
||||
#include <sprout/weed/parser/numeric/oct.hpp>
|
||||
#include <sprout/weed/parser/numeric/hex.hpp>
|
||||
|
||||
#endif // #ifndef SPROUT_WEED_PARSER_NUMERIC_HPP
|
||||
|
|
40
sprout/weed/parser/numeric/bin.hpp
Normal file
40
sprout/weed/parser/numeric/bin.hpp
Normal file
|
@ -0,0 +1,40 @@
|
|||
#ifndef SPROUT_WEED_PARSER_NUMERIC_BIN_HPP
|
||||
#define SPROUT_WEED_PARSER_NUMERIC_BIN_HPP
|
||||
|
||||
#include <cstdint>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/integer/integer_digits.hpp>
|
||||
#include <sprout/weed/parser/numeric/uint_p.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace weed {
|
||||
//
|
||||
// bin
|
||||
//
|
||||
SPROUT_STATIC_CONSTEXPR auto bin = sprout::weed::uint_p<std::uintmax_t, 2, -1>();
|
||||
|
||||
//
|
||||
// bin8
|
||||
// bin16
|
||||
// bin32
|
||||
// bin64
|
||||
//
|
||||
SPROUT_STATIC_CONSTEXPR auto bin8 = sprout::weed::uint_p<std::uint8_t, 2>();
|
||||
SPROUT_STATIC_CONSTEXPR auto bin16 = sprout::weed::uint_p<std::uint16_t, 2>();
|
||||
SPROUT_STATIC_CONSTEXPR auto bin32 = sprout::weed::uint_p<std::uint32_t, 2>();
|
||||
SPROUT_STATIC_CONSTEXPR auto bin64 = sprout::weed::uint_p<std::uint64_t, 2>();
|
||||
|
||||
//
|
||||
// bin8f
|
||||
// bin16f
|
||||
// bin32f
|
||||
// bin64f
|
||||
//
|
||||
SPROUT_STATIC_CONSTEXPR auto bin8f = sprout::weed::uint_p<std::uint8_t, 2, sprout::integer_digits<std::uint8_t, 2>::value>();
|
||||
SPROUT_STATIC_CONSTEXPR auto bin16f = sprout::weed::uint_p<std::uint16_t, 2, sprout::integer_digits<std::uint16_t, 2>::value>();
|
||||
SPROUT_STATIC_CONSTEXPR auto bin32f = sprout::weed::uint_p<std::uint32_t, 2, sprout::integer_digits<std::uint32_t, 2>::value>();
|
||||
SPROUT_STATIC_CONSTEXPR auto bin64f = sprout::weed::uint_p<std::uint64_t, 2, sprout::integer_digits<std::uint64_t, 2>::value>();
|
||||
} // namespace weed
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_WEED_PARSER_NUMERIC_BIN_HPP
|
|
@ -1,131 +1,39 @@
|
|||
#ifndef SPROUT_WEED_PARSER_NUMERIC_HEX_HPP
|
||||
#define SPROUT_WEED_PARSER_NUMERIC_HEX_HPP
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/iterator/next.hpp>
|
||||
#include <sprout/tuple/tuple.hpp>
|
||||
#include <sprout/weed/unused.hpp>
|
||||
#include <sprout/weed/parser_result.hpp>
|
||||
#include <sprout/weed/parser/parser_base.hpp>
|
||||
#include <sprout/weed/detail/xdigits.hpp>
|
||||
#include <sprout/integer/integer_digits.hpp>
|
||||
#include <sprout/weed/parser/numeric/uint_p.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace weed {
|
||||
//
|
||||
// hex_p
|
||||
// hex
|
||||
//
|
||||
template<typename IntType, std::size_t Min = sizeof(IntType) * 2, std::size_t Max = sizeof(IntType) * 2>
|
||||
struct hex_p
|
||||
: public sprout::weed::parser_base
|
||||
{
|
||||
public:
|
||||
template<typename Context, typename Iterator>
|
||||
struct attribute {
|
||||
public:
|
||||
typedef IntType type;
|
||||
};
|
||||
template<typename Context, typename Iterator>
|
||||
struct result {
|
||||
public:
|
||||
typedef sprout::weed::parser_result<Iterator, typename attribute<Context, Iterator>::type> type;
|
||||
};
|
||||
private:
|
||||
template<std::size_t N, typename Context, typename Iterator, typename PResult>
|
||||
SPROUT_CONSTEXPR typename std::enable_if<
|
||||
N == Max,
|
||||
typename result<Context, Iterator>::type
|
||||
>::type call_1(Iterator first, Iterator last, Iterator temp_first, IntType t, PResult const& res) const {
|
||||
typedef typename result<Context, Iterator>::type result_type;
|
||||
typedef typename attribute<Context, Iterator>::type attribute_type;
|
||||
return sprout::tuples::get<1>(res)
|
||||
? result_type(true, sprout::next(first), static_cast<IntType>(t << 4 | sprout::tuples::get<0>(res)))
|
||||
: N < Min
|
||||
? result_type(false, temp_first, attribute_type())
|
||||
: result_type(true, first, t)
|
||||
;
|
||||
}
|
||||
template<std::size_t N, typename Context, typename Iterator, typename PResult>
|
||||
SPROUT_CONSTEXPR typename std::enable_if<
|
||||
N != Max,
|
||||
typename result<Context, Iterator>::type
|
||||
>::type call_1(Iterator first, Iterator last, Iterator temp_first, IntType t, PResult const& res) const {
|
||||
typedef typename result<Context, Iterator>::type result_type;
|
||||
typedef typename attribute<Context, Iterator>::type attribute_type;
|
||||
return sprout::tuples::get<1>(res)
|
||||
? call_0<N, Context>(sprout::next(first), last, temp_first, static_cast<IntType>(t << 4 | sprout::tuples::get<0>(res)))
|
||||
: N < Min
|
||||
? result_type(false, temp_first, attribute_type())
|
||||
: result_type(true, first, t)
|
||||
;
|
||||
}
|
||||
template<std::size_t N, typename Context, typename Iterator>
|
||||
SPROUT_CONSTEXPR typename result<Context, Iterator>::type call_0(Iterator first, Iterator last, Iterator temp_first, IntType t) const {
|
||||
typedef typename result<Context, Iterator>::type result_type;
|
||||
typedef typename attribute<Context, Iterator>::type attribute_type;
|
||||
return first != last
|
||||
? call_1<N + 1, Context>(first, last, temp_first, t, sprout::weed::detail::from_xdigit<IntType>(*first))
|
||||
: N < Min
|
||||
? result_type(false, temp_first, attribute_type())
|
||||
: result_type(true, first, t)
|
||||
;
|
||||
}
|
||||
template<typename Context, typename Iterator, typename PResult>
|
||||
SPROUT_CONSTEXPR typename result<Context, Iterator>::type call(Iterator first, Iterator last, Iterator temp_first, PResult const& res) const {
|
||||
typedef typename result<Context, Iterator>::type result_type;
|
||||
typedef typename attribute<Context, Iterator>::type attribute_type;
|
||||
return sprout::tuples::get<1>(res)
|
||||
? call_0<1, Context>(sprout::next(first), last, temp_first, sprout::tuples::get<0>(res))
|
||||
: result_type(false, temp_first, attribute_type())
|
||||
;
|
||||
}
|
||||
public:
|
||||
template<typename Context, typename Iterator>
|
||||
SPROUT_CONSTEXPR typename result<Context, Iterator>::type operator()(Iterator first, Iterator last, Context const&) const {
|
||||
typedef typename result<Context, Iterator>::type result_type;
|
||||
typedef typename attribute<Context, Iterator>::type attribute_type;
|
||||
return first != last
|
||||
? call<Context>(first, last, first, sprout::weed::detail::from_xdigit<IntType>(*first))
|
||||
: result_type(false, first, attribute_type())
|
||||
;
|
||||
}
|
||||
};
|
||||
SPROUT_STATIC_CONSTEXPR auto hex = sprout::weed::uint_p<std::uintmax_t, 16, -1>();
|
||||
|
||||
//
|
||||
// hex8
|
||||
// hex16
|
||||
// hex32
|
||||
// hex64
|
||||
// uhex8
|
||||
// uhex16
|
||||
// uhex32
|
||||
// uhex64
|
||||
//
|
||||
SPROUT_STATIC_CONSTEXPR sprout::weed::hex_p<std::int8_t, 1> hex8 = sprout::weed::hex_p<std::int8_t, 1>();
|
||||
SPROUT_STATIC_CONSTEXPR sprout::weed::hex_p<std::int16_t, 1> hex16 = sprout::weed::hex_p<std::int16_t, 1>();
|
||||
SPROUT_STATIC_CONSTEXPR sprout::weed::hex_p<std::int32_t, 1> hex32 = sprout::weed::hex_p<std::int32_t, 1>();
|
||||
SPROUT_STATIC_CONSTEXPR sprout::weed::hex_p<std::int64_t, 1> hex64 = sprout::weed::hex_p<std::int64_t, 1>();
|
||||
SPROUT_STATIC_CONSTEXPR sprout::weed::hex_p<std::uint8_t, 1> uhex8 = sprout::weed::hex_p<std::uint8_t, 1>();
|
||||
SPROUT_STATIC_CONSTEXPR sprout::weed::hex_p<std::uint16_t, 1> uhex16 = sprout::weed::hex_p<std::uint16_t, 1>();
|
||||
SPROUT_STATIC_CONSTEXPR sprout::weed::hex_p<std::uint32_t, 1> uhex32 = sprout::weed::hex_p<std::uint32_t, 1>();
|
||||
SPROUT_STATIC_CONSTEXPR sprout::weed::hex_p<std::uint64_t, 1> uhex64 = sprout::weed::hex_p<std::uint64_t, 1>();
|
||||
SPROUT_STATIC_CONSTEXPR auto hex8 = sprout::weed::uint_p<std::uint8_t, 16>();
|
||||
SPROUT_STATIC_CONSTEXPR auto hex16 = sprout::weed::uint_p<std::uint16_t, 16>();
|
||||
SPROUT_STATIC_CONSTEXPR auto hex32 = sprout::weed::uint_p<std::uint32_t, 16>();
|
||||
SPROUT_STATIC_CONSTEXPR auto hex64 = sprout::weed::uint_p<std::uint64_t, 16>();
|
||||
|
||||
//
|
||||
// hex8f
|
||||
// hex16f
|
||||
// hex32f
|
||||
// hex64f
|
||||
// uhex8f
|
||||
// uhex16f
|
||||
// uhex32f
|
||||
// uhex64f
|
||||
//
|
||||
SPROUT_STATIC_CONSTEXPR sprout::weed::hex_p<std::int8_t> hex8f = sprout::weed::hex_p<std::int8_t>();
|
||||
SPROUT_STATIC_CONSTEXPR sprout::weed::hex_p<std::int16_t> hex16f = sprout::weed::hex_p<std::int16_t>();
|
||||
SPROUT_STATIC_CONSTEXPR sprout::weed::hex_p<std::int32_t> hex32f = sprout::weed::hex_p<std::int32_t>();
|
||||
SPROUT_STATIC_CONSTEXPR sprout::weed::hex_p<std::int64_t> hex64f = sprout::weed::hex_p<std::int64_t>();
|
||||
SPROUT_STATIC_CONSTEXPR sprout::weed::hex_p<std::uint8_t> uhex8f = sprout::weed::hex_p<std::uint8_t>();
|
||||
SPROUT_STATIC_CONSTEXPR sprout::weed::hex_p<std::uint16_t> uhex16f = sprout::weed::hex_p<std::uint16_t>();
|
||||
SPROUT_STATIC_CONSTEXPR sprout::weed::hex_p<std::uint32_t> uhex32f = sprout::weed::hex_p<std::uint32_t>();
|
||||
SPROUT_STATIC_CONSTEXPR sprout::weed::hex_p<std::uint64_t> uhex64f = sprout::weed::hex_p<std::uint64_t>();
|
||||
SPROUT_STATIC_CONSTEXPR auto hex8f = sprout::weed::uint_p<std::uint8_t, 16, sprout::integer_digits<std::uint8_t, 16>::value>();
|
||||
SPROUT_STATIC_CONSTEXPR auto hex16f = sprout::weed::uint_p<std::uint16_t, 16, sprout::integer_digits<std::uint16_t, 16>::value>();
|
||||
SPROUT_STATIC_CONSTEXPR auto hex32f = sprout::weed::uint_p<std::uint32_t, 16, sprout::integer_digits<std::uint32_t, 16>::value>();
|
||||
SPROUT_STATIC_CONSTEXPR auto hex64f = sprout::weed::uint_p<std::uint64_t, 16, sprout::integer_digits<std::uint64_t, 16>::value>();
|
||||
} // namespace weed
|
||||
} // namespace sprout
|
||||
|
||||
|
|
40
sprout/weed/parser/numeric/oct.hpp
Normal file
40
sprout/weed/parser/numeric/oct.hpp
Normal file
|
@ -0,0 +1,40 @@
|
|||
#ifndef SPROUT_WEED_PARSER_NUMERIC_OCT_HPP
|
||||
#define SPROUT_WEED_PARSER_NUMERIC_OCT_HPP
|
||||
|
||||
#include <cstdint>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/integer/integer_digits.hpp>
|
||||
#include <sprout/weed/parser/numeric/uint_p.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace weed {
|
||||
//
|
||||
// oct
|
||||
//
|
||||
SPROUT_STATIC_CONSTEXPR auto oct = sprout::weed::uint_p<std::uintmax_t, 8, -1>();
|
||||
|
||||
//
|
||||
// oct8
|
||||
// oct16
|
||||
// oct32
|
||||
// oct64
|
||||
//
|
||||
SPROUT_STATIC_CONSTEXPR auto oct8 = sprout::weed::uint_p<std::uint8_t, 8>();
|
||||
SPROUT_STATIC_CONSTEXPR auto oct16 = sprout::weed::uint_p<std::uint16_t, 8>();
|
||||
SPROUT_STATIC_CONSTEXPR auto oct32 = sprout::weed::uint_p<std::uint32_t, 8>();
|
||||
SPROUT_STATIC_CONSTEXPR auto oct64 = sprout::weed::uint_p<std::uint64_t, 8>();
|
||||
|
||||
//
|
||||
// oct8f
|
||||
// oct16f
|
||||
// oct32f
|
||||
// oct64f
|
||||
//
|
||||
SPROUT_STATIC_CONSTEXPR auto oct8f = sprout::weed::uint_p<std::uint8_t, 8, sprout::integer_digits<std::uint8_t, 8>::value>();
|
||||
SPROUT_STATIC_CONSTEXPR auto oct16f = sprout::weed::uint_p<std::uint16_t, 8, sprout::integer_digits<std::uint16_t, 8>::value>();
|
||||
SPROUT_STATIC_CONSTEXPR auto oct32f = sprout::weed::uint_p<std::uint32_t, 8, sprout::integer_digits<std::uint32_t, 8>::value>();
|
||||
SPROUT_STATIC_CONSTEXPR auto oct64f = sprout::weed::uint_p<std::uint64_t, 8, sprout::integer_digits<std::uint64_t, 8>::value>();
|
||||
} // namespace weed
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_WEED_PARSER_NUMERIC_OCT_HPP
|
29
sprout/weed/parser/numeric/uint.hpp
Normal file
29
sprout/weed/parser/numeric/uint.hpp
Normal file
|
@ -0,0 +1,29 @@
|
|||
#ifndef SPROUT_WEED_PARSER_NUMERIC_UINT_HPP
|
||||
#define SPROUT_WEED_PARSER_NUMERIC_UINT_HPP
|
||||
|
||||
#include <cstdint>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/integer/integer_digits.hpp>
|
||||
#include <sprout/weed/parser/numeric/uint_p.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace weed {
|
||||
//
|
||||
// uint
|
||||
//
|
||||
SPROUT_STATIC_CONSTEXPR auto uint = sprout::weed::uint_p<std::uintmax_t, 10, -1>();
|
||||
|
||||
//
|
||||
// uint8
|
||||
// uint16
|
||||
// uint32
|
||||
// uint64
|
||||
//
|
||||
SPROUT_STATIC_CONSTEXPR auto uint8 = sprout::weed::uint_p<std::uint8_t, 10>();
|
||||
SPROUT_STATIC_CONSTEXPR auto uint16 = sprout::weed::uint_p<std::uint16_t, 10>();
|
||||
SPROUT_STATIC_CONSTEXPR auto uint32 = sprout::weed::uint_p<std::uint32_t, 10>();
|
||||
SPROUT_STATIC_CONSTEXPR auto uint64 = sprout::weed::uint_p<std::uint64_t, 10>();
|
||||
} // namespace weed
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_WEED_PARSER_NUMERIC_UINT_HPP
|
157
sprout/weed/parser/numeric/uint_p.hpp
Normal file
157
sprout/weed/parser/numeric/uint_p.hpp
Normal file
|
@ -0,0 +1,157 @@
|
|||
#ifndef SPROUT_WEED_PARSER_NUMERIC_UINT_P_HPP
|
||||
#define SPROUT_WEED_PARSER_NUMERIC_UINT_P_HPP
|
||||
|
||||
#include <cstddef>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/iterator/next.hpp>
|
||||
#include <sprout/tuple/tuple.hpp>
|
||||
#include <sprout/integer/integer_digits.hpp>
|
||||
#include <sprout/weed/unused.hpp>
|
||||
#include <sprout/weed/parser_result.hpp>
|
||||
#include <sprout/weed/parser/parser_base.hpp>
|
||||
#include <sprout/weed/detail/ndigits.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace weed {
|
||||
//
|
||||
// uint_p
|
||||
//
|
||||
template<
|
||||
typename IntType,
|
||||
std::size_t Radix,
|
||||
std::size_t MinDigits = 1,
|
||||
std::size_t MaxDigits = sprout::integer_digits<IntType, Radix>::value
|
||||
>
|
||||
struct uint_p
|
||||
: public sprout::weed::parser_base
|
||||
{
|
||||
public:
|
||||
template<typename Context, typename Iterator>
|
||||
struct attribute {
|
||||
public:
|
||||
typedef IntType type;
|
||||
};
|
||||
template<typename Context, typename Iterator>
|
||||
struct result {
|
||||
public:
|
||||
typedef sprout::weed::parser_result<Iterator, typename attribute<Context, Iterator>::type> type;
|
||||
};
|
||||
private:
|
||||
template<std::size_t N, typename Context, typename Iterator, typename PResult>
|
||||
SPROUT_CONSTEXPR typename std::enable_if<
|
||||
N == MaxDigits,
|
||||
typename result<Context, Iterator>::type
|
||||
>::type call_1(
|
||||
Iterator first,
|
||||
Iterator last,
|
||||
Iterator temp_first,
|
||||
IntType t,
|
||||
PResult const& res
|
||||
) const
|
||||
{
|
||||
typedef typename result<Context, Iterator>::type result_type;
|
||||
typedef typename attribute<Context, Iterator>::type attribute_type;
|
||||
return sprout::tuples::get<1>(res)
|
||||
? result_type(
|
||||
true,
|
||||
sprout::next(first),
|
||||
static_cast<IntType>(t * Radix | sprout::tuples::get<0>(res))
|
||||
)
|
||||
: N < MinDigits
|
||||
? result_type(false, temp_first, attribute_type())
|
||||
: result_type(true, first, t)
|
||||
;
|
||||
}
|
||||
template<std::size_t N, typename Context, typename Iterator, typename PResult>
|
||||
SPROUT_CONSTEXPR typename std::enable_if<
|
||||
N != MaxDigits,
|
||||
typename result<Context, Iterator>::type
|
||||
>::type call_1(
|
||||
Iterator first,
|
||||
Iterator last,
|
||||
Iterator temp_first,
|
||||
IntType t,
|
||||
PResult const& res
|
||||
) const
|
||||
{
|
||||
typedef typename result<Context, Iterator>::type result_type;
|
||||
typedef typename attribute<Context, Iterator>::type attribute_type;
|
||||
return sprout::tuples::get<1>(res)
|
||||
? call_0<N, Context>(
|
||||
sprout::next(first),
|
||||
last, temp_first,
|
||||
static_cast<IntType>(t * Radix | sprout::tuples::get<0>(res))
|
||||
)
|
||||
: N < MinDigits
|
||||
? result_type(false, temp_first, attribute_type())
|
||||
: result_type(true, first, t)
|
||||
;
|
||||
}
|
||||
template<std::size_t N, typename Context, typename Iterator>
|
||||
SPROUT_CONSTEXPR typename result<Context, Iterator>::type call_0(
|
||||
Iterator first,
|
||||
Iterator last,
|
||||
Iterator temp_first,
|
||||
IntType t
|
||||
) const
|
||||
{
|
||||
typedef typename result<Context, Iterator>::type result_type;
|
||||
typedef typename attribute<Context, Iterator>::type attribute_type;
|
||||
return first != last
|
||||
? call_1<N + 1, Context>(
|
||||
first,
|
||||
last,
|
||||
temp_first,
|
||||
t,
|
||||
sprout::weed::detail::from_ndigit<Radix, IntType>(*first)
|
||||
)
|
||||
: N < MinDigits
|
||||
? result_type(false, temp_first, attribute_type())
|
||||
: result_type(true, first, t)
|
||||
;
|
||||
}
|
||||
template<typename Context, typename Iterator, typename PResult>
|
||||
SPROUT_CONSTEXPR typename result<Context, Iterator>::type call(
|
||||
Iterator first,
|
||||
Iterator last,
|
||||
Iterator temp_first,
|
||||
PResult const& res
|
||||
) const
|
||||
{
|
||||
typedef typename result<Context, Iterator>::type result_type;
|
||||
typedef typename attribute<Context, Iterator>::type attribute_type;
|
||||
return sprout::tuples::get<1>(res)
|
||||
? call_0<1, Context>(
|
||||
sprout::next(first),
|
||||
last,
|
||||
temp_first,
|
||||
sprout::tuples::get<0>(res)
|
||||
)
|
||||
: result_type(false, temp_first, attribute_type())
|
||||
;
|
||||
}
|
||||
public:
|
||||
template<typename Context, typename Iterator>
|
||||
SPROUT_CONSTEXPR typename result<Context, Iterator>::type operator()(
|
||||
Iterator first,
|
||||
Iterator last,
|
||||
Context const&
|
||||
) const
|
||||
{
|
||||
typedef typename result<Context, Iterator>::type result_type;
|
||||
typedef typename attribute<Context, Iterator>::type attribute_type;
|
||||
return first != last
|
||||
? call<Context>(
|
||||
first,
|
||||
last,
|
||||
first,
|
||||
sprout::weed::detail::from_ndigit<Radix, IntType>(*first)
|
||||
)
|
||||
: result_type(false, first, attribute_type())
|
||||
;
|
||||
}
|
||||
};
|
||||
} // namespace weed
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_WEED_PARSER_NUMERIC_UINT_P_HPP
|
Loading…
Reference in a new issue