aboutsummaryrefslogtreecommitdiff
path: root/src/util.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/util.cpp')
-rw-r--r--src/util.cpp55
1 files changed, 43 insertions, 12 deletions
diff --git a/src/util.cpp b/src/util.cpp
index cccf2df484..30590912ff 100644
--- a/src/util.cpp
+++ b/src/util.cpp
@@ -460,6 +460,7 @@ void ParseParameters(int argc, const char* const argv[])
{
mapArgs.clear();
mapMultiArgs.clear();
+
for (int i = 1; i < argc; i++)
{
std::string str(argv[i]);
@@ -475,9 +476,15 @@ void ParseParameters(int argc, const char* const argv[])
if (boost::algorithm::starts_with(str, "/"))
str = "-" + str.substr(1);
#endif
+
if (str[0] != '-')
break;
+ // Interpret --foo as -foo.
+ // If both --foo and -foo are set, the last takes effect.
+ if (str.length() > 1 && str[1] == '-')
+ str = str.substr(1);
+
mapArgs[str] = strValue;
mapMultiArgs[str].push_back(strValue);
}
@@ -485,19 +492,8 @@ void ParseParameters(int argc, const char* const argv[])
// New 0.6 features:
BOOST_FOREACH(const PAIRTYPE(string,string)& entry, mapArgs)
{
- string name = entry.first;
-
- // interpret --foo as -foo (as long as both are not set)
- if (name.find("--") == 0)
- {
- std::string singleDash(name.begin()+1, name.end());
- if (mapArgs.count(singleDash) == 0)
- mapArgs[singleDash] = entry.second;
- name = singleDash;
- }
-
// interpret -nofoo as -foo=0 (and -nofoo=0 as -foo=1) as long as -foo not set
- InterpretNegativeSetting(name, mapArgs);
+ InterpretNegativeSetting(entry.first, mapArgs);
}
}
@@ -1407,3 +1403,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();
+}