ilikecats567 / arduino

Automatically exported from code.google.com/p/arduino
Other
0 stars 0 forks source link

Add numerical parsing functions from Stream to String as well #893

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
The numeric parsing functions in Stream are useful, but they would be helpful 
in String as well.

Original issue reported on code.google.com by tom.i...@gmail.com on 20 Apr 2012 at 12:57

GoogleCodeExporter commented 9 years ago
I guess the question is what you consider as the current location in the 
"Stream" for the purposes of parsing.  Maybe we should add a StringStream 
object (or similar) that would let you treat a String as a Stream?  

Original comment by dmel...@gmail.com on 9 May 2012 at 1:03

GoogleCodeExporter commented 9 years ago
Current location in Stream should be the last byte I read or parsed. Again, I 
take TextFinder as my model, since it works well, and makes sense in terms of 
how it operates.

For String, though, it could be simpler. What I'm thinking of would be 
something that parses a string and pulls out the first legit number.  Classic 
use case would be something that reads values from a comma-separated value 
string.  given:

String foo = "23.5, 456, 123\r\n"

I want to do:

float first = foo.parseFloat();
float second = foo.parseFloat();
float third = foo.parseFloat();   //or parseInt

and get numeric values.

Original comment by tom.i...@gmail.com on 9 May 2012 at 11:01