I see that ranges is primitive to organzie universal approach to write some algorithms. But I'm using algorithms from the library but I still can't start with writing my own algorithms based on ranges. For example I have the following function written without ranges. I want to improve it and make it working with different types of strings (char[], string, wchar[], etc...). So could someone give me an example how to rewrite this function in `range`-style?

//Parses HTML form data
dstring[dstring] parseFormData2(dstring queryStr)
{       size_t LexStart = 0;
        dstring curKey;
        dstring curValue;
        for( size_t i = 0; i < queryStr.length; ++i )
        {       if( queryStr[i] == '=' )
                {       curKey = queryStr[LexStart..i].idup;
                        curValue = null;
                        LexStart = i+1;
                }
                if( (queryStr[i] == '&') || (i+1 == queryStr.length) )
{ curValue = queryStr[ LexStart .. (i+1 == queryStr.length) ? ++i : i ].idup;
                        if( curKey.length > 0)
                        {       result[curKey] = curValue;
                                //result[curKey] ~= curValue;
                        }
                        curKey = null;
                        LexStart = i+1;
                }
        }
        return result;
}

Reply via email to