2 Copyright (C) 2016 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
6 DCP-o-matic is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 DCP-o-matic is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
21 #include "name_format.h"
22 #include <boost/optional.hpp>
23 #include <boost/foreach.hpp>
27 using boost::optional;
32 if (c == '/' || c == ':') {
34 } else if (c == ' ') {
46 for (size_t i = 0; i < c.length(); ++i) {
54 NameFormat::add (string name, char placeholder, string title)
56 _components.push_back (Component (name, placeholder, title));
59 optional<NameFormat::Component>
60 NameFormat::component_by_placeholder (char p) const
62 BOOST_FOREACH (Component const & i, _components) {
63 if (i.placeholder == p) {
68 return optional<Component> ();
72 NameFormat::get (Map values) const
75 for (size_t i = 0; i < _specification.length(); ++i) {
77 if (_specification[i] == '%' && (i < _specification.length() - 1)) {
78 optional<Component> c = component_by_placeholder (_specification[i + 1]);
80 result += filter (values[c->name]);
87 result += filter (_specification[i]);
95 operator== (NameFormat const & a, NameFormat const & b)
97 return a.specification() == b.specification();