Newer
Older
* Copyright 1999-2001,2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Revision 1.20 2004/09/29 00:24:01 knoaman
* Performance: improve src offset calculation. Patch by Anthony O'Dowd.
*
* Revision 1.19 2004/09/08 13:56:14 peiyongz
* Apache License Version 2.0
*
* Revision 1.18 2004/06/15 15:51:21 peiyongz
* Compilation error on (AIX, Solaris) solved
*
* Revision 1.17 2004/06/14 15:18:53 peiyongz
* Consolidated End Of Line Handling
*
* Revision 1.16 2004/06/03 15:38:27 peiyongz
* XML1.1: The characters #x85 and #x2028 cannot be reliably recognized
* and translated until an entity's encoding declaration (if present) has been
* read. Therefore, it is a fatal error to use them within the XML declaration or
* text declaration.
*
David Abram Cargill
committed
* Revision 1.15 2004/01/29 11:46:30 cargilld
* Code cleanup changes to get rid of various compiler diagnostic messages.
*
Khaled Noaman
committed
* Revision 1.14 2003/05/16 21:36:58 knoaman
* Memory manager implementation: Modify constructors to pass in the memory manager.
*
* Revision 1.13 2003/05/15 18:26:29 knoaman
* Partial implementation of the configurable memory manager.
*
* Revision 1.12 2003/01/27 16:50:27 knoaman
* some cleanup.
*
* Revision 1.10 2002/12/11 22:09:08 knoaman
* Performance: reduce instructions count.
*
* Revision 1.9 2002/12/03 15:31:19 knoaman
* Enable/disable calculation of src offset.
*
* Revision 1.8 2002/12/02 17:20:05 knoaman
* Remove unused data member.
*
* Revision 1.7 2002/11/28 19:19:12 knoaman
* Performance: remove unnecessary if condition.
*
* Revision 1.6 2002/11/28 18:17:22 knoaman
* Performance: make getNextChar/peekNextChar inline.
*
* Revision 1.5 2002/11/25 21:31:08 tng
* Performance:
* 1. use XMLRecognizer::Encodings enum to make new transcode, faster than comparing the encoding string every time.
* 2. Pre uppercase the encodingString before calling encodingForName to avoid calling compareIString
*
* Revision 1.4 2002/11/04 14:58:19 tng
* C++ Namespace Support.
*
* Revision 1.3 2002/09/27 12:56:23 tng
* [Bug 12740] Extra include. By Peter Volchek.
*
Tinny Ng
committed
* Revision 1.2 2002/05/27 18:42:14 tng
* To get ready for 64 bit large file, use XMLSSize_t to represent line and column number.
*
* Revision 1.1.1.1 2002/02/01 22:22:02 peiyongz
* sane_include
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
*
* Revision 1.18 2001/12/06 17:47:04 tng
* Performance Enhancement. Modify the handling of the fNEL option so that it results in fgCharCharsTable being modified, instead of having all of the low-level routines check the option. This seemed acceptable because the code appears to only permit the option to be turned on and not turned off again. By Henry Zongaro.
*
* Revision 1.17 2001/07/12 18:50:13 tng
* Some performance modification regarding standalone check and xml decl check.
*
* Revision 1.16 2001/05/11 13:26:17 tng
* Copyright update.
*
* Revision 1.15 2001/05/03 18:42:51 knoaman
* Added new option to the parsers so that the NEL (0x85) char can be treated as a newline character.
*
* Revision 1.14 2001/01/25 19:16:58 tng
* const should be used instead of static const. Fixed by Khaled Noaman.
*
* Revision 1.13 2000/07/25 22:33:05 aruna1
* Char definitions in XMLUni moved to XMLUniDefs
*
* Revision 1.12 2000/07/08 00:17:13 andyh
* Cleanup of yesterday's speedup changes. Merged new bit into the
* scanner character properties table.
*
* Revision 1.11 2000/07/07 01:08:44 andyh
* Parser speed up in scan of XML content.
*
* Revision 1.10 2000/07/06 21:00:52 jpolast
* inlined getNextCharIfNot() for better performance
*
* Revision 1.9 2000/05/11 23:11:33 andyh
* Add missing validity checks for stand-alone documents, character range
* and Well-formed parsed entities. Changes contributed by Sean MacRoibeaird
* <sean.Macroibeaird@ireland.sun.com>
*
* Revision 1.8 2000/03/02 19:54:29 roddey
* This checkin includes many changes done while waiting for the
* 1.1.0 code to be finished. I can't list them all here, but a list is
* available elsewhere.
*
* Revision 1.7 2000/02/24 20:18:07 abagchi
* Swat for removing Log from API docs
*
* Revision 1.6 2000/02/06 07:47:53 rahulj
* Year 2K copyright swat.
*
* Revision 1.5 2000/01/25 01:04:21 roddey
* Fixes a bogus error about ]]> in char data.
*
* Revision 1.4 2000/01/22 00:01:08 roddey
* Simple change to get rid of two hard coded 'x' type characters, which won't
* work on EBCDIC systems.
*
* Revision 1.3 1999/12/18 00:20:00 roddey
* More changes to support the new, completely orthagonal, support for
* intrinsic encodings.
*
* Revision 1.2 1999/12/15 19:48:03 roddey
* Changed to use new split of transcoder interfaces into XML transcoders and
* LCP transcoders, and implementation of intrinsic transcoders as pluggable
* transcoders, and addition of Latin1 intrinsic support.
*
* Revision 1.1.1.1 1999/11/09 01:08:22 twl
* Initial checkin
*
* Revision 1.3 1999/11/08 20:44:47 rahul
* Swat for adding in Product name and CVS comment log variable.
*
*/
#if !defined(XMLREADER_HPP)
#define XMLREADER_HPP
#include <xercesc/framework/XMLRecognizer.hpp>
#include <xercesc/framework/XMLBuffer.hpp>
#include <xercesc/util/TranscodingException.hpp>
class InputSource;
class BinInputStream;
class ReaderMgr;
class XMLScanner;
class XMLTranscoder;
// ---------------------------------------------------------------------------
// Instances of this class are used to manage the content of entities. The
// scanner maintains a stack of these, one for each entity (this means entity
// in the sense of any parsed file or internal entity) currently being
// scanned. This class, given a binary input stream will handle reading in
// the data and decoding it from its external decoding into the internal
// Unicode format. Once internallized, this class provides the access
// methods to read in the data in various ways, maintains line and column
// information, and provides high performance character attribute checking
// methods.
//
// This is NOT to be derived from.
//
// ---------------------------------------------------------------------------
class XMLPARSER_EXPORT XMLReader : public XMemory
{
public:
// -----------------------------------------------------------------------
// Public types
// -----------------------------------------------------------------------
enum Types
{
Type_PE
, Type_General
};
enum Sources
{
Source_Internal
, Source_External
};
enum RefFrom
{
RefFrom_Literal
, RefFrom_NonLiteral
};
enum XMLVersion
{
XMLV1_0
, XMLV1_1
, XMLV_Unknown
};
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
(
const XMLCh* const toCheck
, const unsigned int count
);
(
const XMLCh* const toCheck
, const unsigned int count
);
bool isXMLLetter(const XMLCh toCheck);
bool isFirstNameChar(const XMLCh toCheck);
bool isNameChar(const XMLCh toCheck);
bool isPlainContentChar(const XMLCh toCheck);
bool isSpecialStartTagChar(const XMLCh toCheck);
bool isXMLChar(const XMLCh toCheck);
bool isWhitespace(const XMLCh toCheck);
bool isControlChar(const XMLCh toCheck);
bool isPublicIdChar(const XMLCh toCheck);
// -----------------------------------------------------------------------
// Constructors and Destructor
// -----------------------------------------------------------------------
XMLReader
(
Khaled Noaman
committed
const XMLCh* const pubId
, const XMLCh* const sysId
, BinInputStream* const streamToAdopt
, const RefFrom from
, const Types type
, const Sources source
, const bool throwAtEnd = false
, const bool calculateSrcOfs = true
, const XMLVersion xmlVersion = XMLV1_0
, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
Khaled Noaman
committed
const XMLCh* const pubId
, const XMLCh* const sysId
, BinInputStream* const streamToAdopt
, const XMLCh* const encodingStr
, const RefFrom from
, const Types type
, const Sources source
, const bool throwAtEnd = false
, const bool calculateSrcOfs = true
, const XMLVersion xmlVersion = XMLV1_0
, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
Khaled Noaman
committed
const XMLCh* const pubId
, const XMLCh* const sysId
, BinInputStream* const streamToAdopt
, XMLRecognizer::Encodings encodingEnum
, const RefFrom from
, const Types type
, const Sources source
, const bool throwAtEnd = false
, const bool calculateSrcOfs = true
, const XMLVersion xmlVersion = XMLV1_0
, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
~XMLReader();
// -----------------------------------------------------------------------
// Character buffer management methods
// -----------------------------------------------------------------------
unsigned long charsLeftInBuffer() const;
bool refreshCharBuffer();
// -----------------------------------------------------------------------
// Scanning methods
// -----------------------------------------------------------------------
bool getName(XMLBuffer& toFill, const bool token);
bool getNextChar(XMLCh& chGotten);
bool getNextCharIfNot(const XMLCh chNotToGet, XMLCh& chGotten);
void movePlainContentChars(XMLBuffer &dest);
bool getSpaces(XMLBuffer& toFill);
bool getUpToCharOrWS(XMLBuffer& toFill, const XMLCh toCheck);
bool peekNextChar(XMLCh& chGotten);
bool skipIfQuote(XMLCh& chGotten);
bool skipSpaces(bool& skippedSomething, bool inDecl = false);
bool skippedChar(const XMLCh toSkip);
bool skippedSpace();
bool skippedString(const XMLCh* const toSkip);
bool peekString(const XMLCh* const toPeek);
// -----------------------------------------------------------------------
// Getter methods
// -----------------------------------------------------------------------
Tinny Ng
committed
XMLSSize_t getColumnNumber() const;
Tinny Ng
committed
XMLSSize_t getLineNumber() const;
bool getNoMoreFlag() const;
const XMLCh* getPublicId() const;
unsigned int getReaderNum() const;
RefFrom getRefFrom() const;
Sources getSource() const;
unsigned int getSrcOffset() const;
const XMLCh* getSystemId() const;
bool getThrowAtEnd() const;
Types getType() const;
// -----------------------------------------------------------------------
// Setter methods
// -----------------------------------------------------------------------
bool setEncoding
(
const XMLCh* const newEncoding
);
void setReaderNum(const unsigned int newNum);
void setThrowAtEnd(const bool newValue);
David Abram Cargill
committed
// -----------------------------------------------------------------------
// Unimplemented constructors and operators
// -----------------------------------------------------------------------
XMLReader(const XMLReader&);
XMLReader& operator=(const XMLReader&);
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
// ---------------------------------------------------------------------------
// Class Constants
//
// kCharBufSize
// The size of the character spool buffer that we use. Its not terribly
// large because its just getting filled with data from a raw byte
// buffer as we go along. We don't want to decode all the text at
// once before we find out that there is an error.
//
// NOTE: This is a size in characters, not bytes.
//
// kRawBufSize
// The size of the raw buffer from which raw bytes are spooled out
// as we transcode chunks of data. As it is emptied, it is filled back
// in again from the source stream.
// ---------------------------------------------------------------------------
enum Constants
{
kCharBufSize = 16 * 1024
, kRawBufSize = 48 * 1024
};
// -----------------------------------------------------------------------
// Private helper methods
// -----------------------------------------------------------------------
void checkForSwapped();
void doInitCharSizeChecks();
void doInitDecode();
XMLByte getNextRawByte
(
const bool eoiOk
);
void refreshRawBuffer();
void setTranscoder
(
const XMLCh* const newEncoding
);
unsigned int xcodeMoreChars
(
XMLCh* const bufToFill
, unsigned char* const charSizes
, const unsigned int maxChars
);
inline void handleEOL
(
XMLCh& curCh
, bool inDecl = false
);
// -----------------------------------------------------------------------
// Data members
//
// fCharIndex
// The index into the character buffer. When this hits fCharsAvail
// then its time to refill.
//
// fCharBuf
// A buffer that the reader manager fills up with transcoded
// characters a small amount at a time.
//
// fCharsAvail
// The characters currently available in the character buffer.
//
// fCharSizeBuf
// This buffer is an array that contains the number of source chars
// eaten to create each char in the fCharBuf buffer. So the entry
// fCharSizeBuf[x] is the number of source chars that were eaten
// to make the internalized char fCharBuf[x]. This only contains
// useful data if fSrcOfsSupported is true.
//
// fCharOfsBuf
// This buffer is an array that contains the offset in the
// fRawByteBuf buffer of each char in the fCharBuf buffer. It
// only contains useful data if fSrcOfsSupported is true.
//
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
// fCurCol
// fCurLine
// The current line and column that we are in within this reader's
// text.
//
// fEncoding
// This is the rough encoding setting. This enum is set during
// construction and just tells us the rough family of encoding that
// we are doing.
//
// fEncodingStr
// This is the name of the encoding we are using. It will be
// provisionally set during construction, from the auto-sensed
// encoding. But it might be overridden when the XMLDecl is finally
// seen by the scanner. It can also be forced to a particular
// encoding, in which case fForcedEncoding is set.
//
// fForcedEncoding
// If the encoding if forced then this is set and all other
// information will be ignored. This encoding will be taken as
// gospel. This is done by calling an alternate constructor.
//
// fNoMore
// This is set when the source text is exhausted. It lets us know
// quickly that no more text is available.
//
// fRawBufIndex
// The current index into the raw byte buffer. When its equal to
// fRawBytesAvail then we need to read another buffer.
//
// fRawByteBuf
// This is the raw byte buffer that is used to spool out bytes
// from into the fCharBuf buffer, as we transcode in blocks.
//
// fRawBytesAvail
// The number of bytes currently available in the raw buffer. This
// helps deal with the last buffer's worth, which will usually not
// be a full one.
//
// fReaderNum
// Each reader from a particular reader manager (which means from a
// particular document) is given a unique number. The reader manager
// sets these numbers. They are used to catch things like partial
// markup errors.
//
// fRefFrom
// This flag is provided in the ctor, and tells us if we represent
// some entity being expanded inside a literal. Sometimes things
// happen differently inside and outside literals.
//
// fPublicId
// fSystemId
// These are the system and public ids of the source that this
// reader is reading.
//
// fSentTrailingSpace
// If we are a PE entity being read and we not referenced from a
// literal, then a leading and trailing space must be faked into the
// data. This lets us know we've done the trailing space already (so
// we don't just keep doing it again and again.)
//
// fSource
// Indicates whether the content this reader is spooling as already
// been internalized. This will prevent multiple processing of
// whitespace when an already internalized entity is being spooled
// out.
//
// fSpareChar
// Some encodings can create two chars in an atomic way, e.g.
// surrogate pairs. We might not be able to store both, so we store
// it here until the next buffer transcoding operation.
//
// fSrcOfsBase
// This is the base offset within the source of this entity. Values
// in the curent fCharSizeBuf array are relative to this value.
//
// fSrcOfsSupported
// This flag is set to indicate whether source byte offset info
// is supported. For intrinsic encodings, its always set since we
// can always support it. For transcoder based encodings, we ask
// the transcoder if it supports it or not.
//
// fStream
// This is the input stream that provides the data for the reader.
// Its always treated as a raw byte stream. The derived class will
// ask for buffers of text from it and will handle making some
// sense of it.
//
// fSwapped
// If the encoding is one of the ones we do intrinsically, and its
// in a different byte order from our native order, then this is
// set to remind us to byte swap it during transcoding.
//
// fThrowAtEnd
// Indicates whether the reader manager should throw an end of entity
// exception at the end of this reader instance. This is usually
// set for top level external entity references. It overrides the
// reader manager's global flag that controls throwing at the end
// of entities. Defaults to false.
//
// fTranscoder
// If the encoding is not one that we handle intrinsically, then
// we use an an external transcoder to do it. This class is an
// abstraction that allows us to use pluggable external transcoding
// services (via XMLTransService in util.)
//
// fType
// Indicates whether this reader represents a PE or not. If this
// flag is true and the fInLiteral flag is false, then we will put
// out an extra space at the end.
//
// fgCharCharsTable;
// Pointer to XMLChar table, depends on XML version
//
// fNEL
// Boolean indicates if NEL and LSEP should be recognized as NEL
//
// fXMLVersion
// Enum to indicate if this Reader is conforming to XML 1.0 or XML 1.1
// -----------------------------------------------------------------------
unsigned int fCharIndex;
XMLCh fCharBuf[kCharBufSize];
unsigned int fCharsAvail;
unsigned char fCharSizeBuf[kCharBufSize];
unsigned int fCharOfsBuf[kCharBufSize];
Tinny Ng
committed
XMLSSize_t fCurCol;
XMLSSize_t fCurLine;
XMLRecognizer::Encodings fEncoding;
XMLCh* fEncodingStr;
bool fForcedEncoding;
bool fNoMore;
XMLCh* fPublicId;
unsigned int fRawBufIndex;
XMLByte fRawByteBuf[kRawBufSize];
unsigned int fRawBytesAvail;
unsigned int fReaderNum;
RefFrom fRefFrom;
bool fSentTrailingSpace;
Sources fSource;
unsigned int fSrcOfsBase;
bool fSrcOfsSupported;
XMLCh* fSystemId;
BinInputStream* fStream;
bool fSwapped;
bool fThrowAtEnd;
XMLTranscoder* fTranscoder;
Types fType;
XMLByte* fgCharCharsTable;
bool fNEL;
XMLVersion fXMLVersion;
MemoryManager* fMemoryManager;
};
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
inline bool XMLReader::isNameChar(const XMLCh toCheck)
{
return ((fgCharCharsTable[toCheck] & gNameCharMask) != 0);
}
inline bool XMLReader::isPlainContentChar(const XMLCh toCheck)
{
return ((fgCharCharsTable[toCheck] & gPlainContentCharMask) != 0);
}
}
inline bool XMLReader::isSpecialStartTagChar(const XMLCh toCheck)
{
return ((fgCharCharsTable[toCheck] & gSpecialStartTagCharMask) != 0);
}
inline bool XMLReader::isXMLChar(const XMLCh toCheck)
{
return ((fgCharCharsTable[toCheck] & gXMLCharMask) != 0);
}
inline bool XMLReader::isXMLLetter(const XMLCh toCheck)
{
}
inline bool XMLReader::isWhitespace(const XMLCh toCheck)
{
return ((fgCharCharsTable[toCheck] & gWhitespaceCharMask) != 0);
}
inline bool XMLReader::isControlChar(const XMLCh toCheck)
{
return ((fgCharCharsTable[toCheck] & gControlCharMask) != 0);
}
// ---------------------------------------------------------------------------
// XMLReader: Buffer management methods
// ---------------------------------------------------------------------------
inline unsigned long XMLReader::charsLeftInBuffer() const
{
return fCharsAvail - fCharIndex;
}
// ---------------------------------------------------------------------------
// XMLReader: Getter methods
// ---------------------------------------------------------------------------
Tinny Ng
committed
inline XMLSSize_t XMLReader::getColumnNumber() const
{
return fCurCol;
}
inline const XMLCh* XMLReader::getEncodingStr() const
{
return fEncodingStr;
}
Tinny Ng
committed
inline XMLSSize_t XMLReader::getLineNumber() const
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
{
return fCurLine;
}
inline bool XMLReader::getNoMoreFlag() const
{
return fNoMore;
}
inline const XMLCh* XMLReader::getPublicId() const
{
return fPublicId;
}
inline unsigned int XMLReader::getReaderNum() const
{
return fReaderNum;
}
inline XMLReader::RefFrom XMLReader::getRefFrom() const
{
return fRefFrom;
}
inline XMLReader::Sources XMLReader::getSource() const
{
return fSource;
}
inline const XMLCh* XMLReader::getSystemId() const
{
return fSystemId;
}
inline bool XMLReader::getThrowAtEnd() const
{
return fThrowAtEnd;
}
inline XMLReader::Types XMLReader::getType() const
{
return fType;
}
// ---------------------------------------------------------------------------
// XMLReader: Setter methods
// ---------------------------------------------------------------------------
inline void XMLReader::setReaderNum(const unsigned int newNum)
{
fReaderNum = newNum;
}
inline void XMLReader::setThrowAtEnd(const bool newValue)
{
fThrowAtEnd = newValue;
}
inline void XMLReader::setXMLVersion(const XMLVersion version)
{
fXMLVersion = version;
if (version == XMLV1_1) {
fNEL = true;
fgCharCharsTable = XMLChar1_1::fgCharCharsTable1_1;
}
else {
fNEL = XMLChar1_0::enableNEL;
fgCharCharsTable = XMLChar1_0::fgCharCharsTable1_0;
}
}
// ---------------------------------------------------------------------------
//
// XMLReader: movePlainContentChars()
//
// Move as many plain (no special handling of any sort required) content
// characters as possible from this reader to the supplied destination buffer.
//
// This is THE hottest performance spot in the parser.
//
// ---------------------------------------------------------------------------
inline void XMLReader::movePlainContentChars(XMLBuffer &dest)
{
unsigned int count = fCharIndex;
while (fCharIndex < fCharsAvail)
fCurCol += (fCharIndex - count);
dest.append(&fCharBuf[count], fCharIndex - count);
}
}
// ---------------------------------------------------------------------------
// XMLReader: getNextCharIfNot() method inlined for speed
// ---------------------------------------------------------------------------
inline bool XMLReader::getNextCharIfNot(const XMLCh chNotToGet, XMLCh& chGotten)
{
//
// See if there is at least a char in the buffer. Else, do the buffer
// reload logic.
//
{
// If fNoMore is set, then we have nothing else to give
if (fNoMore)
return false;
// Try to refresh
if (!refreshCharBuffer())
return false;
// Check the next char
if (fCharBuf[fCharIndex] == chNotToGet)
return false;
// Its not the one we want to skip so bump the index
chGotten = fCharBuf[fCharIndex++];
// Handle end of line normalization and line/col member maintenance.
// ---------------------------------------------------------------------------
// XMLReader: getNextChar() method inlined for speed
// ---------------------------------------------------------------------------
inline bool XMLReader::getNextChar(XMLCh& chGotten)
{
//
// See if there is at least a char in the buffer. Else, do the buffer
// reload logic.
//
if (fCharIndex >= fCharsAvail)
{
// If fNoMore is set, then we have nothing else to give
if (fNoMore)
return false;
// Try to refresh
if (!refreshCharBuffer())
return false;
}
chGotten = fCharBuf[fCharIndex++];
// Handle end of line normalization and line/col member maintenance.
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
return true;
}
// ---------------------------------------------------------------------------
// XMLReader: peekNextChar() method inlined for speed
// ---------------------------------------------------------------------------
inline bool XMLReader::peekNextChar(XMLCh& chGotten)
{
//
// If there is something still in the buffer, get it. Else do the reload
// scenario.
//
if (fCharIndex >= fCharsAvail)
{
// Try to refresh the buffer
if (!refreshCharBuffer())
{
chGotten = chNull;
return false;
}
}
chGotten = fCharBuf[fCharIndex];
//
// Even though we are only peeking, we have to act the same as the
// normal char get method in regards to newline normalization, though
// its not as complicated as the actual character getting method's.
//
if ((chGotten == chCR || ((chGotten == chNEL || chGotten == chLineSeparator) && fNEL))
&& (fSource == Source_External))
chGotten = chLF;
return true;
}
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
/***
*
* XML1.1
*
* 2.11 End-of-Line Handling
*
* XML parsed entities are often stored in computer files which, for editing
* convenience, are organized into lines. These lines are typically separated
* by some combination of the characters CARRIAGE RETURN (#xD) and LINE FEED (#xA).
*
* To simplify the tasks of applications, the XML processor MUST behave as if
* it normalized all line breaks in external parsed entities (including the document
* entity) on input, before parsing, by translating all of the following to a single
* #xA character:
*
* 1. the two-character sequence #xD #xA
* 2. the two-character sequence #xD #x85
* 3. the single character #x85
* 4. the single character #x2028
* 5. any #xD character that is not immediately followed by #xA or #x85.
*
*
***/
inline void XMLReader::handleEOL(XMLCh& curCh, bool inDecl)
{
// 1. the two-character sequence #xD #xA
// 2. the two-character sequence #xD #x85
// 5. any #xD character that is not immediately followed by #xA or #x85.
if (curCh == chCR)
{
fCurCol = 1;
fCurLine++;
//
// If not already internalized, then convert it to an
// LF and eat any following LF.
//
if (fSource == Source_External)
{
if ((fCharIndex < fCharsAvail) || refreshCharBuffer())
{
if ( fCharBuf[fCharIndex] == chLF ||
((fCharBuf[fCharIndex] == chNEL) && fNEL) )
{
fCharIndex++;
}
}
curCh = chLF;
}
}
else if (curCh == chLF)
{
fCurCol = 1;
fCurLine++;
}
// 3. the single character #x85
// 4. the single character #x2028
else if (curCh == chNEL || curCh == chLineSeparator)
{
if (inDecl && fXMLVersion == XMLV1_1)
{
/***
* XML1.1
*
* 2.11 End-of-Line Handling
* ...
* The characters #x85 and #x2028 cannot be reliably recognized and translated
* until an entity's encoding declaration (if present) has been read.
* Therefore, it is a fatal error to use them within the XML declaration or
* text declaration.
*
***/
ThrowXMLwithMemMgr1
(
TranscodingException
, XMLExcepts::Reader_NelLsepinDecl
, fSystemId
, fMemoryManager
);
}
if (fNEL && fSource == Source_External)
{
fCurCol = 1;
fCurLine++;
curCh = chLF;
}
}
else
{
fCurCol++;
}
return;
}