]>
Commit | Line | Data |
---|---|---|
f3c0d7a5 A |
1 | // © 2016 and later: Unicode, Inc. and others. |
2 | // License & terms of use: http://www.unicode.org/copyright.html | |
374ca955 A |
3 | /* |
4 | ********************************************************************** | |
4388f060 | 5 | * Copyright (c) 2004-2011, International Business Machines |
374ca955 A |
6 | * Corporation and others. All Rights Reserved. |
7 | ********************************************************************** | |
8 | * Author: Alan Liu | |
9 | * Created: March 19 2004 | |
10 | * Since: ICU 3.0 | |
11 | ********************************************************************** | |
12 | */ | |
13 | #ifndef __ICU_INTLTEST_TEXTFILE__ | |
14 | #define __ICU_INTLTEST_TEXTFILE__ | |
15 | ||
46f4442e | 16 | #include "intltest.h" |
374ca955 A |
17 | #include "filestrm.h" |
18 | ||
19 | /** | |
20 | * This class implements access to a text data file located in the | |
21 | * icu/source/test/testdata/ directory. | |
22 | */ | |
23 | class TextFile { | |
24 | public: | |
25 | /** | |
26 | * Open a file with the given name, in the given encoding, in the | |
27 | * ICU testdata directory. See textfile.cpp to determine if the | |
28 | * 'name' and 'encoding' parameters are aliased or copied. | |
29 | */ | |
30 | TextFile(const char* name, const char* encoding, UErrorCode& ec); | |
31 | ||
32 | virtual ~TextFile(); | |
33 | ||
34 | /** | |
35 | * Read a line terminated by ^J or ^M or ^M^J, and convert it from | |
36 | * this file's encoding to Unicode. The EOL character(s) are not | |
37 | * included in 'line'. | |
38 | * @return TRUE if a line was read, or FALSE if the EOF | |
39 | * was reached or an error occurred | |
40 | */ | |
41 | UBool readLine(UnicodeString& line, UErrorCode& ec); | |
42 | ||
43 | /** | |
44 | * Read a line, ignoring blank lines and lines that start with | |
45 | * '#'. Trim leading white space. | |
4388f060 | 46 | * @param trim if TRUE then remove leading Pattern_White_Space |
374ca955 A |
47 | * @return TRUE if a line was read, or FALSE if the EOF |
48 | * was reached or an error occurred | |
49 | */ | |
50 | UBool readLineSkippingComments(UnicodeString& line, UErrorCode& ec, | |
51 | UBool trim = FALSE); | |
52 | ||
53 | /** | |
54 | * Return the line number of the last line returned by readLine(). | |
55 | */ | |
56 | inline int32_t getLineNumber() const; | |
57 | ||
58 | private: | |
59 | UBool ensureCapacity(int32_t capacity); | |
60 | UBool setBuffer(int32_t index, char c, UErrorCode& ec); | |
61 | ||
62 | FileStream* file; | |
63 | char* name; | |
64 | char* encoding; | |
65 | char* buffer; | |
66 | int32_t capacity; | |
67 | int32_t lineNo; | |
68 | }; | |
69 | ||
70 | inline int32_t TextFile::getLineNumber() const { | |
71 | return lineNo; | |
72 | } | |
73 | ||
74 | #endif |