Back to index

lightning-sunbird  0.9+nobinonly
Classes | Functions | Variables
nsRDFXMLSerializer.cpp File Reference
#include "nsRDFXMLSerializer.h"
#include "nsIAtom.h"
#include "nsIOutputStream.h"
#include "nsIRDFService.h"
#include "nsIRDFContainerUtils.h"
#include "nsIServiceManager.h"
#include "nsString.h"
#include "nsXPIDLString.h"
#include "nsVoidArray.h"
#include "rdf.h"
#include "rdfutil.h"
#include "rdfIDataSource.h"
#include "nsITimelineService.h"

Go to the source code of this file.

Classes

class  QNameCollector

Functions

static nsresult rdf_BlockingWrite (nsIOutputStream *stream, const char *buf, PRUint32 size)
static nsresult rdf_BlockingWrite (nsIOutputStream *stream, const nsCSubstring &s)
static nsresult rdf_BlockingWrite (nsIOutputStream *stream, const nsAString &s)
static void rdf_EscapeAmpersandsAndAngleBrackets (nsCString &s)
static void rdf_EscapeQuotes (nsCString &s)
static void rdf_EscapeAttributeValue (nsCString &s)

Variables

static const char kRDFDescriptionOpen [] = " <RDF:Description"
static const char kIDAttr [] = " RDF:ID=\""
static const char kAboutAttr [] = " RDF:about=\""
static const char kRDFDescriptionClose [] = " </RDF:Description>\n"
static const char kRDFResource1 [] = " RDF:resource=\""
static const char kRDFResource2 [] = "\"/>\n"
static const char kRDFParseTypeInteger [] = " NC:parseType=\"Integer\">"
static const char kRDFParseTypeDate [] = " NC:parseType=\"Date\">"
static const char kRDFUnknown [] = "><!-- unknown node type -->"
static const char amp [] = "&amp;"
static const char lt [] = "&lt;"
static const char gt [] = "&gt;"
static const char quot [] = "&quot;"

Function Documentation

static nsresult rdf_BlockingWrite ( nsIOutputStream stream,
const char *  buf,
PRUint32  size 
) [static]

Definition at line 190 of file nsRDFXMLSerializer.cpp.

{
    PRUint32 written = 0;
    PRUint32 remaining = size;
    while (remaining > 0) {
        nsresult rv;
        PRUint32 cb;

        if (NS_FAILED(rv = stream->Write(buf + written, remaining, &cb)))
            return rv;

        written += cb;
        remaining -= cb;
    }
    return NS_OK;
}

Here is the caller graph for this function:

static nsresult rdf_BlockingWrite ( nsIOutputStream stream,
const nsCSubstring s 
) [static]

Definition at line 208 of file nsRDFXMLSerializer.cpp.

{
    return rdf_BlockingWrite(stream, s.BeginReading(), s.Length());
}

Here is the call graph for this function:

static nsresult rdf_BlockingWrite ( nsIOutputStream stream,
const nsAString &  s 
) [static]

Definition at line 214 of file nsRDFXMLSerializer.cpp.

{
    NS_ConvertUCS2toUTF8 utf8(s);
    return rdf_BlockingWrite(stream, utf8.get(), utf8.Length());
}

Here is the call graph for this function:

Definition at line 317 of file nsRDFXMLSerializer.cpp.

{
    PRUint32 newLength, origLength;
    newLength = origLength = s.Length();

    // Compute the length of the result string.
    const char* start = s.BeginReading();
    const char* end = s.EndReading();
    const char* c = start;
    while (c != end) {
        switch (*c) {
        case '&' :
            newLength += sizeof(amp) - 2;
            break;
        case '<':
        case '>':
            newLength += sizeof(gt) - 2;
            break;
        default:
            break;
        }
        ++c;
    }
    if (newLength == origLength) {
        // nothing to escape
        return;
    }

    // escape the chars from the end back to the front.
    s.SetLength(newLength);

    // Buffer might have changed, get the pointers again
    start = s.BeginReading(); // begin of string
    c = start + origLength - 1; // last char in original string
    char* w = s.EndWriting() - 1; // last char in grown buffer
    while (c >= start) {
        switch (*c) {
        case '&' :
            w -= 4;
            nsCharTraits<char>::copy(w, amp, sizeof(amp) - 1);
            break;
        case '<':
            w -= 3;
            nsCharTraits<char>::copy(w, lt, sizeof(lt) - 1);
            break;
        case '>':
            w -= 3;
            nsCharTraits<char>::copy(w, gt, sizeof(gt) - 1);
            break;
        default:
            *w = *c;
        }
        --w;
        --c;
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void rdf_EscapeAttributeValue ( nsCString s) [static]

Definition at line 386 of file nsRDFXMLSerializer.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

static void rdf_EscapeQuotes ( nsCString s) [static]

Definition at line 376 of file nsRDFXMLSerializer.cpp.

{
    PRInt32 i = 0;
    while ((i = s.FindChar('"', i)) != -1) {
        s.Replace(i, 1, quot, sizeof(quot) - 1);
        i += sizeof(quot) - 2;
    }
}

Here is the caller graph for this function:


Variable Documentation

const char amp[] = "&amp;" [static]

Definition at line 311 of file nsRDFXMLSerializer.cpp.

const char gt[] = "&gt;" [static]

Definition at line 313 of file nsRDFXMLSerializer.cpp.

const char kAboutAttr[] = " RDF:about=\"" [static]

Definition at line 69 of file nsRDFXMLSerializer.cpp.

const char kIDAttr[] = " RDF:ID=\"" [static]

Definition at line 68 of file nsRDFXMLSerializer.cpp.

const char kRDFDescriptionClose[] = " </RDF:Description>\n" [static]

Definition at line 70 of file nsRDFXMLSerializer.cpp.

const char kRDFDescriptionOpen[] = " <RDF:Description" [static]

Definition at line 67 of file nsRDFXMLSerializer.cpp.

const char kRDFParseTypeDate[] = " NC:parseType=\"Date\">" [static]

Definition at line 74 of file nsRDFXMLSerializer.cpp.

const char kRDFParseTypeInteger[] = " NC:parseType=\"Integer\">" [static]

Definition at line 73 of file nsRDFXMLSerializer.cpp.

const char kRDFResource1[] = " RDF:resource=\"" [static]

Definition at line 71 of file nsRDFXMLSerializer.cpp.

const char kRDFResource2[] = "\"/>\n" [static]

Definition at line 72 of file nsRDFXMLSerializer.cpp.

const char kRDFUnknown[] = "><!-- unknown node type -->" [static]

Definition at line 75 of file nsRDFXMLSerializer.cpp.

const char lt[] = "&lt;" [static]

Definition at line 312 of file nsRDFXMLSerializer.cpp.

const char quot[] = "&quot;" [static]

Definition at line 314 of file nsRDFXMLSerializer.cpp.