diff options
| author | Carl Hetherington <cth@carlh.net> | 2020-05-06 00:50:37 +0200 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2020-05-06 00:50:37 +0200 |
| commit | 0d71b001187ec79dbdbddde4ebaabbdff8e2b9bd (patch) | |
| tree | e1259c8e3d32a5a87f75582ccd543c8299c71429 /src/name_format.cc | |
| parent | 5acc1161e26bdb98e47be591878252cf900d6fa9 (diff) | |
Allow ignoring of specifications in NameFormat.
Diffstat (limited to 'src/name_format.cc')
| -rw-r--r-- | src/name_format.cc | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/src/name_format.cc b/src/name_format.cc index 7b9cfd63..76cca3fd 100644 --- a/src/name_format.cc +++ b/src/name_format.cc @@ -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; |
