On Sat, 2013-05-18,
sumi...@gmail.com wrote:
> I am getting below response from server -
>
> Main stream options:
> EncType1=H.264
> Resolution1=704*576
> KeyInterval1=50
> FrameRate1=25
> BitflowType1=VBR
> NormalBitrate1=2048
Lets assume for a moment the simplest possible grammar: the language
is a set of lines ended by CRLF. Each line is on the form
"foo=bar\r\n" with no whitespace anywhere. There are no "continuation
lines" like in HTTP or mail headers.
> Now I need to parse the parameter and its value, I have list of
> parameter in client, I just need the value of the parameter.
>
> I tried by using string operation and I used -
> string::find(), string::substr() and string::find_first_not_of() function
> and some how I have complete the code . and its working.
Note that the functions in <algorithm> are at least as useful as the
std::string member functions (which I find a bit hard to work with).
Also there's the stuff in <cctype>.
> the string for allowed_chars for find_first_not_of() ,
> "abcdefghijklmnopqrstuvvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.:=-1234567890*"
>
> but its very bulky code and need every time compare with each characters.
>
> please give me some batter idea for parsing .
>
> this should be my function -
> string value = getParamValue(const string& response,
> const string& paramName)
That interface says a few interesting things:
- You are not interested in the difference between "EncType1 isn't
mentioned in the response" and "EncType1 has an empty value".
- You're not interested in the same parameter name being listed twice.
- You have to start from scratch every time you get() a value -- the
work isn't split into one parsing step and one get(name) step. That
means less-than-optimal performance, but perhaps that doesn't
matter.
- You have some way to get the parameters, and nothing but the
parameters, into a single string. I often find that this part is a
bit inconvenient; better to parse line by line into some data
structure until you find end-of-parameters.