* string.h - strsep
@ 2002-11-05 13:20 Ömer Rauf Atay
2002-11-05 15:19 ` Gokhan Kisacikoglu
2002-11-06 4:48 ` John Love-Jensen
0 siblings, 2 replies; 3+ messages in thread
From: Ömer Rauf Atay @ 2002-11-05 13:20 UTC (permalink / raw)
To: gcc-help
I think my string.h file does not include the strsep function.
My system is Sun Os 5.7 using gcc 2.95
I tried to use strtok instead but it simply skip the empty tokens.
Any comments?
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: string.h - strsep
2002-11-05 13:20 string.h - strsep Ömer Rauf Atay
@ 2002-11-05 15:19 ` Gokhan Kisacikoglu
2002-11-06 4:48 ` John Love-Jensen
1 sibling, 0 replies; 3+ messages in thread
From: Gokhan Kisacikoglu @ 2002-11-05 15:19 UTC (permalink / raw)
To: Ömer Rauf Atay; +Cc: gcc-help
> Any comments?
>
Using the <string> library from the standard templates instead; but you
will have to do some work. You can find more info at:
http://www.sgi.com/tech/stl/basic_string.html
For example, to tokenize a string;
#include <string>
#include <vector>
// headers necessary only for testing:
//
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
typedef vector <string> string_array;
unsigned int
tokenize(const string &_str,
const string &_delim,
string_array &_tokens )
{
_tokens = string_array();
if ( _str.empty() ) return 0;
for ( string :: size_type spos = 0;
spos != _str.size();
spos += _delim.size() )
{
string :: size_type epos = _str.find( _delim, spos );
if ( epos == string :: npos )
{
_tokens.push_back( string( _str, spos, epos ) );
break;
}
_tokens.push_back( string( _str, spos, epos-spos ) );
spos = epos;
}
return _tokens.size();
}
int main(void)
{
string_array tokens;
// test: 1
string str = "my string to be tokenized";
string delimiter = " ";
cout << "token count: "
<< tokenize( str, delimiter, tokens ) << endl;
copy( tokens.begin(), tokens.end(),
ostream_iterator <string> ( cout, "_" ) );
cout << endl;
// test: 2
cout << "token count: "
<< tokenize( "another string to-!be-!tokenized-!", "-!", tokens )
<< endl;
copy( tokens.begin(), tokens.end(),
ostream_iterator <string> ( cout, "_" ) );
cout << endl;
// test: 3
cout << "token count: "
<< tokenize( "", " ", tokens ) << endl;
copy( tokens.begin(), tokens.end(),
ostream_iterator <string> ( cout, "_" ) );
cout << endl;
}
Regards,
Gokhan
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: string.h - strsep
2002-11-05 13:20 string.h - strsep Ömer Rauf Atay
2002-11-05 15:19 ` Gokhan Kisacikoglu
@ 2002-11-06 4:48 ` John Love-Jensen
1 sibling, 0 replies; 3+ messages in thread
From: John Love-Jensen @ 2002-11-06 4:48 UTC (permalink / raw)
To: Ömer Rauf Atay, gcc-help
Hi Omer,
The strsep function is not a standard function.
Man page on strsep.
<http://www.neosoft.com/neosoft/man/strsep.3.html>
You'll have to write your own strsep from the man page spec, or solve your
parsing problem through different means.
I recommend the very cool, very schwing Spirit:
<http://spirit.sourceforge.net/index.php?doc=docs/v1_5/quick_start.html>
I think Spirit is either part of BOOST, or soon to be part of BOOST. A good
portion of BOOST is very likely to become part of the next C++ standard,
which is probably 5-10 years out.
<http://www.boost.org>
I suspect GCC, as usual, will be a leader in incorporating the "highly
likely" technology of the C++ Working Group for the next C++ standard.
Especially in the area of Generic Programming via improved template
facility. But keep in mind, those technologies are a moving target.
--Eljay
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2002-11-06 12:48 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-11-05 13:20 string.h - strsep Ömer Rauf Atay
2002-11-05 15:19 ` Gokhan Kisacikoglu
2002-11-06 4:48 ` John Love-Jensen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).