Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   Re: file overwrite data manipulation (http://www.velocityreviews.com/forums/t267745-re-file-overwrite-data-manipulation.html)

Chris Theis 06-26-2003 07:32 AM

Re: file overwrite data manipulation
 

"Lans Redmond" <lredmond@nyc.rr.com> wrote in message
news:pWuKa.6447$DF1.2587377@twister.nyc.rr.com...
> try looking at strtok function.
> it will parse ur string based on the delimiter you pass in (tilde), your
> parsed string will be the value, after the 5th token then just do a

memmove
> to change the data
>
>

Please don't top post!

You have to be aware that using strtok might result in some unwanted
side-effects because of its design. Before using it one should consider that
it holds its data in a static buffer which means that you can't use strtok
in two places at the same time, you're in trouble with multithreading, it
modifies the input sequence(!!!), it depends on reading lines, which means
that you have to introduce buffers big enough for the longest line and this
might lead to a waste of buffersize.

Thus it might be better to use some other tokenizer approach using
istreambuf_iterators or whatever. A simple tokenizer could look like this:

////////////////////////////////////////////////////////////////////////////
//
std::vector<std::string> TokenizeString( const std::string& Text, const
std::string& Delimiters )
// Tokenize a passed string with respect to the provided delimiters
//
// e.g.
// string Line = "this_dog_is mine";
// string Delimiters = " ,:_;#";
// vector<string> WordList = TokenizeString( Line, Delimiters );
////////////////////////////////////////////////////////////////////////////
//
{
std::vector<std::string> WordList;
std::string::size_type Begin, End;
std::string Word;
Begin = Text.find_first_not_of( Delimiters ); // skip blanks or whatever
one finds at the beginning
while( Begin != std::string::npos ) {
End = Text.find_first_of( Delimiters, Begin );
if( End == std::string::npos ) { // we'v reached the end without
finding another delimiter
End = Text.length();
}

Word.assign( Text.begin() + Begin, Text.begin() + End );
WordList.push_back( Word );
Begin = Text.find_first_not_of( Delimiters, End);
}
return WordList;
}

Regards
Chris




All times are GMT. The time now is 01:31 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.