summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/libutil.cc
diff options
context:
space:
mode:
authordshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573>2007-03-16 15:48:28 +0000
committerdshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573>2007-03-16 15:48:28 +0000
commit54bfc8f5f26243e68353eeedb959864e6565de4c (patch)
treec7b82c5f497ab9f3bbfc5da435f60305738863ee /crawl-ref/source/libutil.cc
parenteff8860c8c5cf24ffb3ff64e4b44af416d72b3d4 (diff)
downloadcrawl-ref-54bfc8f5f26243e68353eeedb959864e6565de4c.tar.gz
crawl-ref-54bfc8f5f26243e68353eeedb959864e6565de4c.zip
Added message_colour option to allow custom-colouring individual messages. This
does not affect formatted_mpr. Moved low magic warning to the danger channel and added a message_colour option to colour it lightcyan in the stock init.txt. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@1050 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref/source/libutil.cc')
-rw-r--r--crawl-ref/source/libutil.cc37
1 files changed, 25 insertions, 12 deletions
diff --git a/crawl-ref/source/libutil.cc b/crawl-ref/source/libutil.cc
index 096eeffc8a..0b7772b531 100644
--- a/crawl-ref/source/libutil.cc
+++ b/crawl-ref/source/libutil.cc
@@ -380,30 +380,43 @@ std::string & trim_string( std::string &str )
return (str);
}
+static void add_segment(std::vector<std::string> &segs,
+ std::string s,
+ bool trim,
+ bool accept_empty)
+{
+ if (trim && !s.empty())
+ trim_string(s);
+
+ if (accept_empty || !s.empty())
+ segs.push_back(s);
+}
+
std::vector<std::string> split_string(
const char *sep,
std::string s,
bool trim_segments,
- bool accept_empty_segments)
+ bool accept_empty_segments,
+ int nsplits)
{
std::vector<std::string> segments;
int separator_length = strlen(sep);
std::string::size_type pos;
- while ((pos = s.find(sep, 0)) != std::string::npos)
+ while (nsplits && (pos = s.find(sep)) != std::string::npos)
{
- if (pos > 0 || accept_empty_segments)
- segments.push_back(s.substr(0, pos));
+ add_segment(segments, s.substr(0, pos),
+ trim_segments, accept_empty_segments);
+
s.erase(0, pos + separator_length);
+
+ if (nsplits > 0)
+ --nsplits;
}
- if (s.length() > 0)
- segments.push_back(s);
-
- if (trim_segments)
- {
- for (int i = 0, count = segments.size(); i < count; ++i)
- trim_string(segments[i]);
- }
+
+ if (!s.empty())
+ add_segment(segments, s, trim_segments, accept_empty_segments);
+
return segments;
}