Allow ignoring of specifications in NameFormat.
authorCarl Hetherington <cth@carlh.net>
Tue, 5 May 2020 22:50:37 +0000 (00:50 +0200)
committerCarl Hetherington <cth@carlh.net>
Tue, 5 May 2020 22:50:37 +0000 (00:50 +0200)
src/name_format.cc
src/name_format.h

index 7b9cfd634760b1b57d6dd399729da6cdb2b9d150..76cca3fd3d45e2edbba4fc8d74df256d9f8e15b5 100644 (file)
@@ -64,15 +64,24 @@ filter (string c)
        return o;
 }
 
+
+/** @param values Values to replace our specifications with; e.g.
+ *  if the specification contains %c it will be be replaced with the
+ *  value corresponding to the key 'c'.
+ *  @param suffix Suffix to add on after processing the specification.
+ *  @param ignore Any specification characters in this string will not
+ *  be replaced, but left as-is.
+ */
 string
-NameFormat::get (Map values, string suffix) const
+NameFormat::get (Map values, string suffix, string ignore) const
 {
        string result;
        for (size_t i = 0; i < _specification.length(); ++i) {
                bool done = false;
                if (_specification[i] == '%' && (i < _specification.length() - 1)) {
-                       Map::const_iterator j = values.find(_specification[i + 1]);
-                       if (j != values.end()) {
+                       char const key = _specification[i + 1];
+                       Map::const_iterator j = values.find(key);
+                       if (j != values.end() && ignore.find(key) == string::npos) {
                                result += filter (j->second);
                                ++i;
                                done = true;
index e5cfb76d9382722202f74bc67c26c3b6ab96a095..e6fc9d724dab2b98db6df11346253073a124cf99 100644 (file)
@@ -60,7 +60,7 @@ public:
 
        typedef std::map<char, std::string> Map;
 
-       std::string get (Map, std::string suffix) const;
+       std::string get (Map, std::string suffix, std::string ignore = "") const;
 
 private:
        std::string _specification;