strRead should be refactored to account for a number of different issues.
[ ] What is the purpose of strRead? It looks like it splits the line and then trims it. It is better to use the delimited version of "getLine" to do that. See the docs here: http://www.cplusplus.com/reference/string/string/getline/
[ ] The trim operations in strRead should be put into different functions - trimLeft() and trimRight().
[ ] strRead should be renamed readString. Best practices suggest that function names are verbObject, not objectVerb. However, given that the sole purpose of this function is to split the properties, you might call it splitString instead.
[ ] What happens if the input string does not contain "="?
Implementing these changes suggests that the body of the function would look something like...
string res; // Where the result is stored
if (s.find('=') > -1) {
stringstream inputStringStream(s);
trimLeft(trimRight(getLine(s,res,'=');
} else {
// Add some code to throw an exception, log an error, or otherwise complain that '=' was not found.
}
return res;
This isn't how you would want to implement it in code where you were doing a lot of string splitting because the branch is expensive. However, for a short input file this gives you the ability to handle errors in the input without undefined behavior.
strRead should be refactored to account for a number of different issues.
Implementing these changes suggests that the body of the function would look something like...
This isn't how you would want to implement it in code where you were doing a lot of string splitting because the branch is expensive. However, for a short input file this gives you the ability to handle errors in the input without undefined behavior.