1 //===-- StringConvert.cpp ---------------------------------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
11 #include "lldb/Host/StringConvert.h"
13 namespace lldb_private {
14 namespace StringConvert {
16 int32_t ToSInt32(const char *s, int32_t fail_value, int base,
20 const long sval = ::strtol(s, &end, base);
23 *success_ptr = ((sval <= INT32_MAX) && (sval >= INT32_MIN));
24 return (int32_t)sval; // All characters were used, return the result
32 uint32_t ToUInt32(const char *s, uint32_t fail_value, int base,
36 const unsigned long uval = ::strtoul(s, &end, base);
39 *success_ptr = (uval <= UINT32_MAX);
40 return (uint32_t)uval; // All characters were used, return the result
48 int64_t ToSInt64(const char *s, int64_t fail_value, int base,
52 int64_t uval = ::strtoll(s, &end, base);
56 return uval; // All characters were used, return the result
64 uint64_t ToUInt64(const char *s, uint64_t fail_value, int base,
68 uint64_t uval = ::strtoull(s, &end, base);
72 return uval; // All characters were used, return the result
80 double ToDouble(const char *s, double fail_value, bool *success_ptr) {
83 double val = strtod(s, &end);
87 return val; // All characters were used, return the result