コード例 #1
0
ファイル: ElemTextLiteral.cpp プロジェクト: apache/xalan-c
XALAN_CPP_NAMESPACE_BEGIN



ElemTextLiteral::ElemTextLiteral(
            StylesheetConstructionContext&  constructionContext,
            Stylesheet&                     stylesheetTree,
            XalanFileLoc                    lineNumber, 
            XalanFileLoc                    columnNumber,
            const XMLCh*                    ch,
            XalanDOMString::size_type       start,
            XalanDOMString::size_type       length,
            bool                            fPreserveSpace,
            bool                            fDisableOutputEscaping) :
    ElemTemplateElement(
        constructionContext,
        stylesheetTree,
        StylesheetConstructionContext::ELEMNAME_TEXT_LITERAL_RESULT,
        stylesheetTree.getBaseIdentifier(),
        lineNumber,
        columnNumber),
    m_isWhitespace(isXMLWhitespace(ch, start, length)),
    // Always null-terminate our buffer, since we may need it that way.
    m_ch(constructionContext.allocateXalanDOMCharVector(ch + start, length, true)),
    m_length(length)
{
    disableOutputEscaping(fDisableOutputEscaping);

    preserveSpace(fPreserveSpace);
}
コード例 #2
0
ファイル: AVTPartSimple.cpp プロジェクト: apache/xalan-c
XALAN_CPP_NAMESPACE_BEGIN



/**
 * Simple string part of a complex AVT.
 */
AVTPartSimple::AVTPartSimple(
            StylesheetConstructionContext&  constructionContext,
            const XalanDOMChar*             val,
            XalanDOMString::size_type       len) :
    AVTPart(),
    m_val(constructionContext.allocateXalanDOMCharVector(val, len, false)),
    m_len(len)
{
}
コード例 #3
0
/**
 * Construct an AVT by parsing the string, and either 
 * constructing a vector of AVTParts, or simply hold 
 * on to the string if the AVT is simple.
 */
