diff options
| author | Maxime Coste <maxime.coste@havok.com> | 2015-01-13 13:47:46 +0000 |
|---|---|---|
| committer | Maxime Coste <maxime.coste@havok.com> | 2015-01-13 13:47:46 +0000 |
| commit | b9c4fc2d8c455991d1ffda250df5acacf5949a82 (patch) | |
| tree | dec84b141a17e81612207e77c05e5edd6fed597a /src | |
| parent | 9b4dc8d56be05fa74f53ca327c6c174252dd08ec (diff) | |
Add size_t and float to_string overload, and _sv UDL
Diffstat (limited to 'src')
| -rw-r--r-- | src/string.cc | 14 | ||||
| -rw-r--r-- | src/string.hh | 7 |
2 files changed, 21 insertions, 0 deletions
diff --git a/src/string.cc b/src/string.cc index 2bea1cf4..dab1d2fe 100644 --- a/src/string.cc +++ b/src/string.cc @@ -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(); diff --git a/src/string.hh b/src/string.hh index 18e9ae4e..54a8b900 100644 --- a/src/string.hh +++ b/src/string.hh @@ -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) |
