dgquvn / repo

1 stars 1 forks source link

strRead should be refactored #5

Closed jayjaybillings closed 7 years ago

jayjaybillings commented 7 years ago

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...

   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.