Back to index

lightning-sunbird  0.9+nobinonly
Static Public Member Functions
XMLUtils Class Reference

#include <XMLUtils.h>

List of all members.

Static Public Member Functions

static nsresult splitExpatName (const PRUnichar *aExpatName, nsIAtom **aPrefix, nsIAtom **aLocalName, PRInt32 *aNameSpaceID)
static nsresult splitQName (const nsAString &aName, nsIAtom **aPrefix, nsIAtom **aLocalName)
static const nsDependentSubstring getLocalPart (const nsAString &src)
static MBool isWhitespace (const PRUnichar &aChar)
static PRBool isWhitespace (const nsAFlatString &aText)
 Returns true if the given string has only whitespace characters.
static void normalizePIValue (nsAString &attValue)
 Normalizes the value of a XML processingInstruction.
static PRBool isValidQName (const nsAFlatString &aQName, const PRUnichar **aColon)
 Returns true if the given string is a valid XML QName.
static PRBool isLetter (PRUnichar aChar)
 Returns true if the given character represents an Alpha letter.
static PRBool isNCNameChar (PRUnichar aChar)
 Returns true if the given character is an allowable NCName character.
static MBool getXMLSpacePreserve (const txXPathNode &aNode)

Detailed Description

Definition at line 127 of file XMLUtils.h.


Member Function Documentation

const nsDependentSubstring XMLUtils::getLocalPart ( const nsAString &  src) [static]

Definition at line 177 of file XMLUtils.cpp.

