diff options
author | Wladimir J. van der Laan <laanwj@gmail.com> | 2014-06-12 16:42:41 +0200 |
---|---|---|
committer | Wladimir J. van der Laan <laanwj@gmail.com> | 2014-06-12 16:42:55 +0200 |
commit | fe1f41728755851dfc000bdb99fce91bc7f24b8d (patch) | |
tree | a7bc4c720a442bdcbc1c41fb84b13e2058cf0070 /src/util.cpp | |
parent | e5ee8f016ebb1db1bac3c4d0dd895249a4a17a1d (diff) | |
parent | 5c97aae6da813ce4873651b31f75b26ea6f1352f (diff) | |
download | bitcoin-fe1f41728755851dfc000bdb99fce91bc7f24b8d.tar.xz |
Merge pull request #4281
5c97aae qt: Unify AboutDialog and HelpMessageDialog (Wladimir J. van der Laan)
45615af Add 'about' information to `-version` output (Wladimir J. van der Laan)
97789d3 util: Add function FormatParagraph to format paragraph to fixed-width (Wladimir J. van der Laan)
96b733e Add `-version` option to get just the version (Wladimir J. van der Laan)
Diffstat (limited to 'src/util.cpp')
-rw-r--r-- | src/util.cpp | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/util.cpp b/src/util.cpp index cccf2df484..3e3dabb678 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -1407,3 +1407,38 @@ std::string DateTimeStrFormat(const char* pszFormat, int64_t nTime) ss << boost::posix_time::from_time_t(nTime); return ss.str(); } + +std::string FormatParagraph(const std::string in, size_t width, size_t indent) +{ + std::stringstream out; + size_t col = 0; + size_t ptr = 0; + while(ptr < in.size()) + { + // Find beginning of next word + ptr = in.find_first_not_of(' ', ptr); + if (ptr == std::string::npos) + break; + // Find end of next word + size_t endword = in.find_first_of(' ', ptr); + if (endword == std::string::npos) + endword = in.size(); + // Add newline and indentation if this wraps over the allowed width + if (col > 0) + { + if ((col + endword - ptr) > width) + { + out << '\n'; + for(size_t i=0; i<indent; ++i) + out << ' '; + col = 0; + } else + out << ' '; + } + // Append word + out << in.substr(ptr, endword - ptr); + col += endword - ptr; + ptr = endword; + } + return out.str(); +} |