From: Christian Freund on
And what is wrong with 'strtok'? You take '/' separator and a while-loop to
iterate through ... That is not even c++.

"Ramon F Herrera" <ramon(a)conexus.net> schrieb im Newsbeitrag
news:27a01af4-cda4-4221-909c-a79ee34a3096(a)p8g2000yqb.googlegroups.com...
>
> The one facility I miss from Perl is 'split()'. What should I use to
> implement it in C++?
>
> My choices would be:
>
> - string operations such as .find() and .substr() and from there RYO.
>
> - something based on Boost::regex
>
> I need to break down a file path into its constituent subdirectories,
> and similar operations.
>
> Any other suggestions, comments?
>
> TIA,
>
> -Ramon
>
> RYO: Roll Your Own
>

From: Ronald Landheer-Cieslak on
Christian Freund wrote:
> And what is wrong with 'strtok'? You take '/' separator and a while-loop
> to iterate through ... That is not even c++.
IMO, there are plenty of things wrong with strtok, but the best reasons
why it should generally be avoided are listed here:
http://www.stanford.edu/~blp/writings/clc/strtok.html

rlc

>
> "Ramon F Herrera" <ramon(a)conexus.net> schrieb im Newsbeitrag
> news:27a01af4-cda4-4221-909c-a79ee34a3096(a)p8g2000yqb.googlegroups.com...
>>
>> The one facility I miss from Perl is 'split()'. What should I use to
>> implement it in C++?
>>
>> My choices would be:
>>
>> - string operations such as .find() and .substr() and from there RYO.
>>
>> - something based on Boost::regex
>>
>> I need to break down a file path into its constituent subdirectories,
>> and similar operations.
>>
>> Any other suggestions, comments?
>>
>> TIA,
>>
>> -Ramon
>>
>> RYO: Roll Your Own
>>
>


--
Ronald Landheer-Cieslak
Software Development Professional
http://landheer-cieslak.com
http://vlinder.ca

--- news://freenews.netfront.net/ - complaints: news(a)netfront.net ---
From: Christian Freund on
The only reasonable reason provided there, for tokenizing a filename with
always the same delmiter between directories, is the last one. That is
because it uses static buffers internally. -> So use strtok_s instead, in
your program that runs strtok in several instances parallely.

Anyways you are right, strtok is not the wisdoms last shot ;-) ... but ...
Just because a standard-function should not be used for every case, it is
daring to imply it should not be used for any case.

"Ronald Landheer-Cieslak" <ronald(a)landheer-cieslak.com> schrieb im
Newsbeitrag news:hk7okj$18di$1(a)adenine.netfront.net...
> Christian Freund wrote:
>> And what is wrong with 'strtok'? You take '/' separator and a while-loop
>> to iterate through ... That is not even c++.
> IMO, there are plenty of things wrong with strtok, but the best reasons
> why it should generally be avoided are listed here:
> http://www.stanford.edu/~blp/writings/clc/strtok.html
>
> rlc
>
>>
>> "Ramon F Herrera" <ramon(a)conexus.net> schrieb im Newsbeitrag
>> news:27a01af4-cda4-4221-909c-a79ee34a3096(a)p8g2000yqb.googlegroups.com...
>>>
>>> The one facility I miss from Perl is 'split()'. What should I use to
>>> implement it in C++?
>>>
>>> My choices would be:
>>>
>>> - string operations such as .find() and .substr() and from there RYO.
>>>
>>> - something based on Boost::regex
>>>
>>> I need to break down a file path into its constituent subdirectories,
>>> and similar operations.
>>>
>>> Any other suggestions, comments?
>>>
>>> TIA,
>>>
>>> -Ramon
>>>
>>> RYO: Roll Your Own
>>>
>>
>
>
> --
> Ronald Landheer-Cieslak
> Software Development Professional
> http://landheer-cieslak.com
> http://vlinder.ca
>
> --- news://freenews.netfront.net/ - complaints: news(a)netfront.net ---

