MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / FormatParagraph

Function FormatParagraph

src/util/strencodings.cpp:201–241  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

199}
200
201std::string FormatParagraph(std::string_view in, size_t width, size_t indent)
202{
203 assert(width >= indent);
204 std::stringstream out;
205 size_t ptr = 0;
206 size_t indented = 0;
207 while (ptr < in.size())
208 {
209 size_t lineend = in.find_first_of('\n', ptr);
210 if (lineend == std::string::npos) {
211 lineend = in.size();
212 }
213 const size_t linelen = lineend - ptr;
214 const size_t rem_width = width - indented;
215 if (linelen <= rem_width) {
216 out << in.substr(ptr, linelen + 1);
217 ptr = lineend + 1;
218 indented = 0;
219 } else {
220 size_t finalspace = in.find_last_of(" \n", ptr + rem_width);
221 if (finalspace == std::string::npos || finalspace < ptr) {
222 // No place to break; just include the entire word and move on
223 finalspace = in.find_first_of("\n ", ptr);
224 if (finalspace == std::string::npos) {
225 // End of the string, just add it and break
226 out << in.substr(ptr);
227 break;
228 }
229 }
230 out << in.substr(ptr, finalspace - ptr) << "\n";
231 if (in[finalspace] == '\n') {
232 indented = 0;
233 } else if (indent) {
234 out << std::string(indent, ' ');
235 indented = indent;
236 }
237 ptr = finalspace + 1;
238 }
239 }
240 return out.str();
241}
242
243/** Upper bound for mantissa.
244 * 10^18-1 is the largest arbitrary decimal that will fit in a signed 64-bit integer.

Callers 10

mainFunction · 0.85
AppInitRawTxFunction · 0.85
AppInitRPCFunction · 0.85
AppInitUtilFunction · 0.85
ProcessInitCommandsFunction · 0.85
WalletAppInitFunction · 0.85
BOOST_AUTO_TEST_CASEFunction · 0.85
FUZZ_TARGETFunction · 0.85
HelpMessageDialogMethod · 0.85
HelpMessageOptFunction · 0.85

Calls 2

strMethod · 0.80
sizeMethod · 0.45

Tested by 2

BOOST_AUTO_TEST_CASEFunction · 0.68
FUZZ_TARGETFunction · 0.68