~ubuntu-branches/ubuntu/trusty/miwm/trusty

« back to all changes in this revision

Viewing changes to EStdStringTokenizer.h

  • Committer: Bazaar Package Importer
  • Author(s): Jari Aalto
  • Date: 2010-01-04 15:25:34 UTC
  • Revision ID: james.westby@ubuntu.com-20100104152534-l3fdvt162le460cv
Tags: upstream-1.1
ImportĀ upstreamĀ versionĀ 1.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifndef ESTDSTRINGTOKENIZER_H
 
2
#define ESTDSTRINGTOKENIZER_H
 
3
 
 
4
#include <string>
 
5
#include <queue>
 
6
 
 
7
        using std::string;
 
8
        /**
 
9
           EStdStringTokenizer:
 
10
 
 
11
           License: see the file LICENSE in this directory.
 
12
           Author: stephan@wanderinghorse.net
 
13
           
 
14
           Based heavily off of work by:
 
15
           
 
16
           Martin Jones (mjones@kde.org)
 
17
           Torben Weis (weis@kde.org)
 
18
           Waldo Bastian (bastian@kde.org)
 
19
 
 
20
           which i originally found as StringTokenizer in the KDE 1.x
 
21
           source tree. i have received explicit permission from each
 
22
           of those gentlemen to release the StringTokenizer code into
 
23
           into the Public Domain. (Many thanks to them for that
 
24
           permission, without which this whole library would
 
25
           necessarily be released under the GNU GPL.)
 
26
 
 
27
           This class is meant to be API- and behaviour-compatible
 
28
           with StringTokenizer. This implementation is, however, MUCH
 
29
           less efficient.
 
30
           
 
31
           EStdStringTokenizer tokenizes strings in a way which is
 
32
           consistent with the way a Unix shell does. This makes it
 
33
           appropriate for use in parsing many types of arbitrary user
 
34
           input, from command-line arguments to comma-separated
 
35
           files.
 
36
        */
 
37
        class EStdStringTokenizer
 
38
        {
 
39
        public:
 
40
                EStdStringTokenizer();
 
41
                ~EStdStringTokenizer();
 
42
 
 
43
                /**
 
44
                   str is split up at points matching any element in
 
45
                   separators. Adjecent separators in str are
 
46
                   interpreted as empty elements. Thus the string
 
47
                   "1;;3", separated by ";", has 3 tokens:
 
48
                   ("1","","3").
 
49
 
 
50
                   To collect the tokens, do this:
 
51
 
 
52
                   EStdStringTokenizer tok( "some string", " " );
 
53
                   while( tok.hasMoreTokens() ) cout << "Token: " << tok.nextToken() << endl;
 
54
                 */
 
55
                void tokenize( const string &str, const string &separators );
 
56
                /**
 
57
                   Returns the next token in our list.
 
58
                   Calling nextToken() when hasMoreTokens() returns
 
59
                   false has undefined behaviour.
 
60
                 */
 
61
                string nextToken();
 
62
                /**
 
63
                   Returns true if this object has more tokens to give you.
 
64
                */
 
65
                bool hasMoreTokens() const;
 
66
 
 
67
        private:
 
68
                typedef std::queue<std::string> queue_type;
 
69
                //EStringList m_list;
 
70
                queue_type m_list;
 
71
        };
 
72
 
 
73
#endif // ESTDSTRINGTOKENIZER_H
 
74