Bitcoin Core 32.99.0
P2P Digital Currency
Loading...
Searching...
No Matches
string.cpp
Go to the documentation of this file.
1// Copyright (c) 2020-present The Bitcoin Core developers
2// Distributed under the MIT software license, see the accompanying
3// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5#include <blockfilter.h>
6#include <clientversion.h>
7#include <common/args.h>
9#include <common/messages.h>
10#include <common/settings.h>
11#include <common/system.h>
12#include <common/url.h>
13#include <netbase.h>
14#include <outputtype.h>
15#include <rpc/client.h>
16#include <rpc/request.h>
17#include <rpc/server.h>
18#include <rpc/util.h>
19#include <script/descriptor.h>
20#include <script/script.h>
21#include <serialize.h>
22#include <streams.h>
24#include <test/fuzz/fuzz.h>
25#include <test/fuzz/util.h>
26#include <util/fees.h>
27#include <util/strencodings.h>
28#include <util/string.h>
29#include <util/translation.h>
30
31#include <cassert>
32#include <cstdint>
33#include <cstdlib>
34#include <ios>
35#include <stdexcept>
36#include <string>
37#include <vector>
38
44using util::Join;
48
50{
51 FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
55
56 (void)AmountErrMsg(random_string_1, random_string_2);
57 (void)AmountHighWarn(random_string_1);
63 (void)FeeModeFromString(random_string_1, fee_estimate_mode);
64 const auto width{fuzzed_data_provider.ConsumeIntegralInRange<size_t>(1, 1000)};
76 (void)OnlyHasDefaultSectionSetting(settings, random_string_1, random_string_2);
79 (void)RemovePrefix(random_string_1, random_string_2);
80 (void)ResolveErrMsg(random_string_1, random_string_2);
81 try {
83 } catch (const std::runtime_error&) {
84 }
85 try {
87 } catch (const std::runtime_error&) {
88 }
91#ifndef WIN32
93#endif // WIN32
95 std::string host_out;
100 (void)TrimString(random_string_1);
103 (void)ContainsNUL(random_string_1);
104 try {
106 } catch (const std::runtime_error&) {
107 }
108
109 {
111 std::string s;
112 auto limited_string = LIMITED_STRING(s, 10);
114 try {
116 assert(data_stream.empty());
117 assert(s.size() <= random_string_1.size());
118 assert(s.size() <= 10);
119 if (!random_string_1.empty()) {
120 assert(!s.empty());
121 }
122 } catch (const std::ios_base::failure&) {
123 }
124 }
125 {
129 std::string deserialized_string;
131 assert(data_stream.empty());
133 }
134 {
137 }
138 {
139 const auto single_split{SplitString(random_string_1, fuzzed_data_provider.ConsumeIntegral<char>())};
140 assert(single_split.size() >= 1);
141 const auto any_split{SplitString(random_string_1, random_string_2)};
142 assert(any_split.size() >= 1);
143 }
144 {
148 (void)(bs1 + bs2);
149 }
150 {
151 const ByteUnit all_units[] = {
161 };
164 }
165}
std::string HelpMessageGroup(const std::string &message)
Format a string to be used as group of options in help messages.
Definition args.cpp:807
std::string HelpMessageOpt(std::string_view option, std::string_view help_param, std::string_view message, bool subopt)
Format a string to be used as option description in help messages.
Definition args.cpp:811
bool BlockFilterTypeByName(std::string_view name, BlockFilterType &filter_type)
Find a filter type by its human-readable name.
BlockFilterType
Definition blockfilter.h:94
Double ended buffer combining vector and stream-like interfaces.
Definition streams.h:165
std::string ConsumeRandomLengthString(size_t max_length)
T ConsumeIntegralInRange(T min, T max)
T PickValueInArray(const T(&array)[size])
UniValue RPCConvertValues(const std::string &strMethod, const std::vector< std::string > &strParams)
Convert command lines arguments to params object when -named is disabled.
Definition client.cpp:451
UniValue RPCConvertNamedValues(const std::string &strMethod, const std::vector< std::string > &strParams)
Convert command line arguments to params object when -named is enabled.
Definition client.cpp:491
std::string FormatSubVersion(const std::string &name, int nClientVersion, const std::vector< std::string > &comments)
Format the subversion field according to BIP 14 spec (https://github.com/bitcoin/bips/blob/master/bip...
std::string ShellEscape(const std::string &arg)
Definition system.cpp:37
#define FUZZ_TARGET(...)
Definition fuzz.h:35
std::string CopyrightHolders(const std::string &strPrefix)
is a home for simple string functions returning descriptive messages that are used in RPC and GUI int...
bilingual_str AmountErrMsg(const std::string &optname, const std::string &strValue)
Definition messages.cpp:171
bool FeeModeFromString(std::string_view mode_string, FeeEstimateMode &fee_estimate_mode)
Definition messages.cpp:96
bilingual_str ResolveErrMsg(const std::string &optname, const std::string &strBind)
Definition messages.cpp:156
bilingual_str AmountHighWarn(const std::string &optname)
Definition messages.cpp:166
std::vector< std::string > SplitString(std::string_view str, char sep)
Definition string.h:153
std::string TrimString(std::string_view str, std::string_view pattern=" \f\n\r\t\v")
Definition string.h:173
std::string RemovePrefix(std::string_view str, std::string_view prefix)
Definition string.h:194
auto Join(const C &container, const S &separator, UnaryOp unary_op)
Join all container items.
Definition string.h:209
bool ContainsNUL(std::string_view str) noexcept
Check if a string contains any embedded NUL (\0) characters.
Definition string.h:238
enum Network ParseNetwork(const std::string &net_in)
Definition netbase.cpp:100
std::optional< OutputType > ParseOutputType(std::string_view type)
UniValue JSONRPCError(int code, const std::string &message)
Definition request.cpp:75
std::string HelpExampleCli(const std::string &methodname, const std::string &args)
Definition util.cpp:189
std::string HelpExampleRpc(const std::string &methodname, const std::string &args)
Definition util.cpp:207
#define LIMITED_STRING(obj, n)
Definition serialize.h:496
bool IsDeprecatedRPCEnabled(const std::string &method)
Definition server.cpp:715
ByteUnit
Used by ParseByteUnits() Lowercase base 1000 Uppercase base 1024.
bool TimingResistantEqual(const T &a, const T &b)
Timing-attack-resistant comparison.
Bilingual messages:
Definition translation.h:24
Stored settings.
Definition settings.h:34
std::vector< std::string > ConsumeRandomLengthStringVector(FuzzedDataProvider &fuzzed_data_provider, const size_t max_vector_size=16, const size_t max_string_length=16) noexcept
Definition util.h:79
bilingual_str Untranslated(std::string original)
Mark a bilingual_str as untranslated.
Definition translation.h:82
std::string UrlDecode(std::string_view url_encoded)
Definition url.cpp:13
FeeEstimateMode
Definition fees.h:18
std::string Capitalize(std::string str)
Capitalizes the first character of the given string.
std::string ToUpper(std::string_view str)
Returns the uppercase equivalent of the given string.
bool ParseFixedPoint(std::string_view val, int decimals, int64_t *amount_out)
Parse number as fixed point according to JSON number syntax.
std::string FormatParagraph(std::string_view in, size_t width, size_t indent)
Format a paragraph of text to a fixed width, adding spaces for indentation to any added line.
bool SplitHostPort(std::string_view in, uint16_t &portOut, std::string &hostOut)
Splits socket address string into host string and port value.
std::optional< uint64_t > ParseByteUnits(std::string_view str, ByteUnit default_multiplier)
Parse a string with suffix unit [k|K|m|M|g|G|t|T].
std::string ToLower(std::string_view str)
Returns the lowercase equivalent of the given string.
std::string SanitizeString(std::string_view str, int rule)
Remove unsafe chars.
constexpr auto Ticks(Dur2 d)
Helper to count the seconds of a duration/time_point.
Definition time.h:82
assert(!tx.IsCoinBase())
FuzzedDataProvider & fuzzed_data_provider
Definition fees.cpp:46