proxygen
Conv.h File Reference
#include <algorithm>
#include <cctype>
#include <climits>
#include <cstddef>
#include <limits>
#include <stdexcept>
#include <string>
#include <tuple>
#include <type_traits>
#include <typeinfo>
#include <utility>
#include <double-conversion/double-conversion.h>
#include <folly/Demangle.h>
#include <folly/Expected.h>
#include <folly/FBString.h>
#include <folly/Likely.h>
#include <folly/Range.h>
#include <folly/Traits.h>
#include <folly/Unit.h>
#include <folly/lang/Exception.h>
#include <folly/portability/Math.h>

Go to the source code of this file.

Classes

struct  folly::ConversionErrorBase
 
class  folly::ConversionError
 
struct  folly::detail::LastElementImpl< Ts >
 
struct  folly::detail::LastElementImpl< Head, Ts... >
 
struct  folly::detail::LastElement< Ts >
 
struct  folly::detail::CheckTrailingSpace
 
struct  folly::detail::ReturnUnit< Error >
 

Namespaces

 folly
 —— Concurrent Priority Queue Implementation ——
 
 folly::detail
 

Typedefs

template<typename Tgt , typename Src >
using folly::detail::IsArithToArith = bool_constant< !std::is_same< Tgt, Src >::value &&!std::is_same< Tgt, bool >::value &&std::is_arithmetic< Src >::value &&std::is_arithmetic< Tgt >::value >
 
template<typename Tgt >
using folly::detail::ParseToResult = decltype(parseTo(StringPiece{}, std::declval< Tgt & >()))
 
template<typename Tgt >
using folly::detail::ParseToError = ExpectedErrorType< decltype(detail::parseToWrap(StringPiece{}, std::declval< Tgt & >()))>
 

Enumerations

enum  folly::ConversionCode : unsigned char {
  folly::ConversionCode::SUCCESS, folly::ConversionCode::EMPTY_INPUT_STRING, folly::ConversionCode::NO_DIGITS, folly::ConversionCode::BOOL_OVERFLOW,
  folly::ConversionCode::BOOL_INVALID_VALUE, folly::ConversionCode::NON_DIGIT_CHAR, folly::ConversionCode::INVALID_LEADING_CHAR, folly::ConversionCode::POSITIVE_OVERFLOW,
  folly::ConversionCode::NEGATIVE_OVERFLOW, folly::ConversionCode::STRING_TO_FLOAT_ERROR, folly::ConversionCode::NON_WHITESPACE_AFTER_END, folly::ConversionCode::ARITH_POSITIVE_OVERFLOW,
  folly::ConversionCode::ARITH_NEGATIVE_OVERFLOW, folly::ConversionCode::ARITH_LOSS_OF_PRECISION, folly::ConversionCode::NUM_ERROR_CODES
}
 

Functions

ConversionError folly::makeConversionError (ConversionCode code, StringPiece input)
 
ConversionCode folly::detail::enforceWhitespaceErr (StringPiece sp)
 
void folly::detail::enforceWhitespace (StringPiece sp)
 
template<class Tgt , class Src >
std::enable_if< std::is_same< Tgt, typename std::decay< Src >::type >::value, Expected< Tgt, ConversionCode > >::type folly::tryTo (Src &&value)
 
template<class Tgt , class Src >
std::enable_if< std::is_same< Tgt, typename std::decay< Src >::type >::value, Tgt >::type folly::to (Src &&value)
 
template<class Tgt , class Src >
std::enable_if< std::is_arithmetic< Src >::value &&!std::is_same< Tgt, Src >::value &&std::is_same< Tgt, bool >::value, Expected< Tgt, ConversionCode > >::type folly::tryTo (const Src &value)
 
template<class Tgt , class Src >
std::enable_if< std::is_arithmetic< Src >::value &&!std::is_same< Tgt, Src >::value &&std::is_same< Tgt, bool >::value, Tgt >::type folly::to (const Src &value)
 
template<typename... Ts>
auto folly::detail::getLastElement (const Ts &...ts) -> decltype(LastElementImpl< Ts... >::call(ts...))
 
uint32_t folly::digits10 (uint64_t v)
 
uint32_t folly::uint64ToBufferUnsafe (uint64_t v, char *const buffer)
 
