diff --git a/src/include/ZividPython/Wrappers.h b/src/include/ZividPython/Wrappers.h index f4a7d1cb..443c5f7b 100644 --- a/src/include/ZividPython/Wrappers.h +++ b/src/include/ZividPython/Wrappers.h @@ -33,24 +33,24 @@ namespace ZividPython throw std::invalid_argument{ "String is empty." }; } - if(!isupper(upperCamelCase[0])) + if(!isupper(upperCamelCase.front())) { std::stringstream msg; msg << "First character of string: '" << upperCamelCase << "' is not capitalized"; throw std::invalid_argument{ msg.str() }; } + std::stringstream ss; - ss << char(tolower(upperCamelCase[0])); + ss << char(std::tolower(upperCamelCase.front())); - for(size_t i = 1; i < upperCamelCase.size(); ++i) + for(auto it = std::next(upperCamelCase.begin()); it != upperCamelCase.end(); it++) { - if(isupper(upperCamelCase[i])) + if(std::isupper(*it)) { - auto previous = i - 1; - auto next = i + 1; + const auto prev = it - 1; + const auto next = it + 1; - if(!isupper(upperCamelCase[previous]) - || (next < upperCamelCase.size() && !isupper(upperCamelCase[next]))) + if(std::islower(*prev) || (next != upperCamelCase.end() && std::islower(*next)) { ss << "_"; }