@@ -685,25 +685,27 @@ namespace mtconnect {
685685 // /
686686 // / @param[in,out] start starting iterator
687687 // / @param[in,out] end ending iterator
688- inline void capitalize (std::string::iterator start, std::string::iterator end)
688+ inline void capitalize (std::ostringstream &camel, std::string::const_iterator start,
689+ std::string::const_iterator end)
689690 {
690691 using namespace std ;
691692
692693 // Exceptions to the rule
693- const static std::unordered_map<std::string , std::string > exceptions = {
694+ const static std::unordered_map<std::string_view , std::string_view > exceptions = {
694695 {" AC" , " AC" }, {" DC" , " DC" }, {" PH" , " PH" },
695696 {" IP" , " IP" }, {" URI" , " URI" }, {" MTCONNECT" , " MTConnect" }};
696697
697- const auto &w = exceptions.find (std::string (start, end));
698+ std::string_view s (&*start, distance (start, end));
699+ const auto &w = exceptions.find (s);
700+ ostream_iterator<char > out (camel);
698701 if (w != exceptions.end ())
699702 {
700- copy (w->second .begin (), w->second .end (), start );
703+ copy (w->second .begin (), w->second .end (), out );
701704 }
702705 else
703706 {
704- *start = ::toupper (*start);
705- start++;
706- transform (start, end, start, ::tolower);
707+ camel << static_cast <char >(::toupper (*start));
708+ transform (start + 1 , end, out, ::tolower);
707709 }
708710 }
709711
@@ -721,34 +723,33 @@ namespace mtconnect {
721723 if (type.empty ())
722724 return " " ;
723725
724- string camel;
726+ ostringstream camel;
727+
728+ auto start = type.begin ();
729+ decltype (start) end;
730+
725731 auto colon = type.find (' :' );
726732
727733 if (colon != string::npos)
728734 {
729735 prefix = type.substr (0ul , colon);
730- camel = type. substr ( colon + 1ul ) ;
736+ start += colon + 1 ;
731737 }
732- else
733- camel = type;
734-
735- auto start = camel.begin ();
736- decltype (start) end;
737738
738739 bool done;
739740 do
740741 {
741- end = find (start, camel.end (), ' _' );
742- capitalize (start, end);
743- done = end == camel.end ();
742+ end = find (start, type.end (), ' _' );
743+ if (start != end)
744+ capitalize (camel, start, end);
745+ done = end == type.end ();
744746 if (!done)
745747 {
746- camel.erase (end);
747- start = end;
748+ start = end + 1 ;
748749 }
749750 } while (!done);
750751
751- return camel;
752+ return camel. str () ;
752753 }
753754
754755 // / @brief parse a string timestamp to a `Timestamp`
0 commit comments