mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-26 21:25:36 -04:00
Creating a common word_count functions for strings.
This commit is contained in:
parent
2bffc33452
commit
fea2c3cc04
3 changed files with 14 additions and 18 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
#include "openmc/string_functions.h"
|
||||
#include <sstream>
|
||||
|
||||
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
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -35,24 +35,6 @@ std::map<int, int> 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.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue