1 //===-- StringConvert.cpp ---------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
14 // Other libraries and framework includes
16 #include "lldb/Host/StringConvert.h"
18 namespace lldb_private {
19 namespace StringConvert {
21 int32_t ToSInt32(const char *s, int32_t fail_value, int base,
25 const long sval = ::strtol(s, &end, base);
28 *success_ptr = ((sval <= INT32_MAX) && (sval >= INT32_MIN));
29 return (int32_t)sval; // All characters were used, return the result
37 uint32_t ToUInt32(const char *s, uint32_t fail_value, int base,
41 const unsigned long uval = ::strtoul(s, &end, base);
44 *success_ptr = (uval <= UINT32_MAX);
45 return (uint32_t)uval; // All characters were used, return the result
53 int64_t ToSInt64(const char *s, int64_t fail_value, int base,
57 int64_t uval = ::strtoll(s, &end, base);
61 return uval; // All characters were used, return the result
69 uint64_t ToUInt64(const char *s, uint64_t fail_value, int base,
73 uint64_t uval = ::strtoull(s, &end, base);
77 return uval; // All characters were used, return the result
85 double ToDouble(const char *s, double fail_value, bool *success_ptr) {
88 double val = strtod(s, &end);
92 return val; // All characters were used, return the result