~ubuntu-branches/ubuntu/precise/xerces-c/precise-updates

« back to all changes in this revision

Viewing changes to src/xercesc/internal/WFXMLScanner.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jay Berkenbilt
  • Date: 2009-12-05 14:58:32 UTC
  • mfrom: (2.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20091205145832-378dg3x72mdzfzup
Tags: 3.1.0~rc1-1
* New upstream release; public release candidate uploaded at request of
  upstream.
* Updated source format to '3.0 (quilt)'

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 */
17
17
 
18
18
/*
19
 
  * $Id: WFXMLScanner.cpp 696218 2008-09-17 09:31:41Z borisk $
 
19
  * $Id: WFXMLScanner.cpp 833045 2009-11-05 13:21:27Z borisk $
20
20
 */
21
21
 
22
22
 
445
445
    delete fElements;
446
446
}
447
447
 
448
 
unsigned int
449
 
WFXMLScanner::resolvePrefix(const   XMLCh* const          prefix
450
 
                            , const ElemStack::MapModes mode)
451
 
{
452
 
    //  Watch for the special namespace prefixes. We always map these to
453
 
    //  special URIs. 'xml' gets mapped to the official URI that its defined
454
 
    //  to map to by the NS spec. xmlns gets mapped to a special place holder
455
 
    //  URI that we define (so that it maps to something checkable.)
456
 
    if (XMLString::equals(prefix, XMLUni::fgXMLNSString))
457
 
        return fXMLNSNamespaceId;
458
 
    else if (XMLString::equals(prefix, XMLUni::fgXMLString))
459
 
        return fXMLNamespaceId;
460
 
 
461
 
    //  Ask the element stack to search up itself for a mapping for the
462
 
    //  passed prefix.
463
 
    bool unknown;
464
 
    unsigned int uriId = fElemStack.mapPrefixToURI(prefix, mode, unknown);
465
 
 
466
 
    // If it was unknown, then the URI was faked in but we have to issue an error
467
 
    if (unknown)
468
 
        emitError(XMLErrs::UnknownPrefix, prefix);
469
 
 
470
 
    // check to see if uriId is empty; in XML 1.1 an emptynamespace is okay unless
471
 
    // we are trying to use it.
472
 
    if (*prefix &&
473
 
        mode == ElemStack::Mode_Element &&
474
 
        fXMLVersion != XMLReader::XMLV1_0 &&
475
 
        uriId == fElemStack.getEmptyNamespaceId())             
476
 
        emitError(XMLErrs::UnknownPrefix, prefix);
477
 
 
478
 
    return uriId;
479
 
}
480
 
 
481
448
//  This method will reset the scanner data structures, and related plugged
482
449
//  in stuff, for a new scan session. We get the input source for the primary
483
450
//  XML entity, create the reader for it, and push it on the stack so that
523
490
        , XMLReader::Type_General
524
491
        , XMLReader::Source_External
525
492
        , fCalculateSrcOfs
 
493
        , fLowWaterMark
526
494
    );
527
495
 
528
496
    if (!newReader) {
839
807
        {
840
808
            if ((nextCh != chForwardSlash) && (nextCh != chCloseAngle))
841
809
            {
842
 
                if (fReaderMgr.getCurrentReader()->isWhitespace(nextCh))
843
 
                {
844
 
                    // Ok, skip by them and peek another char
845
 
                    fReaderMgr.skipPastSpaces();
846
 
                    nextCh = fReaderMgr.peekNextChar();
847
 
                }
848
 
                 else
 
810
                bool bFoundSpace;
 
811
                fReaderMgr.skipPastSpaces(bFoundSpace);
 
812
                if (!bFoundSpace)
849
813
                {
850
814
                    // Emit the error but keep on going
851
815
                    emitError(XMLErrs::ExpectedWhitespace);
852
816
                }
 
817
                // Ok, peek another char
 
818
                nextCh = fReaderMgr.peekNextChar();
853
819
            }
854
820
        }
855
821
 
1170
1136
        {
1171
1137
            if ((nextCh != chForwardSlash) && (nextCh != chCloseAngle))
1172
1138
            {
1173
 
                if (fReaderMgr.getCurrentReader()->isWhitespace(nextCh))
1174
 
                {
1175
 
                    // Ok, skip by them and peek another char
1176
 
                    fReaderMgr.skipPastSpaces();
1177
 
                    nextCh = fReaderMgr.peekNextChar();
1178
 
                }
1179
 
                else
 
1139
                bool bFoundSpace;
 
1140
                fReaderMgr.skipPastSpaces(bFoundSpace);
 
1141
                if (!bFoundSpace)
1180
1142
                {
1181
1143
                    // Emit the error but keep on going
1182
1144
                    emitError(XMLErrs::ExpectedWhitespace);
1183
1145
                }
 
1146
                // Ok, peek another char
 
1147
                nextCh = fReaderMgr.peekNextChar();
1184
1148
            }
1185
1149
        }
1186
1150
 
1538
1502
    return true;
1539
1503
}
1540
1504
 
