diff options
author | dshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573> | 2007-07-21 12:17:29 +0000 |
---|---|---|
committer | dshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573> | 2007-07-21 12:17:29 +0000 |
commit | 9843737e73a47ef6f1da0554b7ca73018d52d345 (patch) | |
tree | 9381ef8b914bc801386f62ce2713c59c17b6a9e8 /crawl-ref/source/libutil.cc | |
parent | b27a757b68bf8a1dcbcb9b3a5cfea5c1278c9bb4 (diff) | |
download | crawl-ref-9843737e73a47ef6f1da0554b7ca73018d52d345.tar.gz crawl-ref-9843737e73a47ef6f1da0554b7ca73018d52d345.zip |
Updated level-design.txt.
Moved map markers to mapmark.cc.
Added support for timer markers that remove a feature after a certain timeout.
Need to hook up messaging to Lua.
Added bazaars (need more bazaar layouts).
git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@1899 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref/source/libutil.cc')
-rw-r--r-- | crawl-ref/source/libutil.cc | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/crawl-ref/source/libutil.cc b/crawl-ref/source/libutil.cc index 09f86ce2fd..e3c68f87bb 100644 --- a/crawl-ref/source/libutil.cc +++ b/crawl-ref/source/libutil.cc @@ -129,6 +129,72 @@ int ends_with(const std::string &s, const char *suffixes[]) return (0); } +// Returns true if s contains tag 'tag', and strips out tag from s. +bool strip_tag(std::string &s, const std::string &tag, bool skip_padding) +{ + if (s == tag) + { + s.clear(); + return (true); + } + + std::string::size_type pos; + + if (skip_padding) + { + if ((pos = s.find(tag)) != std::string::npos) + { + s.erase(pos, tag.length()); + trim_string(s); + return (true); + } + return (false); + } + + if ((pos = s.find(" " + tag + " ")) != std::string::npos) + { + // Leave one space intact. + s.erase(pos, tag.length() + 1); + trim_string(s); + return (true); + } + + if ((pos = s.find(tag + " ")) != std::string::npos + || (pos = s.find(" " + tag)) != std::string::npos) + { + s.erase(pos, tag.length() + 1); + trim_string(s); + return (true); + } + + return (false); +} + +std::string strip_tag_prefix(std::string &s, const std::string &tagprefix) +{ + const std::string::size_type pos = s.find(tagprefix); + if (pos == std::string::npos) + return (""); + + std::string::size_type ns = s.find(" ", pos); + if (ns == std::string::npos) + ns = s.length(); + + const std::string argument = + s.substr(pos + tagprefix.length(), ns - pos - tagprefix.length()); + + s.erase(pos, ns - pos + 1); + trim_string(s); + + return (argument); +} + +int strip_number_tag(std::string &s, const std::string &tagprefix) +{ + const std::string num = strip_tag_prefix(s, tagprefix); + return (num.empty()? TAG_UNFOUND : atoi(num.c_str())); +} + // Naively prefix A/an to a noun. std::string article_a(const std::string &name, bool lowercase) { |