{
    // Anything after ':' is the local part of the name
    PRInt32 idx = src.FindChar(':');
    if (idx == kNotFound) {
        return Substring(src, 0, src.Length());
    }

    NS_ASSERTION(idx > 0, "This QName looks invalid.");
    return Substring(src, idx + 1, src.Length() - (idx + 1));
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 238 of file XMLUtils.cpp.

{
    nsAutoString value;
    txXPathTreeWalker walker(aNode);
    do {
        if (walker.getAttr(txXMLAtoms::space, kNameSpaceID_XML, value)) {
            if (TX_StringEqualsAtom(value, txXMLAtoms::preserve)) {
                return PR_TRUE;
            }
            if (TX_StringEqualsAtom(value, txXMLAtoms::_default)) {
                return PR_FALSE;
            }
        }
    } while (walker.moveToParent());

    return PR_FALSE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PRBool XMLUtils::isLetter ( PRUnichar  aChar) [inline, static]

Returns true if the given character represents an Alpha letter.

Definition at line 183 of file XMLUtils.h.

    {
#ifdef TX_EXE
        return MOZ_XMLIsLetter(NS_REINTERPRET_CAST(const char*, &aChar));
#else
        return gTxParserService->IsXMLLetter(aChar);
#endif
    }

Here is the call graph for this function:

Here is the caller graph for this function:

static PRBool XMLUtils::isNCNameChar ( PRUnichar  aChar) [inline, static]

Returns true if the given character is an allowable NCName character.

Definition at line 195 of file XMLUtils.h.

    {
#ifdef TX_EXE
        return MOZ_XMLIsNCNameChar(NS_REINTERPRET_CAST(const char*, &aChar));
#else
        return gTxParserService->IsXMLNCNameChar(aChar);
#endif
    }

Here is the call graph for this function:

Here is the caller graph for this function:

static PRBool XMLUtils::isValidQName ( const nsAFlatString aQName,
const PRUnichar **  aColon 
) [inline, static]

Returns true if the given string is a valid XML QName.

Definition at line 160 of file XMLUtils.h.

    {
#ifdef TX_EXE
        const PRUnichar* end;
        aQName.EndReading(end);

        const char *colonPtr;
        int result = MOZ_XMLCheckQName(NS_REINTERPRET_CAST(const char*,
                                                           aQName.get()),
                                       NS_REINTERPRET_CAST(const char*,
                                                           end),
                                       PR_TRUE, &colonPtr);
        *aColon = NS_REINTERPRET_CAST(const PRUnichar*, colonPtr);
        return result == 0;
#else
        return NS_SUCCEEDED(gTxParserService->CheckQName(aQName, PR_TRUE, aColon));
#endif
    }

Here is the call graph for this function:

Here is the caller graph for this function:

static MBool XMLUtils::isWhitespace ( const PRUnichar aChar) [inline, static]

Definition at line 140 of file XMLUtils.h.

    {
        return (aChar <= ' ' &&
                (aChar == ' ' || aChar == '\r' ||
                 aChar == '\n'|| aChar == '\t'));
    }

Here is the caller graph for this function:

Returns true if the given string has only whitespace characters.

Definition at line 192 of file XMLUtils.cpp.

{
    nsAFlatString::const_char_iterator start, end;
    aText.BeginReading(start);
    aText.EndReading(end);
    for ( ; start != end; ++start) {
        if (!isWhitespace(*start)) {
            return PR_FALSE;
        }
    }
    return PR_TRUE;
}

Here is the call graph for this function:

void XMLUtils::normalizePIValue ( nsAString &  attValue) [static]

Normalizes the value of a XML processingInstruction.

Normalizes the value of a XML processing instruction.

Definition at line 208 of file XMLUtils.cpp.

{
    nsAutoString origValue(piValue);
    PRUint32 origLength = origValue.Length();
    PRUint32 conversionLoop = 0;
    PRUnichar prevCh = 0;
    piValue.Truncate();

    while (conversionLoop < origLength) {
        PRUnichar ch = origValue.CharAt(conversionLoop);
        switch (ch) {
            case '>':
            {
                if (prevCh == '?') {
                    piValue.Append(PRUnichar(' '));
                }
                break;
            }
            default:
            {
                break;
            }
        }
        piValue.Append(ch);
        prevCh = ch;
        ++conversionLoop;
    }
}
nsresult XMLUtils::splitExpatName ( const PRUnichar aExpatName,
nsIAtom **  aPrefix,
nsIAtom **  aLocalName,
PRInt32 aNameSpaceID 
) [static]

Expat can send the following: localName namespaceURI<separator>localName namespaceURI<separator>localName<separator>prefix

and we use 0xFFFF for the <separator>.

Definition at line 88 of file XMLUtils.cpp.

{
    const PRUnichar *uriEnd = nsnull;
    const PRUnichar *nameEnd = nsnull;
    const PRUnichar *pos;
    for (pos = aExpatName; *pos; ++pos) {
        if (*pos == 0xFFFF) {
            if (uriEnd) {
                nameEnd = pos;
            }
            else {
                uriEnd = pos;
            }
        }
    }

    const PRUnichar *nameStart;
    if (uriEnd) {
        *aNameSpaceID =
            txNamespaceManager::getNamespaceID(nsDependentSubstring(aExpatName,
                                                                    uriEnd));
        if (*aNameSpaceID == kNameSpaceID_Unknown) {
            return NS_ERROR_FAILURE;
        }

        nameStart = (uriEnd + 1);
        if (nameEnd)  {
            const PRUnichar *prefixStart = nameEnd + 1;
            *aPrefix = NS_NewAtom(NS_ConvertUTF16toUTF8(prefixStart,
                                                        pos - prefixStart));
            if (!*aPrefix) {
                return NS_ERROR_OUT_OF_MEMORY;
            }
        }
        else {
            nameEnd = pos;
            *aPrefix = nsnull;
        }
    }
    else {
        *aNameSpaceID = kNameSpaceID_None;
        nameStart = aExpatName;
        nameEnd = pos;
        *aPrefix = nsnull;
    }

    *aLocalName = NS_NewAtom(NS_ConvertUTF16toUTF8(nameStart,
                                                   nameEnd - nameStart));

    return *aLocalName ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult XMLUtils::splitQName ( const nsAString &  aName,
nsIAtom **  aPrefix,
nsIAtom **  aLocalName 
) [static]

Definition at line 152 of file XMLUtils.cpp.

{
    const nsAFlatString& qName = PromiseFlatString(aName);
    const PRUnichar* colon;
    PRBool valid = XMLUtils::isValidQName(qName, &colon);
    if (!valid) {
        return NS_ERROR_FAILURE;
    }

    if (colon) {
        const PRUnichar *end;
        qName.EndReading(end);

        *aPrefix = NS_NewAtom(Substring(qName.get(), colon));
        *aLocalName = NS_NewAtom(Substring(colon + 1, end));
    }
    else {
        *aPrefix = nsnull;
        *aLocalName = NS_NewAtom(aName);
    }

    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:


The documentation for this class was generated from the following files: