src/stream/ZUtil_Strim.h

00001 /*  @(#) $Id: ZUtil_Strim.h,v 1.10 2006/04/27 03:19:32 agreen Exp $ */
00002 
00003 /* ------------------------------------------------------------
00004 Copyright (c) 2003 Andrew Green and Learning in Motion, Inc.
00005 http://www.zoolib.org
00006 
00007 Permission is hereby granted, free of charge, to any person obtaining a copy
00008 of this software and associated documentation files (the "Software"), to deal
00009 in the Software without restriction, including without limitation the rights
00010 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00011 copies of the Software, and to permit persons to whom the Software is
00012 furnished to do so, subject to the following conditions:
00013 
00014 The above copyright notice and this permission notice shall be included in
00015 all copies or substantial portions of the Software.
00016 
00017 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00018 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00019 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00020 COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
00021 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
00022 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00023 ------------------------------------------------------------ */
00024 
00025 #ifndef __ZUtil_Strim__
00026 #define __ZUtil_Strim__ 1
00027 #include "zconfig.h"
00028 
00029 #include "ZStrim.h"
00030 #include "ZStrim_CRLF.h" // For ZStrimR_CRLFRemove
00031 #include "ZStrim_Stream.h" // For ZStrimR_StreamDecoder
00032 
00033 #include <stdexcept>
00034 
00035 // =================================================================================================
00036 #pragma mark -
00037 #pragma mark * ZUtil_Strim
00038 
00039 namespace ZUtil_Strim {
00040 
00041 class StrimU_Std : public ZStrimU
00042         {
00043 public:
00044         StrimU_Std(ZTextDecoder* iDecoder, const ZStreamR& iStreamR);
00045 
00046 // From ZStrimR via ZStrimU 
00047         virtual void Imp_ReadUTF32(UTF32* iDest, size_t iCount, size_t* oCount);
00048 
00049         virtual void Imp_ReadUTF16(UTF16* iDest,
00050                 size_t iCountCU, size_t* oCountCU, size_t iCountCP, size_t* oCountCP);
00051 
00052         virtual void Imp_ReadUTF8(UTF8* iDest,
00053                 size_t iCountCU, size_t* oCountCU, size_t iCountCP, size_t* oCountCP);
00054 
00055 // From ZStrimU
00056         virtual void Imp_Unread();
00057 
00058 // Our protocol
00059         void SetDecoder(ZTextDecoder* iDecoder);
00060         ZTextDecoder* SetDecoderReturnOld(ZTextDecoder* iDecoder);
00061 
00062         size_t GetLineCount();
00063         void ResetLineCount();
00064 
00065 private:
00066         ZStrimR_StreamDecoder fStrimR_StreamDecoder;
00067         ZStrimR_CRLFRemove fStrimR_CRLFRemove;
00068         enum { eStateFresh, eStateNormal, eStateUnread, eStateHitEnd } fState;
00069         UTF32 fCP;
00070         size_t fLineCount;
00071         };
00072 
00073 // =================================================================================================
00074 
00075 class ParseException : public std::runtime_error
00076         {
00077 public:
00078         ParseException(const char* iWhat) : runtime_error(iWhat) {}
00079         ParseException(const std::string& iWhat) : runtime_error(iWhat.c_str()) {}
00080         };
00081 
00082 // =================================================================================================
00083 
00084 void sCopy_WS(const ZStrimU& iStrimU, const ZStrimW& iDest);
00085 void sSkip_WS(const ZStrimU& iStrimU);
00086 
00087 
00088 void sCopy_WSAndCPlusPlusComments(const ZStrimU& iStrimU, const ZStrimW& iDest);
00089 void sSkip_WSAndCPlusPlusComments(const ZStrimU& iStrimU);
00090 
00091 
00092 void sCopy_Line(const ZStrimR& iStrimR, const ZStrimW& iDest);
00093 void sSkip_Line(const ZStrimR& iStrimR);
00094 string8 sRead_Line(const ZStrimR& iStrimR);
00095 
00096 
00097 bool sCopy_Until(const ZStrimR& iStrimR, UTF32 iTerminator, const ZStrimW& iDest);
00098 bool sSkip_Until(const ZStrimR& iStrimR, UTF32 iTerminator);
00099 string8 sRead_Until(const ZStrimR& iStrimR, UTF32 iTerminator);
00100 
00101 
00102 bool sCopy_Until(const ZStrimR& iStrimR, const string8& iTerminator, const ZStrimW& iDest);
00103 bool sSkip_Until(const ZStrimR& iStrimR, const string8& iTerminator);
00104 string8 sRead_Until(const ZStrimR& iStrimR, const string8& iTerminator);
00105 
00106 
00107 bool sTryRead_CP(const ZStrimU& iStrimU, UTF32 iCP);
00108 
00109 
00110 bool sTryRead_Digit(const ZStrimU& iStrimU, int& oDigit);
00111 bool sTryRead_HexDigit(const ZStrimU& iStrimU, int& oDigit);
00112 
00113 
00114 bool sTryRead_DecimalInteger(const ZStrimU& iStrimU, int64& oInteger);
00115 bool sTryRead_HexInteger(const ZStrimU& iStrimU, int64& oInteger);
00116 bool sTryRead_GenericInteger(const ZStrimU& iStrimU, int64& oInteger);
00117 bool sTryRead_Double(const ZStrimU& iStrimU, double& oDouble);
00118 
00119 bool sTryRead_SignedDecimalInteger(const ZStrimU& iStrimU, int64& oInteger);
00120 bool sTryRead_SignedDouble(const ZStrimU& iStrimU, double& oDouble);
00121 
00122 
00123 void sCopy_EscapedString(const ZStrimU& iStrimU, UTF32 iTerminator, const ZStrimW& iDest);
00124 void sRead_EscapedString(const ZStrimU& iStrimU, UTF32 iTerminator, string8& oString);
00125 
00126 
00127 bool sTryCopy_EscapedString(const ZStrimU& iStrimU, UTF32 iDelimiter, const ZStrimW& iDest);
00128 bool sTryRead_EscapedString(const ZStrimU& iStrimU, UTF32 iDelimiter, string8& oString);
00129 
00130 
00131 bool sTryCopy_Identifier(const ZStrimU& iStrimU, const ZStrimW& iDest);
00132 bool sTryRead_Identifier(const ZStrimU& iStrimU, string8& oString);
00133 // Other methods for other kinds of identifiers? -- Java, C++, Pascal, AlphaNum etc
00134 
00135 } // namespace ZUtil_Strim
00136 
00137 #endif // __ZUtil_Strim__

Generated on Thu Jul 26 11:21:56 2007 for ZooLib by  doxygen 1.4.7