Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Private Member Functions | Private Attributes
nsStandardURL::nsSegmentEncoder Class Reference

#include <nsStandardURL.h>

Collaboration diagram for nsStandardURL::nsSegmentEncoder:
Collaboration graph

List of all members.

Public Member Functions

 nsSegmentEncoder (const char *charset)
PRInt32 EncodeSegmentCount (const char *str, const URLSegment &segment, PRInt16 mask, nsAFlatCString &buf, PRBool &appended)
const nsACString & EncodeSegment (const nsASingleFragmentCString &str, PRInt16 mask, nsAFlatCString &buf)

Private Member Functions

PRBool InitUnicodeEncoder ()

Private Attributes

const char * mCharset
nsCOMPtr< nsIUnicodeEncodermEncoder

Detailed Description

Definition at line 116 of file nsStandardURL.h.

Constructor & Destructor Documentation

Definition at line 164 of file nsStandardURL.cpp.

    : mCharset(charset)

Member Function Documentation

Definition at line 222 of file nsStandardURL.cpp.

    const char *text;
    PRBool encoded;
    EncodeSegmentCount(str.BeginReading(text), URLSegment(0, str.Length()), mask, result, encoded);
    if (encoded)
        return result;
    return str;
PRInt32 nsStandardURL::nsSegmentEncoder::EncodeSegmentCount ( const char *  str,
const URLSegment segment,
PRInt16  mask,
nsAFlatCString buf,
PRBool appended 

Definition at line 170 of file nsStandardURL.cpp.

    appended = PR_FALSE;
    if (!str)
        return 0;
    PRInt32 len = 0;
    if (seg.mLen > 0) {
        PRUint32 pos = seg.mPos;
        len = seg.mLen;

        // first honor the origin charset if appropriate. as an optimization,
        // only do this if the segment is non-ASCII.  Further, if mCharset is
        // null or the empty string then the origin charset is UTF-8 and there
        // is nothing to do.
        nsCAutoString encBuf;
        if (mCharset && *mCharset && !nsCRT::IsAscii(str + pos, len)) {
            // we have to encode this segment
            if (mEncoder || InitUnicodeEncoder()) {
                NS_ConvertUTF8toUCS2 ucsBuf(Substring(str + pos, str + pos + len));
                if (NS_SUCCEEDED(EncodeString(mEncoder, ucsBuf, encBuf))) {
                    str = encBuf.get();
                    pos = 0;
                    len = encBuf.Length();
                // else some failure occured... assume UTF-8 is ok.

        // escape per RFC2396 unless UTF-8 and allowed by preferences
        PRInt16 escapeFlags = (gEscapeUTF8 || mEncoder) ? 0 : esc_OnlyASCII;

        PRUint32 initLen = result.Length();

        // now perform any required escaping
        if (NS_EscapeURL(str + pos, len, mask | escapeFlags, result)) {
            len = result.Length() - initLen;
            appended = PR_TRUE;
        else if (str == encBuf.get()) {
            result += encBuf; // append only!!
            len = encBuf.Length();
            appended = PR_TRUE;
    return len;

Here is the call graph for this function:

Definition at line 235 of file nsStandardURL.cpp.

    NS_ASSERTION(!mEncoder, "Don't call this if we have an encoder already!");
    nsresult rv;
    if (!gCharsetMgr) {
        rv = CallGetService(";1",
        if (NS_FAILED(rv)) {
            NS_ERROR("failed to get charset-converter-manager");
            return PR_FALSE;

    rv = gCharsetMgr->GetUnicodeEncoder(mCharset, getter_AddRefs(mEncoder));
    if (NS_FAILED(rv)) {
        NS_ERROR("failed to get unicode encoder");
        mEncoder = 0; // just in case
        return PR_FALSE;

    return PR_TRUE;

Here is the call graph for this function:

Member Data Documentation

Definition at line 139 of file nsStandardURL.h.

Definition at line 141 of file nsStandardURL.h.

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