diff --git a/include/openmc/string_functions.h b/include/openmc/string_functions.h index a3da179a0..acbbe4e1d 100644 --- a/include/openmc/string_functions.h +++ b/include/openmc/string_functions.h @@ -14,5 +14,7 @@ char* strtrim(char* c_str); void to_lower(std::string& str); +int word_count(std::string const& str); + } // namespace openmc #endif // STRING_FUNCTIONS_H diff --git a/src/string_functions.cpp b/src/string_functions.cpp index f81b09aef..6c077c8c0 100644 --- a/src/string_functions.cpp +++ b/src/string_functions.cpp @@ -1,4 +1,5 @@ #include "openmc/string_functions.h" +#include namespace openmc { @@ -27,4 +28,15 @@ void to_lower(std::string& str) for (int i = 0; i < str.size(); i++) str[i] = std::tolower(str[i]); } +int word_count(std::string const& str) { + std::stringstream stream(str); + std::string dum; + int count = 0; + while(stream >> dum) { count++; } + return count; +} + } // namespace openmc + + + diff --git a/src/surface.cpp b/src/surface.cpp index bf1c2e58c..f535615e8 100644 --- a/src/surface.cpp +++ b/src/surface.cpp @@ -35,24 +35,6 @@ std::map surface_map; // Helper functions for reading the "coeffs" node of an XML surface element //============================================================================== -int word_count(const std::string &text) -{ - bool in_word = false; - int count {0}; - for (auto c = text.begin(); c != text.end(); c++) { - if (std::isspace(*c)) { - if (in_word) { - in_word = false; - count++; - } - } else { - in_word = true; - } - } - if (in_word) count++; - return count; -} - void read_coeffs(pugi::xml_node surf_node, int surf_id, double &c1) { // Check the given number of coefficients.