template<class Tgt >
void folly::toAppend (char value, Tgt *result)
 
template<class T >
constexpr std::enable_if< std::is_same< T, char >::value, size_t >::type folly::estimateSpaceNeeded (T)
 
template<size_t N>
constexpr size_t folly::estimateSpaceNeeded (const char(&)[N])
 
template<class Tgt , class Src >
std::enable_if< std::is_convertible< Src, const char * >::value &&IsSomeString< Tgt >::value >::type folly::toAppend (Src value, Tgt *result)
 
template<class Src >
std::enable_if< std::is_convertible< Src, const char * >::value, size_t >::type folly::estimateSpaceNeeded (Src value)
 
template<class Src >
std::enable_if< IsSomeString< Src >::value, size_t >::type folly::estimateSpaceNeeded (Src const &value)
 
template<class Src >
std::enable_if< std::is_convertible< Src, folly::StringPiece >::value &&!IsSomeString< Src >::value &&!std::is_convertible< Src, const char * >::value, size_t >::type folly::estimateSpaceNeeded (Src value)
 
template<>
size_t folly::estimateSpaceNeeded (std::nullptr_t)
 
template<class Src >
std::enable_if< std::is_pointer< Src >::value &&IsSomeString< std::remove_pointer< Src > >::value, size_t >::type folly::estimateSpaceNeeded (Src value)
 
template<class Tgt , class Src >
std::enable_if< IsSomeString< Src >::value &&IsSomeString< Tgt >::value >::type folly::toAppend (const Src &value, Tgt *result)
 
template<class Tgt >
std::enable_if< IsSomeString< Tgt >::value >::type folly::toAppend (StringPiece value, Tgt *result)
 
template<class Tgt >
std::enable_if< IsSomeString< Tgt >::value >::type folly::toAppend (const fbstring &value, Tgt *result)
 
template<class Tgt , class Src >
size_t::type folly::estimateSpaceNeeded (Src value)
 
template<class Delimiter , class... Ts>
void folly::reserveInTargetDelim (const Delimiter &d, const Ts &...vs)
 
template<class T , class Tgt >
std::enable_if< IsSomeString< typename std::remove_pointer< Tgt >::type >::value >::type folly::toAppendStrImpl (const T &v, Tgt result)
 
 toAppend (v, result)
 
folly::std enable_if::typetoAppendDelimStrImpl const Delimiter, const Tv, Tgtresult folly::sizeof (Ts) >
 
folly::std enable_if::typetoAppendDelimStrImpl const Delimiter, const Tv, Tgtresult bool Tgt::type folly::to (const char *b, const char *e)
 
template<typename Tgt >
FOLLY_NODISCARD std::enable_if< std::is_arithmetic< Tgt >::value, Expected< StringPiece, ConversionCode > >::type folly::parseTo (StringPiece src, Tgt &out)
 
template<class Tgt >
std::enable_if< !std::is_same< Tgt, bool >::value &&(std::is_integral< Tgt >::value||std::is_floating_point< Tgt >::value), Expected< Tgt, ConversionCode > >::type folly::detail::convertTo (const bool &value) noexcept
 
template<class Tgt , class Src >
std::enable_if< std::is_integral< Src >::value &&!std::is_same< Tgt, Src >::value &&!std::is_same< Tgt, bool >::value &&std::is_integral< Tgt >::value, Expected< Tgt, ConversionCode > >::type folly::detail::convertTo (const Src &value) noexcept
 
template<class Tgt , class Src >
std::enable_if< std::is_floating_point< Tgt >::value &&std::is_floating_point< Src >::value &&!std::is_same< Tgt, Src >::value, Expected< Tgt, ConversionCode > >::type folly::detail::convertTo (const Src &value) noexcept
 
template<typename Tgt , typename Src >
std::enable_if< std::is_floating_point< Src >::value &&std::is_integral< Tgt >::value &&!std::is_same< Tgt, bool >::value, bool >::type folly::detail::checkConversion (const Src &value)
 
template<typename Tgt , typename Src >
constexpr std::enable_if< std::is_integral< Src >::value &&std::is_floating_point< Tgt >::value, bool >::type folly::detail::checkConversion (const Src &)
 
