//============================================================================== // intextstream.hpp // Generic input text stream. // // Notice // Copyright ©2008 by David R. Tribble, all rights reserved. // Permission is granted to any person or entity except those designated // by the United States Department of State as a terrorist, or terrorist // government or agency, to use and distribute this source code provided // that the original copyright notice remains present and unaltered. //============================================================================== #ifndef drt_lib_intextstream_hpp #define drt_lib_intextstream_hpp 102 // Identification #ifndef NO_H_IDENT static char drt_lib_intextstream_hpp_REV[] = "@(#)drt/src/lib/intextstream.hpp $Revision: 1.2 $$Date: 2008/12/13 16:31:41 $"; #endif // Includes #ifndef sys_stdio_h #include #define sys_stdio_h #endif #ifndef drt_lib_textstream_hpp #include "textstream.hpp" #endif //------------------------------------------------------------------------------ // class InTextStream // Controls the reading of data for an input text file. // // Handles the following file encodings: // 8-bit (ASCII or ISO 8859-1) // UTF-8 // UTF-16 (big-endian) // UTF-16 reversed (little-endian) // UTF-32 (big-endian) // UTF-32 reversed (little-endian) // 24-bit (big-endian) (non-standard) // 24-bit reversed (little-endian) (non-standard) // // Handles the following newline sequences: // CR (0D) // LF (0A) // CR LF (0D 0A) // NEL (85) // Any // None //------------------------------------------------------------------------------ #define InTextStream_VS 201 // Class version class InTextStream: public TextStream { #if TextStream_VS/100 != 2 #error class TextStream has changed #endif // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ // Static functions private: static int get_8bit(FILE *in); // Read an 8-bit char static int get_7bit(FILE *out); // Read a 7-bit char w/ parity static int get_utf8(FILE *in); // Read a UTF-8 char static int get_utf16(FILE *in); // Read a UTF-16BE char static int get_utf16r(FILE *in); // Read a UTF-16LE char static int get_utf32(FILE *in); // Read a UTF-32BE char static int get_utf32r(FILE *in); // Read a UTF-32LE char static int get_24bit(FILE *in); // Read a 24-bit BE char static int get_24bitr(FILE *in); // Read a 24-bit LE char // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ // Functions public: virtual /**/ ~InTextStream(); // Destructor /**/ InTextStream(); // Constructor virtual bool open(const char *fname, enum FileType ftype, enum EolnType eoln); // Open a file stream virtual bool open(FILE *fp, enum FileType ftype, enum EolnType eoln); // Open an I/O stream virtual bool close(); // Close the stream int read(); // Read a Unicode char int read(int buf[], int len); // Read Unicode chars private: /**/ InTextStream(const TextStream &o); const InTextStream & operator =(const InTextStream &o); bool openPrep(enum FileType ftype, enum EolnType eoln); // Prepare to open a stream // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ // Variables protected: int (*m_get)(FILE *in); // Read a char int m_ungetCh; // Push-back char }; #endif // drt_lib_intextstream_hpp // End intextstream.hpp