@@ -988,20 +988,26 @@ std::string_view SchemaLoader::getSafeCppName(std::string_view type) noexcept
988988 std::regex::optimize | std::regex::ECMAScript);
989989
990990 // Cache the substitutions so we don't need to repeat a replacement.
991- static std::unordered_map<std::string_view, std::string> safeNames;
992- auto itr = safeNames.find (type);
993- std::string cppName { type };
991+ static std::unordered_map<std::string, std::unique_ptr<std::string>> safeNames;
992+ auto itr = std::find_if (safeNames.begin (), safeNames.end (), [type](const auto & entry) noexcept {
993+ return entry.first == type;
994+ });
994995
995- if (safeNames.cend () == itr
996- && (std::regex_search (cppName, leading_Capital) || std::regex_search (cppName, multiple_)))
996+ if (safeNames.cend () == itr)
997997 {
998- std::tie (itr, std::ignore) = safeNames.emplace (type,
999- std::regex_replace (std::regex_replace (cppName, multiple_, R"re( _)re" ),
1000- leading_Capital,
1001- R"re( $1)re" ));
998+ std::string cppName { type };
999+
1000+ if (std::regex_search (cppName, leading_Capital) || std::regex_search (cppName, multiple_))
1001+ {
1002+ std::tie (itr, std::ignore) = safeNames.emplace (std::string { type },
1003+ std::make_unique<std::string>(
1004+ std::regex_replace (std::regex_replace (cppName, multiple_, R"re( _)re" ),
1005+ leading_Capital,
1006+ R"re( $1)re" )));
1007+ }
10021008 }
10031009
1004- return (safeNames.cend () == itr) ? type : itr->second ;
1010+ return (safeNames.cend () == itr) ? type : *( itr->second ) ;
10051011}
10061012
10071013OutputFieldList SchemaLoader::getOutputFields (const peg::ast_node::children_t & fields)
0 commit comments