OpenCores
URL https://opencores.org/ocsvn/scarts/scarts/trunk

Subversion Repositories scarts

[/] [scarts/] [trunk/] [toolchain/] [scarts-gcc/] [gcc-4.1.1/] [libstdc++-v3/] [docs/] [html/] [21_strings/] [stringtok_std_h.txt] - Blame information for rev 20

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 20 jlechner
/*
2
 * Same as stringtok_h.txt, but doesn't (visiably) use C functions.
3
*/
4
 
5
#include 
6
 
7
// The std:: prefix is not used here, for readability, and a line like
8
// "using namespace std;" is dangerous to have in a header file.
9
 
10
template 
11
void
12
stringtok (Container &container, string const &in,
13
           const char * const delimiters = " \t\n")
14
{
15
    const string::size_type len = in.length();
16
          string::size_type i = 0;
17
 
18
    while ( i < len )
19
    {
20
        // eat leading whitespace
21
        i = in.find_first_not_of (delimiters, i);
22
        if (i == string::npos)
23
            return;   // nothing left but white space
24
 
25
        // find the end of the token
26
        string::size_type j = in.find_first_of (delimiters, i);
27
 
28
        // push token
29
        if (j == string::npos) {
30
            container.push_back (in.substr(i));
31
            return;
32
        } else
33
            container.push_back (in.substr(i, j-i));
34
 
35
        // set up for next loop
36
        i = j + 1;
37
    }
38
}
39
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.