Boost logo

Boost Users :

From: Boris Gubenko (Boris.Gubenko_at_[hidden])
Date: 2007-02-18 00:53:41


Boris Gubenko wrote:
> I may be overlooking something, and I hate to say it on the boost mailing
> list,
> but it seems to me that strcoll() C function does exactly what you need.
>

I think I know what I'm overlooking: the integers in your strings are not
all single-digit integers as in your examples. If this is correct, I retract
my strcoll() proposal. Sorry for the confusion.

Boris

----- Original Message -----
From: "Boris Gubenko" <Boris.Gubenko_at_[hidden]>
To: <boost-users_at_[hidden]>
Cc: "Boris Gubenko" <Boris.Gubenko_at_[hidden]>
Sent: Saturday, February 17, 2007 11:44 PM
Subject: Re: [Boost-users] Using Boost string library

>I may be overlooking something, and I hate to say it on the boost mailing list,
> but it seems to me that strcoll() C function does exactly what you need.
>
> Thanks,
> Boris
>
> ----- Original Message -----
> From: "Meryl Silverburgh" <silverburgh.meryl_at_[hidden]>
> To: <boost-users_at_[hidden]>
> Sent: Saturday, February 17, 2007 8:52 PM
> Subject: Re: [Boost-users] Using Boost string library
>
>
>> Thanks for your idea.
>>
>> I have cases like this:
>>
>> /1/1
>> /1/2/3/2
>>
>> Since the first string /1/1 is smaller than the /1/2 (1 is < 2) of the
>> /1/2/3/2, I should able to stop comparison by looking at the 4th
>> character (/1/2) of '/1/2/3/2'.
>>
>> So for cases like that, I would like to stop as soon as i can tell one
>> string is shorter than the other, instead of splitting the whole
>> string.
>>
>>
>>
>> On 2/17/07, Pavol Droba <droba_at_[hidden]> wrote:
>>> Hi,
>>>
>>> Meryl Silverburgh wrote:
>>> > Hi,
>>> >
>>> > I need to compare 2 strings in this format (a integer separator by '/':
>>> > /1/1
>>> > /1/1/2
>>> > /1/1/3
>>> >
>>> > so
>>> > "/1/1" is less than "/1/1/2" and "/1/1/2" is less than " "/1/1/3".
>>> >
>>> > Is there anything in Boost string library to help me to write such a
>>> > comparison?
>>> > Is there a string iterator which literates base on the separator '/'?
>>> > My idea is to find an iterator to loop thru the string based on
>>> > separator '/'.
>>>
>>> There is a split_iterator which you can use. And there is a generic
>>> lexicographical_compare function.
>>>
>>> I've got an idea that might work. But it is a little elaborate.
>>> First, tokenize your string using split, but store the result to
>>> vector<iterator_range>.
>>>
>>> Then define a comparison function, that will take the two
>>> iterator_ranges and compare them. Note, that in this case, tha range
>>> should hold an integer string.
>>> Then simply use lexicographical_compare for the comparison.
>>>
>>>
>>> vector<iterator_range> vec1;
>>> split(vec, s1);
>>> vector<iterator_range> vec2;
>>> split(vec, s2);
>>> if(lexicographical_compare(vec1, vec2, integer_compare))
>>> {
>>> // s1 is less
>>> }
>>>
>>> You can even throw away the vector, and directly create an
>>> iterator_range from the split_iterator. This way you may spare some
>>> unnecessary tokenization.
>>>
>>> typedef split_iterator<string::const_iterator> string_split;
>>> iterator_range<string_split> r1(
>>> make_split_iterator(s1, is_any_of("/")), string_split())
>>>
>>> iterator_range<string_split> r2(
>>> make_split_iterator(s2, is_any_of("/")), string_split())
>>>
>>> if(lexicographical_compare(vec1, vec2, integer_compare))
>>> {
>>> // s1 is less
>>> }
>>>
>>> Best Regards,
>>> Pavol.
>>> _______________________________________________
>>> Boost-users mailing list
>>> Boost-users_at_[hidden]
>>> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>>>
>> _______________________________________________
>> Boost-users mailing list
>> Boost-users_at_[hidden]
>> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>>
>>
>
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>
>


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net