12e5b6d6dSopenharmony_ci// © 2016 and later: Unicode, Inc. and others.
22e5b6d6dSopenharmony_ci// License & terms of use: http://www.unicode.org/copyright.html
32e5b6d6dSopenharmony_ci/*
42e5b6d6dSopenharmony_ci**********************************************************************
52e5b6d6dSopenharmony_ci* Copyright (c) 2004-2011, International Business Machines
62e5b6d6dSopenharmony_ci* Corporation and others.  All Rights Reserved.
72e5b6d6dSopenharmony_ci**********************************************************************
82e5b6d6dSopenharmony_ci* Author: Alan Liu
92e5b6d6dSopenharmony_ci* Created: March 19 2004
102e5b6d6dSopenharmony_ci* Since: ICU 3.0
112e5b6d6dSopenharmony_ci**********************************************************************
122e5b6d6dSopenharmony_ci*/
132e5b6d6dSopenharmony_ci#ifndef __ICU_INTLTEST_TEXTFILE__
142e5b6d6dSopenharmony_ci#define __ICU_INTLTEST_TEXTFILE__
152e5b6d6dSopenharmony_ci
162e5b6d6dSopenharmony_ci#include "intltest.h"
172e5b6d6dSopenharmony_ci#include "filestrm.h"
182e5b6d6dSopenharmony_ci
192e5b6d6dSopenharmony_ci/**
202e5b6d6dSopenharmony_ci * This class implements access to a text data file located in the
212e5b6d6dSopenharmony_ci * icu/source/test/testdata/ directory.
222e5b6d6dSopenharmony_ci */
232e5b6d6dSopenharmony_ciclass TextFile {
242e5b6d6dSopenharmony_ci public:
252e5b6d6dSopenharmony_ci    /**
262e5b6d6dSopenharmony_ci     * Open a file with the given name, in the given encoding, in the
272e5b6d6dSopenharmony_ci     * ICU testdata directory. See textfile.cpp to determine if the
282e5b6d6dSopenharmony_ci     * 'name' and 'encoding' parameters are aliased or copied.
292e5b6d6dSopenharmony_ci     */
302e5b6d6dSopenharmony_ci    TextFile(const char* name, const char* encoding, UErrorCode& ec);
312e5b6d6dSopenharmony_ci
322e5b6d6dSopenharmony_ci    virtual ~TextFile();
332e5b6d6dSopenharmony_ci
342e5b6d6dSopenharmony_ci    /**
352e5b6d6dSopenharmony_ci     * Read a line terminated by ^J or ^M or ^M^J, and convert it from
362e5b6d6dSopenharmony_ci     * this file's encoding to Unicode. The EOL character(s) are not
372e5b6d6dSopenharmony_ci     * included in 'line'.
382e5b6d6dSopenharmony_ci     * @return true if a line was read, or false if the EOF
392e5b6d6dSopenharmony_ci     * was reached or an error occurred
402e5b6d6dSopenharmony_ci     */
412e5b6d6dSopenharmony_ci    UBool readLine(UnicodeString& line, UErrorCode& ec);
422e5b6d6dSopenharmony_ci
432e5b6d6dSopenharmony_ci    /**
442e5b6d6dSopenharmony_ci     * Read a line, ignoring blank lines and lines that start with
452e5b6d6dSopenharmony_ci     * '#'.  Trim leading white space.
462e5b6d6dSopenharmony_ci     * @param trim if true then remove leading Pattern_White_Space
472e5b6d6dSopenharmony_ci     * @return true if a line was read, or false if the EOF
482e5b6d6dSopenharmony_ci     * was reached or an error occurred
492e5b6d6dSopenharmony_ci     */
502e5b6d6dSopenharmony_ci    UBool readLineSkippingComments(UnicodeString& line, UErrorCode& ec,
512e5b6d6dSopenharmony_ci                                   UBool trim = false);
522e5b6d6dSopenharmony_ci
532e5b6d6dSopenharmony_ci    /**
542e5b6d6dSopenharmony_ci     * Return the line number of the last line returned by readLine().
552e5b6d6dSopenharmony_ci     */
562e5b6d6dSopenharmony_ci    inline int32_t getLineNumber() const;
572e5b6d6dSopenharmony_ci
582e5b6d6dSopenharmony_ci private:
592e5b6d6dSopenharmony_ci    UBool ensureCapacity(int32_t capacity);
602e5b6d6dSopenharmony_ci    UBool setBuffer(int32_t index, char c, UErrorCode& ec);
612e5b6d6dSopenharmony_ci
622e5b6d6dSopenharmony_ci    FileStream* file;
632e5b6d6dSopenharmony_ci    char* name;
642e5b6d6dSopenharmony_ci    char* encoding;
652e5b6d6dSopenharmony_ci    char* buffer;
662e5b6d6dSopenharmony_ci    int32_t capacity;
672e5b6d6dSopenharmony_ci    int32_t lineNo;
682e5b6d6dSopenharmony_ci};
692e5b6d6dSopenharmony_ci
702e5b6d6dSopenharmony_ciinline int32_t TextFile::getLineNumber() const {
712e5b6d6dSopenharmony_ci    return lineNo;
722e5b6d6dSopenharmony_ci}
732e5b6d6dSopenharmony_ci
742e5b6d6dSopenharmony_ci#endif
75