Some compilers don't like x = {} where x is a boost::optional<string>
[libdcp.git] / src / name_format.cc
index 1dc1135df44a584c6d9f8d889f3ac3aa8ab57c18..e5c6556e9ae9a6b43fbbb6f65288b2f7ec00bb73 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2016 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2016-2021 Carl Hetherington <cth@carlh.net>
 
     This file is part of libdcp.
 
     files in the program, then also delete it here.
 */
 
+
+/** @file  src/name_format.cc
+ *  @brief NameFormat class
+ */
+
+
 #include "name_format.h"
 #include <boost/optional.hpp>
-#include <boost/foreach.hpp>
+
 
 using std::string;
 using std::map;
 using boost::optional;
 using namespace dcp;
 
+
 static char
 filter (char c)
 {
@@ -52,6 +59,7 @@ filter (char c)
        return c;
 }
 
+
 static string
 filter (string c)
 {
@@ -64,34 +72,18 @@ filter (string c)
        return o;
 }
 
-void
-NameFormat::add (string name, char placeholder, string title)
-{
-       _components.push_back (Component (name, placeholder, title));
-}
-
-optional<NameFormat::Component>
-NameFormat::component_by_placeholder (char p) const
-{
-       BOOST_FOREACH (Component const & i, _components) {
-               if (i.placeholder == p) {
-                       return i;
-               }
-       }
-
-       return optional<Component> ();
-}
 
 string
-NameFormat::get (Map values) 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)) {
-                       optional<Component> c = component_by_placeholder (_specification[i + 1]);
-                       if (c) {
-                               result += filter (values[c->name]);
+                       char const key = _specification[i + 1];
+                       auto j = values.find(key);
+                       if (j != values.end() && ignore.find(key) == string::npos) {
+                               result += filter (j->second);
                                ++i;
                                done = true;
                        }
@@ -102,9 +94,10 @@ NameFormat::get (Map values) const
                }
        }
 
-       return result;
+       return result + suffix;
 }
 
+
 bool
 dcp::operator== (NameFormat const & a, NameFormat const & b)
 {