1541
 
unsigned int
1542
 
WFXMLScanner::resolveQName(const   XMLCh* const qName
1543
 
                           ,       XMLBuffer&   prefixBuf
1544
 
                           , const short        mode
1545
 
                           ,       int&         prefixColonPos)
1546
 
{
1547
 
    //  Lets split out the qName into a URI and name buffer first. The URI
1548
 
    //  can be empty.
1549
 
    prefixColonPos = XMLString::indexOf(qName, chColon);
1550
 
    if (prefixColonPos == -1)
1551
 
    {
1552
 
        //  Its all name with no prefix, so put the whole thing into the name
1553
 
        //  buffer. Then map the empty string to a URI, since the empty string
1554
 
        //  represents the default namespace. This will either return some
1555
 
        //  explicit URI which the default namespace is mapped to, or the
1556
 
        //  the default global namespace.
1557
 
        bool unknown = false;
1558
 
 
1559
 
        prefixBuf.reset();
1560
 
        return fElemStack.mapPrefixToURI(XMLUni::fgZeroLenString, (ElemStack::MapModes) mode, unknown);
1561
 
    }
1562
 
    else
1563
 
    {
1564
 
        //  Copy the chars up to but not including the colon into the prefix
1565
 
        //  buffer.
1566
 
        prefixBuf.set(qName, prefixColonPos);
1567
 
 
1568
 
        //  Watch for the special namespace prefixes. We always map these to
1569
 
        //  special URIs. 'xml' gets mapped to the official URI that its defined
1570
 
        //  to map to by the NS spec. xmlns gets mapped to a special place holder
1571
 
        //  URI that we define (so that it maps to something checkable.)
1572
 
        const XMLCh* prefixRawBuf = prefixBuf.getRawBuffer();
1573
 
        if (XMLString::equals(prefixRawBuf, XMLUni::fgXMLNSString)) {
1574
 
 
1575
 
            // if this is an element, it is an error to have xmlns as prefix
1576
 
            if (mode == ElemStack::Mode_Element)
1577
 
                emitError(XMLErrs::NoXMLNSAsElementPrefix, qName);
1578
 
 
1579
 
            return fXMLNSNamespaceId;
1580
 
        }
1581
 
        else if (XMLString::equals(prefixRawBuf, XMLUni::fgXMLString)) {
1582
 
            return  fXMLNamespaceId;
1583
 
        }
1584
 
        else
1585
 
        {
1586
 
            bool unknown = false;
1587
 
            unsigned int uriId = fElemStack.mapPrefixToURI(prefixRawBuf, (ElemStack::MapModes) mode, unknown);
1588
 
 
1589
 
            if (unknown)
1590
 
                emitError(XMLErrs::UnknownPrefix, prefixRawBuf);
1591
 
 
1592
 
            return uriId;
1593
 
        }
1594
 
    }
1595
 
}
1596
 
 
1597
1505
// ---------------------------------------------------------------------------
1598
1506
//  XMLScanner: Private parsing methods
1599
1507
// ---------------------------------------------------------------------------