template<typename Tgt , typename Src >
constexpr std::enable_if< std::is_floating_point< Src >::value &&std::is_same< Tgt, bool >::value, bool >::type folly::detail::checkConversion (const Src &)
 
template<typename Tgt , typename Src >
std::enable_if< (std::is_integral< Src >::value &&std::is_floating_point< Tgt >::value)||(std::is_floating_point< Src >::value &&std::is_integral< Tgt >::value), Expected< Tgt, ConversionCode > >::type folly::detail::convertTo (const Src &value) noexcept
 
template<typename Tgt , typename Src >
std::string folly::detail::errorValue (const Src &value)
 
template<typename Tgt , typename Src >
std::enable_if< detail::IsArithToArith< Tgt, Src >::value, Expected< Tgt, ConversionCode > >::type folly::tryTo (const Src &value) noexcept
 
template<typename Tgt , typename Src >
std::enable_if< detail::IsArithToArith< Tgt, Src >::value, Tgt >::type folly::to (const Src &value)
 
template<class T >
FOLLY_NODISCARD std::enable_if< std::is_enum< T >::value, Expected< StringPiece, ConversionCode > >::type folly::parseTo (StringPiece in, T &out) noexcept
 
FOLLY_NODISCARD Expected< StringPiece, ConversionCode > folly::parseTo (StringPiece in, StringPiece &out) noexcept
 
FOLLY_NODISCARD Expected< StringPiece, ConversionCode > folly::parseTo (StringPiece in, std::string &out)
 
FOLLY_NODISCARD Expected< StringPiece, ConversionCode > folly::parseTo (StringPiece in, fbstring &out)
 
template<class Tgt >
std::enable_if< std::is_void< ParseToResult< Tgt > >::value, Expected< StringPiece, ConversionCode > >::type folly::detail::parseToWrap (StringPiece sp, Tgt &out)
 
template<class Tgt >
std::enable_if< !std::is_void< ParseToResult< Tgt > >::value, ParseToResult< Tgt > >::type folly::detail::parseToWrap (StringPiece sp, Tgt &out)
 
template<class Tgt >
std::enable_if< !std::is_same< StringPiece, Tgt >::value, Expected< Tgt, detail::ParseToError< Tgt > > >::type folly::tryTo (StringPiece src)
 
template<class Tgt , class Src >
std::enable_if< IsSomeString< Src >::value &&!std::is_same< StringPiece, Tgt >::value, Tgt >::type folly::to (Src const &src)
 
template<class Tgt >
std::enable_if<!std::is_same< StringPiece, Tgt >::value, Tgt >::type folly::to (StringPiece src)
 
template<class Tgt >
Expected< Tgt, detail::ParseToError< Tgt > > folly::tryTo (StringPiece *src)
 
template<class Tgt >
Tgt folly::to (StringPiece *src)
 
template<class Tgt , class Src >
std::enable_if< std::is_enum< Src >::value &&!std::is_same< Src, Tgt >::value &&!std::is_convertible< Tgt, StringPiece >::value, Expected< Tgt, ConversionCode > >::type folly::tryTo (const Src &value)
 
template<class Tgt , class Src >
std::enable_if< !std::is_convertible< Src, StringPiece >::value &&std::is_enum< Tgt >::value &&!std::is_same< Src, Tgt >::value, Expected< Tgt, ConversionCode > >::type folly::tryTo (const Src &value)
 
template<class Tgt , class Src >
std::enable_if< std::is_enum< Src >::value &&!std::is_same< Src, Tgt >::value &&!std::is_convertible< Tgt, StringPiece >::value, Tgt >::type folly::to (const Src &value)
 
template<class Tgt , class Src >
std::enable_if< !std::is_convertible< Src, StringPiece >::value &&std::is_enum< Tgt >::value &&!std::is_same< Src, Tgt >::value, Tgt >::type folly::to (const Src &value)
 

Variables

