Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- template<class T>
- std::vector<std::string> MapEvaluator<T>::extractVariables(std::string expression) {
- expression = expression + " ";
- std::vector<std::string> variables = {};
- std::string substring;
- size_t consecutiveCharsCaps = 0;
- bool previousCharCaps = false;
- for (size_t i = 0; i < expression.length(); i++)
- {
- if (isCapital(expression[i]))
- {
- consecutiveCharsCaps++;
- previousCharCaps = true;
- }
- else {
- if(previousCharCaps) {
- substring = expression.substr(i - consecutiveCharsCaps, consecutiveCharsCaps);
- variables.push_back(substring);
- consecutiveCharsCaps = 0;
- previousCharCaps = false;
- }
- }
- }
- unique(variables);
- return variables;
- }
- template <class T>
- void MapEvaluator<T>::unique(std::vector<std::string> &vec)
- {
- auto end = vec.end();
- for (auto it = vec.begin(); it != end; ++it) {
- end = std::remove(it + 1, end, *it);
- }
- vec.erase(end, vec.end());
- }
- template<class T>
- bool MapEvaluator<T>::isCapital(char c) {
- return (c >='A' && c <= 'Z');
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement