Back to index

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

#include <nsParserUtils.h>

List of all members.

Static Public Member Functions

static PRBool GetQuotedAttributeValue (const nsString &aSource, nsIAtom *aName, nsAString &aValue, PRBool aComplyWithSpec=PR_FALSE)
 This will parse aSource, to extract the value of the pseudo attribute with the name specified in aName.
static PRBool IsJavaScriptLanguage (const nsString &aName, const char **aVersion)
static void SplitMimeType (const nsAString &aValue, nsString &aType, nsString &aParams)

Detailed Description

Definition at line 44 of file nsParserUtils.h.


Member Function Documentation

PRBool nsParserUtils::GetQuotedAttributeValue ( const nsString aSource,
nsIAtom aName,
nsAString &  aValue,
PRBool  aComplyWithSpec = PR_FALSE 
) [static]

This will parse aSource, to extract the value of the pseudo attribute with the name specified in aName.

See http://www.w3.org/TR/xml-stylesheet/#NT-StyleSheetPI for the specification which is used to parse aSource.

NOTE: if aComplyWithSpec is PR_FALSE (the default), the parsing of the value will not be following the specification: we won't treat < and & as illegal and we won't expand entities. aComplyWithSpec is only for backwards compatibility with Gecko <= 1.8, it won't be available in Gecko 1.9.

Parameters:
aSourcethe string to parse
aNamethe name of the attribute to get the value for
aValue[out] the value for the attribute with name specified in aAttribute. Empty if the attribute isn't present.
aComplyWithSpecIf PR_TRUE we'll treat < and & as illegal and expand entities.

Definition at line 62 of file nsParserUtils.cpp.

{
  aValue.Truncate();

  const PRUnichar *start = aSource.get();
  const PRUnichar *end = start + aSource.Length();
  const PRUnichar *iter;
  
  while (start != end) {
    SKIP_WHITESPACE(start, end);
    iter = start;
    SKIP_ATTR_NAME(iter, end);

    // Remember the attr name.
    const nsDependentSubstring & attrName = Substring(start, iter);

    // Now check whether this is a valid name="value" pair.
    start = iter;
    SKIP_WHITESPACE(start, end);
    if (*start != '=') {
      // No '=', so this is not a name="value" pair.  We don't know
      // what it is, and we have no way to handle it.
      break;
    }
    
    // Have to skip the value.
    ++start;
    SKIP_WHITESPACE(start, end);
    PRUnichar q = *start;
    if (q != kQuote && q != kApostrophe) {
      // Not a valid quoted value, so bail.
      break;
    }
    
    ++start;  // Point to the first char of the value.
    iter = start;

    while (iter != end && *iter != q) {
      ++iter;
    }

    if (iter == end) {
      // Oops, unterminated quoted string.
      break;
    }

    // At this point attrName holds the name of the "attribute" and
    // the value is between start and iter.
    
    if (aName->Equals(attrName)) {
      if (!aComplyWithSpec) {
        aValue.Append(start, iter - start);

        return PR_TRUE;
      }

      nsCOMPtr<nsIParserService_MOZILLA_1_8_BRANCH> parserService =
        do_QueryInterface(nsContentUtils::GetParserServiceWeakRef());
      NS_ENSURE_TRUE(parserService, PR_FALSE);

      // We'll accumulate as many characters as possible (until we hit either
      // the end of the string or the beginning of an entity). Chunks will be
      // delimited by start and chunkEnd.
      const PRUnichar *chunkEnd = start;
      while (chunkEnd != iter) {
        if (*chunkEnd == kLessThan) {
          aValue.Truncate();

          return PR_FALSE;
        }

        if (*chunkEnd == kAmpersand) {
          aValue.Append(start, chunkEnd - start);

          // Point to first character after the ampersand.
          ++chunkEnd;

          const PRUnichar *afterEntity;
          PRUnichar result[2];
          PRUint32 count =
            parserService->DecodeEntity(chunkEnd, iter, &afterEntity, result);
          if (count == 0) {
            aValue.Truncate();

            return PR_FALSE;
          }

          aValue.Append(result, count);

          // Advance to after the entity and begin a new chunk.
          start = chunkEnd = afterEntity;
        }
        else {
          ++chunkEnd;
        }
      }

      // Append remainder.
      aValue.Append(start, iter - start);

      return PR_TRUE;
    }

    // Resume scanning after the end of the attribute value (past the quote
    // char).
    start = iter + 1;
  }

  return PR_FALSE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool nsParserUtils::IsJavaScriptLanguage ( const nsString aName,
const char **  aVersion 
) [static]

Definition at line 181 of file nsParserUtils.cpp.

{
  JSVersion version = JSVERSION_UNKNOWN;

  if (aName.LowerCaseEqualsLiteral("javascript") ||
      aName.LowerCaseEqualsLiteral("livescript") ||
      aName.LowerCaseEqualsLiteral("mocha")) {
    version = JSVERSION_DEFAULT;
  }
  else if (aName.LowerCaseEqualsLiteral("javascript1.0")) {
    version = JSVERSION_1_0;
  }
  else if (aName.LowerCaseEqualsLiteral("javascript1.1")) {
    version = JSVERSION_1_1;
  }
  else if (aName.LowerCaseEqualsLiteral("javascript1.2")) {
    version = JSVERSION_1_2;
  }
  else if (aName.LowerCaseEqualsLiteral("javascript1.3")) {
    version = JSVERSION_1_3;
  }
  else if (aName.LowerCaseEqualsLiteral("javascript1.4")) {
    version = JSVERSION_1_4;
  }
  else if (aName.LowerCaseEqualsLiteral("javascript1.5")) {
    version = JSVERSION_1_5;
  }
  else if (aName.LowerCaseEqualsLiteral("javascript1.6")) {
    version = JSVERSION_1_6;
  }
  else if (aName.LowerCaseEqualsLiteral("javascript1.7")) {
    version = JSVERSION_1_7;
  }
  if (version == JSVERSION_UNKNOWN)
    return PR_FALSE;
  *aVersion = JS_VersionToString(version);
  return PR_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsParserUtils::SplitMimeType ( const nsAString &  aValue,
nsString aType,
nsString aParams 
) [static]

Definition at line 221 of file nsParserUtils.cpp.

{
  aType.Truncate();
  aParams.Truncate();
  PRInt32 semiIndex = aValue.FindChar(PRUnichar(';'));
  if (-1 != semiIndex) {
    aType = Substring(aValue, 0, semiIndex);
    aParams = Substring(aValue, semiIndex + 1,
                       aValue.Length() - (semiIndex + 1));
    aParams.StripWhitespace();
  }
  else {
    aType = aValue;
  }
  aType.StripWhitespace();
}

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: