add strtoimax, strtoumax

This commit is contained in:
bolero-MURAKAMI 2012-04-17 23:18:51 +09:00
parent c532099a35
commit ece20bf8ef
4 changed files with 87 additions and 0 deletions

View file

@ -16,5 +16,7 @@
#include <sprout/cstdlib/strtof.hpp> #include <sprout/cstdlib/strtof.hpp>
#include <sprout/cstdlib/strtod.hpp> #include <sprout/cstdlib/strtod.hpp>
#include <sprout/cstdlib/strtold.hpp> #include <sprout/cstdlib/strtold.hpp>
#include <sprout/cstdlib/strtoimax.hpp>
#include <sprout/cstdlib/strtoumax.hpp>
#endif // #ifndef SPROUT_CSTDLIB_CONVERSION_HPP #endif // #ifndef SPROUT_CSTDLIB_CONVERSION_HPP

View file

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

View file

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

View file

@ -2,6 +2,7 @@
#define SPROUT_STRING_STRING_TO_INT_HPP #define SPROUT_STRING_STRING_TO_INT_HPP
#include <cstddef> #include <cstddef>
#include <cstdint>
#include <string> #include <string>
#include <type_traits> #include <type_traits>
#include <sprout/config.hpp> #include <sprout/config.hpp>
@ -111,6 +112,30 @@ namespace sprout {
return sprout::string_to_int<unsigned long long>(str, base); return sprout::string_to_int<unsigned long long>(str, base);
} }
//
// stoimax
//
template<typename Elem, std::size_t N, typename Traits>
inline SPROUT_CONSTEXPR std::intmax_t stoimax(sprout::basic_string<Elem, N, Traits> const& str, std::size_t* idx, int base = 10) {
return sprout::string_to_int<std::intmax_t>(str, idx, base);
}
template<typename Elem, std::size_t N, typename Traits>
inline SPROUT_CONSTEXPR std::intmax_t stoimax(sprout::basic_string<Elem, N, Traits> const& str, int base = 10) {
return sprout::string_to_int<std::intmax_t>(str, base);
}
//
// stoumax
//
template<typename Elem, std::size_t N, typename Traits>
inline SPROUT_CONSTEXPR std::uintmax_t stoumax(sprout::basic_string<Elem, N, Traits> const& str, std::size_t* idx, int base = 10) {
return sprout::string_to_int<std::uintmax_t>(str, idx, base);
}
template<typename Elem, std::size_t N, typename Traits>
inline SPROUT_CONSTEXPR std::uintmax_t stoumax(sprout::basic_string<Elem, N, Traits> const& str, int base = 10) {
return sprout::string_to_int<std::uintmax_t>(str, base);
}
// //
// from_string // from_string
// //