]> git.saurik.com Git - apple/icu.git/blob - icuSources/test/intltest/textfile.h
ICU-511.27.tar.gz
[apple/icu.git] / icuSources / test / intltest / textfile.h
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 19 2004
8 * Since: ICU 3.0
9 **********************************************************************
10 */
11 #ifndef __ICU_INTLTEST_TEXTFILE__
12 #define __ICU_INTLTEST_TEXTFILE__
13
14 #include "intltest.h"
15 #include "filestrm.h"
16
17 /**
18 * This class implements access to a text data file located in the
19 * icu/source/test/testdata/ directory.
20 */
21 class TextFile {
22 public:
23 /**
24 * Open a file with the given name, in the given encoding, in the
25 * ICU testdata directory. See textfile.cpp to determine if the
26 * 'name' and 'encoding' parameters are aliased or copied.
27 */
28 TextFile(const char* name, const char* encoding, UErrorCode& ec);
29
30 virtual ~TextFile();
31
32 /**
33 * Read a line terminated by ^J or ^M or ^M^J, and convert it from
34 * this file's encoding to Unicode. The EOL character(s) are not
35 * included in 'line'.
36 * @return TRUE if a line was read, or FALSE if the EOF
37 * was reached or an error occurred
38 */
39 UBool readLine(UnicodeString& line, UErrorCode& ec);
40
41 /**
42 * Read a line, ignoring blank lines and lines that start with
43 * '#'. Trim leading white space.
44 * @param trim if TRUE then remove leading Pattern_White_Space
45 * @return TRUE if a line was read, or FALSE if the EOF
46 * was reached or an error occurred
47 */
48 UBool readLineSkippingComments(UnicodeString& line, UErrorCode& ec,
49 UBool trim = FALSE);
50
51 /**
52 * Return the line number of the last line returned by readLine().
53 */
54 inline int32_t getLineNumber() const;
55
56 private:
57 UBool ensureCapacity(int32_t capacity);
58 UBool setBuffer(int32_t index, char c, UErrorCode& ec);
59
60 FileStream* file;
61 char* name;
62 char* encoding;
63 char* buffer;
64 int32_t capacity;
65 int32_t lineNo;
66 };
67
68 inline int32_t TextFile::getLineNumber() const {
69 return lineNo;
70 }
71
72 #endif