diff --git a/stringutils.h b/stringutils.h index 1d14496..405f4fc 100644 --- a/stringutils.h +++ b/stringutils.h @@ -19,72 +19,72 @@ typedef std::vector stringvecvec; class stringUtils { public: - inline static std::string stripRComments(const std::string & rCode) - { - std::stringstream out; - - //Fixes https://github.com/jasp-stats/INTERNAL-jasp/issues/72 - //Gotta do some rudimentary parsing here... A comment starts with # and ends with newline, but if a # is inside a string then it doesn't start a comment... - //String are started with ' or " - - enum class status { R, Comment, SingleStr, DoubleStr }; - - status curStatus = status::R; - - for(size_t r=0; r splitString(const std::string & str, const char sep = ',') - { - std::vector vecString; - std::string item; - std::stringstream stringStream(str); - - while (std::getline(stringStream, item, sep)) - vecString.push_back(item); - - return vecString; - } + inline static std::string stripRComments(const std::string & rCode) + { + std::stringstream out; + + //Fixes https://github.com/jasp-stats/INTERNAL-jasp/issues/72 + //Gotta do some rudimentary parsing here... A comment starts with # and ends with newline, but if a # is inside a string then it doesn't start a comment... + //String are started with ' or " + + enum class status { R, Comment, SingleStr, DoubleStr }; + + status curStatus = status::R; + + for(size_t r=0; r splitString(const std::string & str, const char sep = ',') + { + std::vector vecString; + std::string item; + std::stringstream stringStream(str); + + while (std::getline(stringStream, item, sep)) + vecString.push_back(item); + + return vecString; + } inline static std::string toLower(std::string input) { @@ -94,23 +94,26 @@ class stringUtils inline static std::string replaceBy(std::string input, const std::string & replaceThis, const std::string & withThis) { - size_t oldLen = replaceThis.size(), - newLen = withThis.size(); + size_t oldLen = replaceThis.size(); - for(std::string::size_type curPos = input.find_first_of(replaceThis); curPos + oldLen < input.size() && curPos != std::string::npos; curPos = input.find_first_of(replaceThis, curPos)) - { + for ( std::string::size_type curPos = input.find(replaceThis) + ; curPos + oldLen <= input.size() && curPos != std::string::npos + ; curPos = input.find(replaceThis) + ) input.replace(curPos, oldLen, withThis); - curPos += newLen; - } return input; } inline static std::string escapeHtmlStuff(std::string input) { - input = replaceBy(input, "&", "&"); - input = replaceBy(input, "<", "<"); - input = replaceBy(input, ">", ">"); + input = replaceBy(input, "&", "&" ); + input = replaceBy(input, "<", "<" ); + input = replaceBy(input, ">", ">" ); + input = replaceBy(input, "<sub>", "" ); + input = replaceBy(input, "</sub>", ""); + input = replaceBy(input, "<sup>", "" ); + input = replaceBy(input, "</sup>", ""); return input; } @@ -196,7 +199,7 @@ class stringUtils } private: - stringUtils(); + stringUtils(); }; #endif // STRINGUTILS_H