Back to index

lightning-sunbird  0.9+nobinonly
Defines | Functions
moz_extensions.c File Reference

Go to the source code of this file.

Defines

#define PREFIX(ident)   big2_ ## ident
#define BYTE_TYPE(p)   BIG2_BYTE_TYPE(XmlGetUtf16InternalEncodingNS(), p)
#define IS_NAME_CHAR_MINBPC(p)   BIG2_IS_NAME_CHAR_MINBPC(0, p)
#define IS_NMSTRT_CHAR_MINBPC(p)   BIG2_IS_NMSTRT_CHAR_MINBPC(0, p)
#define MOZ_EXPAT_VALID_QNAME   (0)
#define MOZ_EXPAT_EMPTY_QNAME   (1 << 0)
#define MOZ_EXPAT_INVALID_CHARACTER   (1 << 1)
#define MOZ_EXPAT_MALFORMED   (1 << 2)

Functions

int MOZ_XMLCheckQName (const char *ptr, const char *end, int ns_aware, const char **colon)
int MOZ_XMLIsLetter (const char *ptr)
int MOZ_XMLIsNCNameChar (const char *ptr)
int MOZ_XMLTranslateEntity (const char *ptr, const char *end, const char **next, XML_Char *result)

Define Documentation

Definition at line 50 of file moz_extensions.c.

Definition at line 51 of file moz_extensions.c.

Definition at line 52 of file moz_extensions.c.

#define MOZ_EXPAT_EMPTY_QNAME   (1 << 0)

Definition at line 57 of file moz_extensions.c.

Definition at line 58 of file moz_extensions.c.

#define MOZ_EXPAT_MALFORMED   (1 << 2)

Definition at line 59 of file moz_extensions.c.

Definition at line 56 of file moz_extensions.c.

#define PREFIX (   ident)    big2_ ## ident

Definition at line 49 of file moz_extensions.c.


Function Documentation

int MOZ_XMLCheckQName ( const char *  ptr,
const char *  end,
int  ns_aware,
const char **  colon 
)

Definition at line 61 of file moz_extensions.c.

{
  int result = MOZ_EXPAT_VALID_QNAME;
  int nmstrt = 1;
  *colon = 0;
  if (ptr == end) {
    return MOZ_EXPAT_EMPTY_QNAME;
  }
  do {
    switch (BYTE_TYPE(ptr)) {
    case BT_COLON:
      if (ns_aware) {
        if (*colon != 0 || nmstrt || ptr + 2 == end) {
          /* We already encountered a colon or this is the first or the last
             character so the QName is malformed. */
          result |= MOZ_EXPAT_MALFORMED;
        }
        *colon = ptr;
        nmstrt = 1;
      }
      else if (nmstrt) {
        /* This is the first character so the QName is malformed. */
        result |= MOZ_EXPAT_MALFORMED;
        nmstrt = 0;
      }
      break;
    case BT_NONASCII:
      if (nmstrt) {
        if (!IS_NMSTRT_CHAR_MINBPC(ptr)) {
          /* If this is a valid name character the QName is malformed, 
             otherwise it contains an invalid character. */
          result |= IS_NAME_CHAR_MINBPC(ptr) ? MOZ_EXPAT_MALFORMED :
                                               MOZ_EXPAT_INVALID_CHARACTER;
        }
      }
      else if (!IS_NAME_CHAR_MINBPC(ptr)) {
        result |= MOZ_EXPAT_INVALID_CHARACTER;
      }
      nmstrt = 0;
      break;
    case BT_NMSTRT:
    case BT_HEX:
      nmstrt = 0;
      break;
    case BT_DIGIT:
    case BT_NAME:
    case BT_MINUS:
      if (nmstrt) {
        result |= MOZ_EXPAT_MALFORMED;
        nmstrt = 0;
      }
      break;
    default:
      result |= MOZ_EXPAT_INVALID_CHARACTER;
      nmstrt = 0;
    }
    ptr += 2;
  } while (ptr != end);
  return result;
}

Here is the caller graph for this function:

int MOZ_XMLIsLetter ( const char *  ptr)

Definition at line 123 of file moz_extensions.c.

{
  switch (BYTE_TYPE(ptr)) {
  case BT_NONASCII:
    if (!IS_NMSTRT_CHAR_MINBPC(ptr)) {
      return 0;
    }
  case BT_NMSTRT:
  case BT_HEX:
    return 1;
  default:
    return 0;
  }
}

Here is the caller graph for this function:

int MOZ_XMLIsNCNameChar ( const char *  ptr)

Definition at line 138 of file moz_extensions.c.

{
  switch (BYTE_TYPE(ptr)) {
  case BT_NONASCII:
    if (!IS_NAME_CHAR_MINBPC(ptr)) {
      return 0;
    }
  case BT_NMSTRT:
  case BT_HEX:
  case BT_DIGIT:
  case BT_NAME:
  case BT_MINUS:
    return 1;
  default:
    return 0;
  }
}

Here is the caller graph for this function:

int MOZ_XMLTranslateEntity ( const char *  ptr,
const char *  end,
const char **  next,
XML_Char result 
)

Definition at line 156 of file moz_extensions.c.

{
  const ENCODING* enc = XmlGetUtf16InternalEncodingNS();
  int tok = PREFIX(scanRef)(enc, ptr, end, next);
  if (tok <= XML_TOK_INVALID) {
    return 0;
  }

  if (tok == XML_TOK_CHAR_REF) {
    int n = XmlCharRefNumber(enc, ptr);

    // We could get away with just < 0, but better safe than sorry.
    if (n <= 0) {
      return 0;
    }

    return XmlUtf16Encode(n, (unsigned short*)result);
  }

  if (tok == XML_TOK_ENTITY_REF) {
    XML_Char ch = (XML_Char)XmlPredefinedEntityName(enc, ptr, *next - 2);
    if (!ch) {
      return 0;
    }

    *result = ch;
    return 1;
  }

  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function: