Originally Posted by
tabstop
Why not use find to tell you where the \n character is, and pass that to substr?
Good idea. I didn't think of that.
Thanks.
So what I got is:
Code:
vector<string> C_script_operations::findJsFunctionsNames(string& scriptStr) {
vector<string> result_vec;
string search_str = "function";
string current_function_name;
size_t last_function_keyword_pos = scriptStr.find_last_of(search_str, scriptStr.size());
if (last_function_keyword_pos != string::npos) {
for (size_t i = scriptStr.find(search_str, 0); i < last_function_keyword_pos; i = scriptStr.find(search_str, i+1)) {
if (i != string::npos) {
current_function_name = stripStr(scriptStr.substr(scriptStr.find_last_of(search_str, i + search_str.size() - 1),
scriptStr.find('\n', i + search_str.size() - 1)), "function", "\n", 1, exclusive);
if (!current_function_name.empty()) {
removeSpcsFromStr(current_function_name);
result_vec.push_back(current_function_name);
}
}
}
}
return result_vec;
}
So I'm off now to go test my function...