1 /*
2 **********************************************************************
3 * Copyright (c) 2004-2011, International Business Machines
4 * Corporation and others.  All Rights Reserved.
5 **********************************************************************
6 * Author: Alan Liu
7 * Created: March 22 2004
8 * Since: ICU 3.0
9 **********************************************************************
10 */
11 #ifndef __ICU_INTLTEST_TOKITER__
12 #define __ICU_INTLTEST_TOKITER__
13 
14 #include "intltest.h"
15 
16 class TextFile;
17 
18 /**
19  * An iterator class that returns successive string tokens from some
20  * source.  String tokens are, in general, separated by Pattern_White_Space
21  * in the source test.  Furthermore, they may be delimited by
22  * either single or double quotes (opening and closing quotes must
23  * match).  Escapes are processed using standard ICU unescaping.
24  */
25 class TokenIterator {
26  public:
27 
28     /**
29      * Construct an iterator over the tokens returned by the given
30      * TextFile, ignoring blank lines and comment lines (first
31      * non-blank character is '#').  Note that trailing comments on a
32      * line, beginning with the first unquoted '#', are recognized.
33      */
34     TokenIterator(TextFile* r);
35 
36     virtual ~TokenIterator();
37 
38     /**
39      * Return the next token from this iterator.
40      * @return TRUE if a token was read, or FALSE if no more tokens
41      * are available or an error occurred.
42      */
43     UBool next(UnicodeString& token, UErrorCode& ec);
44 
45     /**
46      * Return the one-based line number of the line of the last token
47      * returned by next(). Should only be called after a call to
48      * next(); otherwise the return value is undefined.
49      */
50     int32_t getLineNumber() const;
51 
52     /**
53      * Return a string description of the position of the last line
54      * returned by readLine() or readLineSkippingComments().
55      */
56     //public String describePosition() {
57     //    return reader.describePosition() + ':' + (lastpos+1);
58     //}
59 
60  private:
61     UBool nextToken(UnicodeString& token, UErrorCode& ec);
62 
63     TextFile* reader; // alias
64     UnicodeString line;
65     UBool done;
66     UBool haveLine;
67     int32_t pos;
68     int32_t lastpos;
69 };
70 
71 #endif
72