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