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 //===----------------------------------------------------------------------===//
12 #include "lldb/Host/StringConvert.h"
14 namespace lldb_private {
15 namespace StringConvert {
17 int32_t ToSInt32(const char *s, int32_t fail_value, int base,
21 const long sval = ::strtol(s, &end, base);
24 *success_ptr = ((sval <= INT32_MAX) && (sval >= INT32_MIN));
25 return (int32_t)sval; // All characters were used, return the result
33 uint32_t ToUInt32(const char *s, uint32_t fail_value, int base,
37 const unsigned long uval = ::strtoul(s, &end, base);
40 *success_ptr = (uval <= UINT32_MAX);
41 return (uint32_t)uval; // All characters were used, return the result
49 int64_t ToSInt64(const char *s, int64_t fail_value, int base,
53 int64_t uval = ::strtoll(s, &end, base);
57 return uval; // All characters were used, return the result
65 uint64_t ToUInt64(const char *s, uint64_t fail_value, int base,
69 uint64_t uval = ::strtoull(s, &end, base);
73 return uval; // All characters were used, return the result
81 double ToDouble(const char *s, double fail_value, bool *success_ptr) {
84 double val = strtod(s, &end);
88 return val; // All characters were used, return the result