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<String>& 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

Edited 3 Years Ago by Dani: Formatting fixed

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<String>& 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

How would we know what it does? We can't run it. You haven't given us all the code. What is Block<String>? What is the reserve(int) function? You haven't told us. Run it and see for yourself.

Also, please use code tags and formatting:

// paste code here

Edited 3 Years Ago by mike_2000_17: Fixed formatting

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<String>& 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

nobody is able to help you amid Block, String, length, isspace, reserve...

Edited 3 Years Ago by mike_2000_17: Fixed formatting

This article has been dead for over six months. Start a new discussion instead.