i want to know what the following function is doing?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • amit129

    i want to know what the following function is doing?

    hi,

    Please tell me what the below mentined code is doing? If i pass String
    s as my name is "xyz. and " i am writing . what should be the output.

    Thanks in advance

    void parse(Block<Str ing>& f, String s)
    {
    int inquote = 0;
    int nf = 0;
    int start = -1;
    for(int i = 0; i <= length(s); i++){
    if(i == length(s) || (isspace(s[i]) && !inquote) || (s[i] == '"' &&
    inquote)){
    if(start != -1){
    nf++;
    f.reserve(nf);
    if(inquote && i != length(s))
    f[nf-1] = s(start,i-start+1);
    else
    f[nf-1] = s(start,i-start);
    start = -1;
    inquote = 0;
    }
    }
    else if(start == -1){
    start = i;
    inquote = (s[i] == '"');
    }
    }
    f.size(nf);
    }

    Amit
  • Jens Thoms Toerring

    #2
    Re: i want to know what the following function is doing?

    amit129 <rockiecool129@ gmail.comwrote:
    Please tell me what the below mentined code is doing? If i pass String
    s as my name is "xyz. and " i am writing . what should be the output.
    void parse(Block<Str ing>& f, String s)
    Why don't you put it into a simple program and just test what
    it does? Moreover, you picked the wrong newsgroup, this one is
    for C, not C++. The experts for C++ are on the other side of
    the hallway in comp.lang.c++.
    Regards, Jens
    --
    \ Jens Thoms Toerring ___ jt@toerring.de
    \______________ ____________ http://toerring.de

    Comment

    • Szabolcs Borsanyi

      #3
      Re: i want to know what the following function is doing?

      On Tue, May 27, 2008 at 03:13:31AM -0700, amit129 wrote:
      hi,
      >
      Please tell me what the below mentined code is doing? If i pass String
      s as my name is "xyz. and " i am writing . what should be the output.
      >
      Thanks in advance
      >
      void parse(Block<Str ing>& f, String s)
      Uups, you forgot to append a ++ to the newsgroup name. And please
      resist the temptation to think that C++ is C. Beleive or not,
      even your innocent looking '"' has very different meanings in the
      two languages, so the advice we could give will probably not apply to you
      problem.

      Szabolcs

      Comment

      Working...