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

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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.