template<class Tgt , class Src >
std::enable_if< std::is_integral< Src >::value &&IsSomeString< Tgt >::value &&sizeof(Src)< 4 >::typetoAppend(Src value, Tgt *result){typedef typename std::conditional< std::is_signed< Src >::value, int64_t, uint64_t >::type Intermediate;toAppend< Tgt >static_cast< Intermediate >value), result);}template< class Src >typename std::enable_if< std::is_integral< Src >::value &&sizeof(Src)< 4 &&!std::is_same< Src, char >::value, size_t >::typeestimateSpaceNeeded(Src value){typedef typename std::conditional< std::is_signed< Src >::value, int64_t, uint64_t >::type Intermediate;return estimateSpaceNeeded(static_cast< Intermediate >value));}template< class Tgt, class Src >typename std::enable_if< std::is_enum< Src >::value &&IsSomeString< Tgt >::value >::typetoAppend(Src value, Tgt *result){toAppend(static_cast< typename std::underlying_type< Src >::type >value), result);}template< class Src >typename std::enable_if< std::is_enum< Src >::value, size_t >::typeestimateSpaceNeeded(Src value){return estimateSpaceNeeded(static_cast< typename std::underlying_type< Src >::type >value));}namespace detail{constexpr int kConvMaxDecimalInShortestLow=-6;constexpr int kConvMaxDecimalInShortestHigh=21;}template< class Tgt, class Src >typename std::enable_if< std::is_floating_point< Src >::value &&IsSomeString< Tgt >::value >::typetoAppend(Src value, Tgt *result, double_conversion::DoubleToStringConverter::DtoaMode mode, unsigned int numDigits){using namespace double_conversion;DoubleToStringConverter conv(DoubleToStringConverter::NO_FLAGS,"Infinity","NaN", 'E', detail::kConvMaxDecimalInShortestLow, detail::kConvMaxDecimalInShortestHigh, 6, 1);char buffer[256];StringBuilder builder(buffer, sizeof(buffer));switch(mode){case DoubleToStringConverter::SHORTEST:conv.ToShortest(value,&builder);break;case DoubleToStringConverter::SHORTEST_SINGLE:conv.ToShortestSingle(static_cast< float >value),&builder);break;case DoubleToStringConverter::FIXED:conv.ToFixed(value, int(numDigits),&builder);break;default:CHECK(mode==DoubleToStringConverter::PRECISION);conv.ToPrecision(value, int(numDigits),&builder);break;}const size_t length=size_t(builder.position());builder.Finalize();result->append(buffer, length);}template< class Tgt, class Src >typename std::enable_if< std::is_floating_point< Src >::value &&IsSomeString< Tgt >::value >::typetoAppend(Src value, Tgt *result){toAppend(value, result, double_conversion::DoubleToStringConverter::SHORTEST, 0);}template< class Src >typename std::enable_if< std::is_floating_point< Src >::value, size_t >::typeestimateSpaceNeeded(Src value){constexpr int kMaxMantissaSpace=double_conversion::DoubleToStringConverter::kBase10MaximalLength+1;constexpr int kMaxExponentSpace=2+3;static const int kMaxPositiveSpace=std::max({kMaxMantissaSpace+kMaxExponentSpace, kMaxMantissaSpace-detail::kConvMaxDecimalInShortestLow, detail::kConvMaxDecimalInShortestHigh,});return size_t(kMaxPositiveSpace+(value< 0?1:0));}template< class Src >struct HasLengthEstimator:std::false_type{};template< class Src >constexpr typename std::enable_if< !std::is_fundamental< Src >::value &&!IsSomeString< Src >::value &&!std::is_convertible< Src, const char * >::value &&!std::is_convertible< Src, StringPiece >::value &&!std::is_enum< Src >::value &&!HasLengthEstimator< Src >::value, size_t >::typeestimateSpaceNeeded(const Src &){return sizeof(Src)+1;}namespace detail{template< class Tgt >typename std::enable_if< IsSomeString< Tgt >::value, size_t >::typeestimateSpaceToReserve(size_t sofar, Tgt *){return sofar;}template< class T, class...Ts >size_t estimateSpaceToReserve(size_t sofar, const T &v, const Ts &...vs){return estimateSpaceToReserve(sofar+estimateSpaceNeeded(v), vs...);}template< class...Ts >void reserveInTarget(const Ts &...vs){getLastElement(vs...) -> folly::reserve (estimateSpaceToReserve(0, vs...))
 
struct folly::detail::LastElementImpl folly::detail::sizeof
 
folly::std folly::Delimiter
 
folly::std folly::T
 

Function Documentation

toAppend ( v  ,
result   
)