Add size_t and float to_string overload, and _sv UDL

This commit is contained in:
Maxime Coste 2015-01-13 13:47:46 +00:00
parent 9b4dc8d56b
commit b9c4fc2d8c
2 changed files with 21 additions and 0 deletions

View File

@ -104,6 +104,20 @@ String to_string(int val)
return buf;
}
String to_string(size_t val)
{
char buf[16];
sprintf(buf, "%lu", val);
return buf;
}
String to_string(float val)
{
char buf[32];
sprintf(buf, "%f", val);
return buf;
}
bool subsequence_match(StringView str, StringView subseq)
{
auto it = str.begin();

View File

@ -259,6 +259,11 @@ inline String operator"" _str(const char* str, size_t)
return String(str);
}
inline StringView operator"" _sv(const char* str, size_t len)
{
return StringView(str, (int)len);
}
inline String codepoint_to_str(Codepoint cp)
{
StringBase str;
@ -269,6 +274,8 @@ inline String codepoint_to_str(Codepoint cp)
int str_to_int(StringView str);
String to_string(int val);
String to_string(size_t val);
String to_string(float val);
template<typename RealType, typename ValueType>
String to_string(const StronglyTypedNumber<RealType, ValueType>& val)