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