summaryrefslogtreecommitdiff
path: root/include/llvm/ADT/StringExtras.h
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2017-06-26 20:32:52 +0000
committerDimitry Andric <dim@FreeBSD.org>2017-06-26 20:32:52 +0000
commit08bbd35a80bf7765fe0d3043f9eb5a2f2786b649 (patch)
tree80108f0f128657f8623f8f66ad9735b4d88e7b47 /include/llvm/ADT/StringExtras.h
parent7c7aba6e5fef47a01a136be655b0a92cfd7090f6 (diff)
Notes
Diffstat (limited to 'include/llvm/ADT/StringExtras.h')
-rw-r--r--include/llvm/ADT/StringExtras.h28
1 files changed, 28 insertions, 0 deletions
diff --git a/include/llvm/ADT/StringExtras.h b/include/llvm/ADT/StringExtras.h
index ffcf998a3d323..cc32bf43f29c8 100644
--- a/include/llvm/ADT/StringExtras.h
+++ b/include/llvm/ADT/StringExtras.h
@@ -15,10 +15,12 @@
#define LLVM_ADT_STRINGEXTRAS_H
#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/StringRef.h"
#include <cassert>
#include <cstddef>
#include <cstdint>
+#include <cstdlib>
#include <cstring>
#include <iterator>
#include <string>
@@ -129,6 +131,32 @@ template <typename N> bool to_integer(StringRef S, N &Num, unsigned Base = 0) {
return !S.getAsInteger(Base, Num);
}
+namespace detail {
+template <typename N>
+inline bool to_float(const Twine &T, N &Num, N (*StrTo)(const char *, char **)) {
+ SmallString<32> Storage;
+ StringRef S = T.toNullTerminatedStringRef(Storage);
+ char *End;
+ N Temp = StrTo(S.data(), &End);
+ if (*End != '\0')
+ return false;
+ Num = Temp;
+ return true;
+}
+}
+
+inline bool to_float(const Twine &T, float &Num) {
+ return detail::to_float(T, Num, strtof);
+}
+
+inline bool to_float(const Twine &T, double &Num) {
+ return detail::to_float(T, Num, strtod);
+}
+
+inline bool to_float(const Twine &T, long double &Num) {
+ return detail::to_float(T, Num, strtold);
+}
+
static inline std::string utostr(uint64_t X, bool isNeg = false) {
char Buffer[21];
char *BufPtr = std::end(Buffer);