From 54bfc8f5f26243e68353eeedb959864e6565de4c Mon Sep 17 00:00:00 2001 From: dshaligram Date: Fri, 16 Mar 2007 15:48:28 +0000 Subject: 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 --- crawl-ref/source/libutil.cc | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) (limited to 'crawl-ref/source/libutil.cc') 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 &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 split_string( const char *sep, std::string s, bool trim_segments, - bool accept_empty_segments) + bool accept_empty_segments, + int nsplits) { std::vector 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; } -- cgit v1.2.3-54-g00ecf