AVT::AVT(
            StylesheetConstructionContext&  constructionContext,
            const LocatorType*              locator,
            const XalanDOMChar*             name,
            const XalanDOMChar*             stringedValue,
            const PrefixResolver&           resolver) :
        m_parts(0),
        m_partsSize(0),
        m_simpleString(0),
        m_simpleStringLength(0),
        m_name(constructionContext.getPooledString(name))
{
    StringTokenizer     tokenizer(stringedValue, theTokenDelimiterCharacters, true);

    const StringTokenizer::size_type    nTokens = tokenizer.countTokens();

    if(nTokens < 2)
    {
        // Do the simple thing
        m_simpleStringLength = length(stringedValue);

        m_simpleString = constructionContext.allocateXalanDOMCharVector(stringedValue, m_simpleStringLength, false);
    }
    else
    {
        // This over-allocates, but we probably won't waste that much space.  If necessary,
        // we could tokenize twice, just counting the numbers of AVTPart instances we
        // will need the first time.
        m_parts = constructionContext.allocateAVTPartPointerVector(nTokens + 1);

        XalanDOMString  buffer(constructionContext.getMemoryManager());
        XalanDOMString  exprBuffer(constructionContext.getMemoryManager());
        XalanDOMString  t(constructionContext.getMemoryManager()); // base token
        XalanDOMString  lookahead(constructionContext.getMemoryManager()); // next token

        while(tokenizer.hasMoreTokens())
        {
            if(length(lookahead))
            {
                t = lookahead;

                clear(lookahead);
            }
            else
            {
                nextToken(constructionContext, locator, tokenizer, t);
            }

            if(length(t) == 1)
            {
                const XalanDOMChar  theChar = charAt(t, 0);

                switch(theChar)
                {
                    case(XalanUnicode::charLeftCurlyBracket):
                    {
                        // Attribute Value Template start
                        nextToken(constructionContext, locator, tokenizer, lookahead);

                        if(equals(lookahead, theLeftCurlyBracketString))
                        {
                            // Double braces mean escape to show brace
                            append(buffer, lookahead);

                            clear(lookahead);

                            break; // from switch
                        }
                        else
                        {
                            if(length(buffer) > 0)
                            {
                                assert(m_partsSize + 1 < nTokens);

                                m_parts[m_partsSize++] =
                                    constructionContext.createAVTPart(
                                        c_wstr(buffer),
                                        length(buffer));

                                clear(buffer);
                            }
                                    
                            clear(exprBuffer);

                            while(length(lookahead) > 0 && !equals(lookahead, theRightCurlyBracketString))
                            {
                                if(length(lookahead) == 1)
                                {
                                    switch(charAt(lookahead, 0))
                                    {
                                        case XalanUnicode::charApostrophe:
                                        case XalanUnicode::charQuoteMark:
                                        {
                                            // String start
                                            append(exprBuffer, lookahead);

                                            const XalanDOMChar  quote[2] =
                                            {
                                                lookahead[0],
                                                0
                                            };

                                            // Consume stuff 'till next quote
                                            nextToken(constructionContext, locator, tokenizer, lookahead);

                                            while(!equals(lookahead, quote))
                                            {
                                                append(exprBuffer, lookahead);

                                                nextToken(constructionContext, locator, tokenizer, lookahead);
                                            }

                                            append(exprBuffer,lookahead);

                                            break;
                                        }

                                        case XalanUnicode::charLeftCurlyBracket:
                                            {
                                                GetCachedString     theGuard(constructionContext);

                                                // What's another brace doing here?
                                                constructionContext.error(
                                                    XalanMessageLoader::getMessage(
                                                        theGuard.get(),
                                                        XalanMessages::LeftBraceCannotAppearWithinExpression),
                                                    0,
                                                    locator);
                                                break;
                                            }

                                        default:
                                            // part of the template stuff, just add it.
                                            append(exprBuffer, lookahead);
                                            break;

                                    } // end inner switch
                                } // end if lookahead length == 1
                                else
                                {
                                    // part of the template stuff, just add it.
                                    append(exprBuffer,lookahead);
                                }

                                nextToken(constructionContext, locator, tokenizer, lookahead);
                            } // end while(!equals(lookahead, "}"))
                            assert(equals(lookahead, theRightCurlyBracketString));

                            // Proper close of attribute template. Evaluate the
                            // expression.
                            clear(buffer);

                            assert(m_partsSize + 1 < nTokens);

                            m_parts[m_partsSize++] =
                                constructionContext.createAVTPart(
                                    locator,
                                    c_wstr(exprBuffer),
                                    length(exprBuffer),
                                    resolver);

                            clear(lookahead); // breaks out of inner while loop
                        }
                        break;
                    }
                    case(XalanUnicode::charRightCurlyBracket):
                    {
                        nextToken(constructionContext, locator, tokenizer, lookahead);

                        if(equals(lookahead, theRightCurlyBracketString))
                        {
                            // Double brace mean escape to show brace
                            append(buffer, lookahead);

                            clear(lookahead); // swallow
                        }
                        else
                        {
                            GetCachedString     theGuard(constructionContext);

                            constructionContext.error(
                                XalanMessageLoader::getMessage(
                                    theGuard.get(),
                                    XalanMessages::UnmatchedWasFound),
                                0,
                                locator);

                        }
                        break;
                    }
                    default:
                    {
                        // Anything else just add to string.
                        append(buffer, theChar);
                    }
                } // end switch t
            } // end if length == 1
            else
            {
                // Anything else just add to string.
                append(buffer,t);
            }
        } // end while(tokenizer.hasMoreTokens())

        if(length(buffer) > 0)
        {
            assert(m_partsSize + 1 < nTokens);

            m_parts[m_partsSize++] = constructionContext.createAVTPart(c_wstr(buffer), length(buffer));

            clear(buffer);
        }
    } // end else nTokens > 1
}