From: Ronald Landheer-Cieslak on
Christian Freund wrote:
> The only reasonable reason provided there, for tokenizing a filename
> with always the same delmiter between directories, is the last one. That
> is because it uses static buffers internally. -> So use strtok_s
> instead, in your program that runs strtok in several instances parallely.
strtok_s is the Microsoft "safe" version of strtok. On other systems
(POSIX) there's strtok_r that does the same thing - a re-entrant strtok.
See http://www.linuxhowtos.org/manpages/3/strtok_r.htm, for example.

> Anyways you are right, strtok is not the wisdoms last shot ;-) ... but
> ... Just because a standard-function should not be used for every case,
> it is daring to imply it should not be used for any case.
I agree: if you know what you're doing and you're in a context where
it's safe to use strtok, there's no reason not to use it. The problem is
that these two preconditions don't always apply to some-one with only
strtok on their toolbelt: to a man with a hammer, everything may look
like a nail. So if I were to recommend a tool for tokenizing and C++ is
available, I'd rather go for boost::tokenizer than for strtok. If I
don't have the option for boost::tokenizer, there are still other
options that I'd go for rather than strtok if I have a chance - mostly
because I think that someone who needs to ask how to tokenize a string
probably doesn't have the proper tool for that yet, so I'd better show
them the safer tools first :)

rlc

>
> "Ronald Landheer-Cieslak" <ronald(a)landheer-cieslak.com> schrieb im
> Newsbeitrag news:hk7okj$18di$1(a)adenine.netfront.net...
>> Christian Freund wrote:
>>> And what is wrong with 'strtok'? You take '/' separator and a
>>> while-loop to iterate through ... That is not even c++.
>> IMO, there are plenty of things wrong with strtok, but the best
>> reasons why it should generally be avoided are listed here:
>> http://www.stanford.edu/~blp/writings/clc/strtok.html
>>
>> rlc
>>
>>>
>>> "Ramon F Herrera" <ramon(a)conexus.net> schrieb im Newsbeitrag
>>> news:27a01af4-cda4-4221-909c-a79ee34a3096(a)p8g2000yqb.googlegroups.com...
>>>>
>>>> The one facility I miss from Perl is 'split()'. What should I use to
>>>> implement it in C++?
>>>>
>>>> My choices would be:
>>>>
>>>> - string operations such as .find() and .substr() and from there RYO.
>>>>
>>>> - something based on Boost::regex
>>>>
>>>> I need to break down a file path into its constituent subdirectories,
>>>> and similar operations.
>>>>
>>>> Any other suggestions, comments?
>>>>
>>>> TIA,
>>>>
>>>> -Ramon
>>>>
>>>> RYO: Roll Your Own
>>>>
>>>
>>
>>
>> --
>> Ronald Landheer-Cieslak
>> Software Development Professional
>> http://landheer-cieslak.com
>> http://vlinder.ca
>>
>> --- news://freenews.netfront.net/ - complaints: news(a)netfront.net ---
>


--
Ronald Landheer-Cieslak
Software Development Professional
http://landheer-cieslak.com
http://vlinder.ca

--- news://freenews.netfront.net/ - complaints: news(a)netfront.net ---
From: Kaz Kylheku on
On 2010-02-02, Christian Freund <christian.freund(a)wrz.de> wrote:
> The only reasonable reason provided there, for tokenizing a filename with
> always the same delmiter between directories, is the last one. That is
> because it uses static buffers internally. -> So use strtok_s instead, in
> your program that runs strtok in several instances parallely.

The ISO C strtok function can be written as a wrapper around the function
strcspn and strspn.

See:

http://groups.google.com/group/comp.lang.c/msg/a97f2432bd5e8efd?dmode=source

Message ID: NbgU7.26524$ip4.508728(a)news2.calgary.shaw.ca