Changeset View
Changeset View
Standalone View
Standalone View
src/util/strencodings.cpp
// Copyright (c) 2009-2010 Satoshi Nakamoto | // Copyright (c) 2009-2010 Satoshi Nakamoto | ||||
// Copyright (c) 2009-2016 The Bitcoin Core developers | // Copyright (c) 2009-2016 The Bitcoin Core developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#include <util/strencodings.h> | #include <util/strencodings.h> | ||||
#include <util/string.h> | |||||
#include <tinyformat.h> | #include <tinyformat.h> | ||||
#include <algorithm> | #include <algorithm> | ||||
#include <cerrno> | #include <cerrno> | ||||
#include <cstdlib> | #include <cstdlib> | ||||
#include <cstring> | #include <cstring> | ||||
#include <limits> | #include <limits> | ||||
▲ Show 20 Lines • Show All 268 Lines • ▼ Show 20 Lines | NODISCARD static bool ParsePrechecks(const std::string &str) { | ||||
if (str.empty()) { | if (str.empty()) { | ||||
return false; | return false; | ||||
} | } | ||||
// No padding allowed | // No padding allowed | ||||
if (str.size() >= 1 && (IsSpace(str[0]) || IsSpace(str[str.size() - 1]))) { | if (str.size() >= 1 && (IsSpace(str[0]) || IsSpace(str[str.size() - 1]))) { | ||||
return false; | return false; | ||||
} | } | ||||
// No embedded NUL characters allowed | // No embedded NUL characters allowed | ||||
if (str.size() != strlen(str.c_str())) { | if (!ValidAsCString(str)) { | ||||
return false; | return false; | ||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
bool ParseInt32(const std::string &str, int32_t *out) { | bool ParseInt32(const std::string &str, int32_t *out) { | ||||
if (!ParsePrechecks(str)) { | if (!ParsePrechecks(str)) { | ||||
return false; | return false; | ||||
▲ Show 20 Lines • Show All 343 Lines • Show Last 20 Lines |