From b9c4fc2d8c455991d1ffda250df5acacf5949a82 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Tue, 13 Jan 2015 13:47:46 +0000 Subject: [PATCH] Add size_t and float to_string overload, and _sv UDL --- src/string.cc | 14 ++++++++++++++ src/string.hh | 7 +++++++ 2 files changed, 21 insertions(+) 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 String to_string(const StronglyTypedNumber& val)