Back to index

lightning-sunbird  0.9+nobinonly
Classes | Defines | Typedefs | Enumerations | Functions | Variables
jsstr.h File Reference
#include <ctype.h>
#include "jspubtd.h"
#include "jsprvtd.h"
#include "jshash.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  JSString
struct  JSDependentString
struct  JSSubString

Defines

#define JSSTRFLAG_BITS   2
#define JSSTRFLAG_SHIFT(flg)   ((size_t)(flg) << JSSTRING_LENGTH_BITS)
#define JSSTRFLAG_MASK   JSSTRFLAG_SHIFT(JS_BITMASK(JSSTRFLAG_BITS))
#define JSSTRFLAG_DEPENDENT   JSSTRFLAG_SHIFT(1)
#define JSSTRFLAG_PREFIX   JSSTRFLAG_SHIFT(2)
#define JSSTRING_BIT(n)   ((size_t)1 << (n))
#define JSSTRING_BITMASK(n)   (JSSTRING_BIT(n) - 1)
#define JSSTRING_HAS_FLAG(str, flg)   ((str)->length & (flg))
#define JSSTRING_IS_DEPENDENT(str)   JSSTRING_HAS_FLAG(str, JSSTRFLAG_DEPENDENT)
#define JSSTRING_IS_PREFIX(str)   JSSTRING_HAS_FLAG(str, JSSTRFLAG_PREFIX)
#define JSSTRING_CHARS(str)
#define JSSTRING_LENGTH(str)
#define JSSTRING_LENGTH_BITS
#define JSSTRING_LENGTH_MASK   JSSTRING_BITMASK(JSSTRING_LENGTH_BITS)
#define JSSTRDEP_START_BITS   (JSSTRING_LENGTH_BITS-JSSTRDEP_LENGTH_BITS)
#define JSSTRDEP_START_SHIFT   JSSTRDEP_LENGTH_BITS
#define JSSTRDEP_START_MASK   JSSTRING_BITMASK(JSSTRDEP_START_BITS)
#define JSSTRDEP_LENGTH_BITS   (JSSTRING_LENGTH_BITS / 2)
#define JSSTRDEP_LENGTH_MASK   JSSTRING_BITMASK(JSSTRDEP_LENGTH_BITS)
#define JSSTRDEP(str)   ((JSDependentString *)(str))
#define JSSTRDEP_START(str)
#define JSSTRDEP_LENGTH(str)
#define JSSTRDEP_SET_START_AND_LENGTH(str, off, len)
#define JSPREFIX_SET_LENGTH(str, len)   (JSSTRDEP(str)->length = JSSTRFLAG_DEPENDENT | JSSTRFLAG_PREFIX | (len))
#define JSSTRDEP_BASE(str)   (JSSTRDEP(str)->base)
#define JSSTRDEP_SET_BASE(str, bstr)   (JSSTRDEP(str)->base = (bstr))
#define JSPREFIX_BASE(str)   JSSTRDEP_BASE(str)
#define JSPREFIX_SET_BASE(str, bstr)   JSSTRDEP_SET_BASE(str,bstr)
#define JSSTRDEP_CHARS(str)
#define JS_CCODE(c)   (js_A[js_Y[(js_X[(uint16)(c)>>6]<<6)|((c)&0x3F)]])
#define JS_CTYPE(c)   (JS_CCODE(c) & 0x1F)
#define JS_ISALPHA(c)
#define JS_ISALNUM(c)
#define JS_ISLETTER(c)
#define JS_ISIDPART(c)
#define JS_ISFORMAT(c)   (((1 << JSCT_FORMAT) >> JS_CTYPE(c)) & 1)
#define JS_ISWORD(c)   ((c) < 128 && (isalnum(c) || (c) == '_'))
#define JS_ISIDSTART(c)   (JS_ISLETTER(c) || (c) == '_' || (c) == '$')
#define JS_ISIDENT(c)   (JS_ISIDPART(c) || (c) == '_' || (c) == '$')
#define JS_ISXMLSPACE(c)
#define JS_ISXMLNSSTART(c)   ((JS_CCODE(c) & 0x00000100) || (c) == '_')
#define JS_ISXMLNS(c)
#define JS_ISXMLNAMESTART(c)   (JS_ISXMLNSSTART(c) || (c) == ':')
#define JS_ISXMLNAME(c)   (JS_ISXMLNS(c) || (c) == ':')
#define JS_ISDIGIT(c)   (JS_CTYPE(c) == JSCT_DECIMAL_DIGIT_NUMBER)
#define JS_ISSPACE(c)   ((JS_CCODE(c) & 0x00070000) == 0x00040000)
#define JS_ISPRINT(c)   ((c) < 128 && isprint(c))
#define JS_ISUPPER(c)   (JS_CTYPE(c) == JSCT_UPPERCASE_LETTER)
#define JS_ISLOWER(c)   (JS_CTYPE(c) == JSCT_LOWERCASE_LETTER)
#define JS_TOUPPER(c)
#define JS_TOLOWER(c)
#define JS7_ISDEC(c)   ((((unsigned)(c)) - '0') <= 9)
#define JS7_UNDEC(c)   ((c) - '0')
#define JS7_ISHEX(c)   ((c) < 128 && isxdigit(c))
#define JS7_UNHEX(c)   (uintN)(JS7_ISDEC(c) ? (c) - '0' : 10 + tolower(c) - 'a')
#define JS7_ISLET(c)   ((c) < 128 && isalpha(c))
#define js_ValueToPrintableString(cx, v)   js_ValueToPrintable(cx, v, js_ValueToString)
#define js_ValueToPrintableSource(cx, v)   js_ValueToPrintable(cx, v, js_ValueToSource)
#define BMH_CHARSET_SIZE   256 /* ISO-Latin-1 */
#define BMH_PATLEN_MAX   255 /* skip table element is uint8 */
#define BMH_BAD_PATTERN   (-2) /* return value if pat is not ISO-Latin-1 */
#define js_strncpy(t, s, n)   memcpy((t), (s), (n) * sizeof(jschar))

Typedefs

typedef enum JSCharType JSCharType
typedef JSString *(* JSValueToStringFun )(JSContext *cx, jsval v)

Enumerations

enum  JSCharType {
  JSCT_UNASSIGNED = 0, JSCT_UPPERCASE_LETTER = 1, JSCT_LOWERCASE_LETTER = 2, JSCT_TITLECASE_LETTER = 3,
  JSCT_MODIFIER_LETTER = 4, JSCT_OTHER_LETTER = 5, JSCT_NON_SPACING_MARK = 6, JSCT_ENCLOSING_MARK = 7,
  JSCT_COMBINING_SPACING_MARK = 8, JSCT_DECIMAL_DIGIT_NUMBER = 9, JSCT_LETTER_NUMBER = 10, JSCT_OTHER_NUMBER = 11,
  JSCT_SPACE_SEPARATOR = 12, JSCT_LINE_SEPARATOR = 13, JSCT_PARAGRAPH_SEPARATOR = 14, JSCT_CONTROL = 15,
  JSCT_FORMAT = 16, JSCT_PRIVATE_USE = 18, JSCT_SURROGATE = 19, JSCT_DASH_PUNCTUATION = 20,
  JSCT_START_PUNCTUATION = 21, JSCT_END_PUNCTUATION = 22, JSCT_CONNECTOR_PUNCTUATION = 23, JSCT_OTHER_PUNCTUATION = 24,
  JSCT_MATH_SYMBOL = 25, JSCT_CURRENCY_SYMBOL = 26, JSCT_MODIFIER_SYMBOL = 27, JSCT_OTHER_SYMBOL = 28
}

Functions

size_t js_MinimizeDependentStrings (JSString *str, int level, JSString **basep)
jscharjs_GetDependentStringChars (JSString *str)
jscharjs_GetStringChars (JSString *str)
JSStringjs_ConcatStrings (JSContext *cx, JSString *left, JSString *right)
const jscharjs_UndependString (JSContext *cx, JSString *str)
JSBool js_InitRuntimeStringState (JSContext *cx)
void js_FinishRuntimeStringState (JSContext *cx)
void js_FinishDeflatedStringCache (JSRuntime *rt)
JSObjectjs_InitStringClass (JSContext *cx, JSObject *obj)
JSStringjs_NewString (JSContext *cx, jschar *chars, size_t length, uintN gcflag)
JSStringjs_NewDependentString (JSContext *cx, JSString *base, size_t start, size_t length, uintN gcflag)
JSStringjs_NewStringCopyN (JSContext *cx, const jschar *s, size_t n, uintN gcflag)
JSStringjs_NewStringCopyZ (JSContext *cx, const jschar *s, uintN gcflag)
void js_FinalizeString (JSContext *cx, JSString *str)
void js_FinalizeStringRT (JSRuntime *rt, JSString *str)
JSObjectjs_StringToObject (JSContext *cx, JSString *str)
 JS_FRIEND_API (const char *) js_ValueToPrintable(JSContext *cx
 JS_FRIEND_API (JSString *) js_ValueToString(JSContext *cx
JSHashNumber js_HashString (JSString *str)
intN js_CompareStrings (JSString *str1, JSString *str2)
JSBool js_EqualStrings (JSString *str1, JSString *str2)
jsint js_BoyerMooreHorspool (const jschar *text, jsint textlen, const jschar *pat, jsint patlen, jsint start)
size_t js_strlen (const jschar *s)
jscharjs_strchr (const jschar *s, jschar c)
jscharjs_strchr_limit (const jschar *s, jschar c, const jschar *limit)
const jscharjs_SkipWhiteSpace (const jschar *s)
jscharjs_InflateString (JSContext *cx, const char *bytes, size_t *length)
char * js_DeflateString (JSContext *cx, const jschar *chars, size_t length)
JSBool js_InflateStringToBuffer (JSContext *cx, const char *bytes, size_t length, jschar *chars, size_t *charsLength)
JSBool js_DeflateStringToBuffer (JSContext *cx, const jschar *chars, size_t charsLength, char *bytes, size_t *length)
JSBool js_SetStringBytes (JSRuntime *rt, JSString *str, char *bytes, size_t length)
char * js_GetStringBytes (JSRuntime *rt, JSString *str)
void js_PurgeDeflatedStringCache (JSRuntime *rt, JSString *str)
JSBool js_str_escape (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
int js_OneUcs4ToUtf8Char (uint8 *utf8Buffer, uint32 ucs4Char)

Variables

jschar js_empty_ucstr []
JSSubString js_EmptySubString
const uint8 js_X []
const uint8 js_Y []
const uint32 js_A []
JSClass js_StringClass
const char js_escape_str []
const char js_unescape_str []
const char js_uneval_str []
const char js_decodeURI_str []
const char js_encodeURI_str []
const char js_decodeURIComponent_str []
const char js_encodeURIComponent_str []
jsval v
jsval JSValueToStringFun v2sfun

Class Documentation

struct JSString

Definition at line 72 of file jsstr.h.

Class Members
jschar * chars
size_t length
struct JSDependentString

Definition at line 86 of file jsstr.h.

Collaboration diagram for JSDependentString:
Class Members
JSString * base
size_t length
struct JSSubString

Definition at line 163 of file jsstr.h.

Class Members
const jschar * chars
size_t length

Define Documentation

#define BMH_BAD_PATTERN   (-2) /* return value if pat is not ISO-Latin-1 */

Definition at line 410 of file jsstr.h.

#define BMH_CHARSET_SIZE   256 /* ISO-Latin-1 */

Definition at line 407 of file jsstr.h.

#define BMH_PATLEN_MAX   255 /* skip table element is uint8 */

Definition at line 408 of file jsstr.h.

#define JS7_ISDEC (   c)    ((((unsigned)(c)) - '0') <= 9)

Definition at line 294 of file jsstr.h.

#define JS7_ISHEX (   c)    ((c) < 128 && isxdigit(c))

Definition at line 296 of file jsstr.h.

#define JS7_ISLET (   c)    ((c) < 128 && isalpha(c))

Definition at line 298 of file jsstr.h.

#define JS7_UNDEC (   c)    ((c) - '0')

Definition at line 295 of file jsstr.h.

#define JS7_UNHEX (   c)    (uintN)(JS7_ISDEC(c) ? (c) - '0' : 10 + tolower(c) - 'a')

Definition at line 297 of file jsstr.h.

#define JS_CCODE (   c)    (js_A[js_Y[(js_X[(uint16)(c)>>6]<<6)|((c)&0x3F)]])

Definition at line 209 of file jsstr.h.

#define JS_CTYPE (   c)    (JS_CCODE(c) & 0x1F)

Definition at line 210 of file jsstr.h.

Value:

Definition at line 219 of file jsstr.h.

Value:
((((1 << JSCT_UPPERCASE_LETTER) |                     \
                           (1 << JSCT_LOWERCASE_LETTER) |                     \
                           (1 << JSCT_TITLECASE_LETTER) |                     \
                           (1 << JSCT_MODIFIER_LETTER) |                      \
                           (1 << JSCT_OTHER_LETTER))                          \
                          >> JS_CTYPE(c)) & 1)

Definition at line 212 of file jsstr.h.

Definition at line 273 of file jsstr.h.

#define JS_ISFORMAT (   c)    (((1 << JSCT_FORMAT) >> JS_CTYPE(c)) & 1)

Definition at line 253 of file jsstr.h.

#define JS_ISIDENT (   c)    (JS_ISIDPART(c) || (c) == '_' || (c) == '$')

Definition at line 263 of file jsstr.h.

Value:

Definition at line 240 of file jsstr.h.

#define JS_ISIDSTART (   c)    (JS_ISLETTER(c) || (c) == '_' || (c) == '$')

Definition at line 262 of file jsstr.h.

Value:
((((1 << JSCT_UPPERCASE_LETTER) |                    \
                            (1 << JSCT_LOWERCASE_LETTER) |                    \
                            (1 << JSCT_TITLECASE_LETTER) |                    \
                            (1 << JSCT_MODIFIER_LETTER) |                     \
                            (1 << JSCT_OTHER_LETTER) |                        \
                            (1 << JSCT_LETTER_NUMBER))                        \
                           >> JS_CTYPE(c)) & 1)

Definition at line 228 of file jsstr.h.

Definition at line 281 of file jsstr.h.

#define JS_ISPRINT (   c)    ((c) < 128 && isprint(c))

Definition at line 278 of file jsstr.h.

#define JS_ISSPACE (   c)    ((JS_CCODE(c) & 0x00070000) == 0x00040000)

Definition at line 277 of file jsstr.h.

Definition at line 280 of file jsstr.h.

#define JS_ISWORD (   c)    ((c) < 128 && (isalnum(c) || (c) == '_'))

Definition at line 260 of file jsstr.h.

#define JS_ISXMLNAME (   c)    (JS_ISXMLNS(c) || (c) == ':')

Definition at line 271 of file jsstr.h.

#define JS_ISXMLNAMESTART (   c)    (JS_ISXMLNSSTART(c) || (c) == ':')

Definition at line 270 of file jsstr.h.

Value:
((JS_CCODE(c) & 0x00000080) || (c) == '.' ||  \
                                 (c) == '-' || (c) == '_')

Definition at line 268 of file jsstr.h.

#define JS_ISXMLNSSTART (   c)    ((JS_CCODE(c) & 0x00000100) || (c) == '_')

Definition at line 267 of file jsstr.h.

Value:
((c) == ' ' || (c) == '\t' || (c) == '\r' ||  \
                                 (c) == '\n')

Definition at line 265 of file jsstr.h.

#define js_strncpy (   t,
  s,
  n 
)    memcpy((t), (s), (n) * sizeof(jschar))

Definition at line 426 of file jsstr.h.

Value:
((jschar) ((JS_CCODE(c) & 0x00200000)                 \
                                   ? (c) + ((int32)JS_CCODE(c) >> 22)         \
                                   : (c)))

Definition at line 286 of file jsstr.h.

Value:
((jschar) ((JS_CCODE(c) & 0x00100000)                 \
                                   ? (c) - ((int32)JS_CCODE(c) >> 22)         \
                                   : (c)))

Definition at line 283 of file jsstr.h.

Definition at line 362 of file jsstr.h.

Definition at line 359 of file jsstr.h.

Definition at line 140 of file jsstr.h.

#define JSPREFIX_SET_BASE (   str,
  bstr 
)    JSSTRDEP_SET_BASE(str,bstr)

Definition at line 141 of file jsstr.h.

Definition at line 135 of file jsstr.h.

#define JSSTRDEP (   str)    ((JSDependentString *)(str))

Definition at line 121 of file jsstr.h.

Definition at line 138 of file jsstr.h.

Value:

Definition at line 126 of file jsstr.h.

Definition at line 118 of file jsstr.h.

Definition at line 119 of file jsstr.h.

#define JSSTRDEP_SET_BASE (   str,
  bstr 
)    (JSSTRDEP(str)->base = (bstr))

Definition at line 139 of file jsstr.h.

Value:
(JSSTRDEP(str)->length = JSSTRFLAG_DEPENDENT                              \
                           | ((off) << JSSTRDEP_START_SHIFT)                  \
                           | (len))

Definition at line 131 of file jsstr.h.

Value:

Definition at line 122 of file jsstr.h.

Definition at line 115 of file jsstr.h.

Definition at line 117 of file jsstr.h.

Definition at line 116 of file jsstr.h.

Definition at line 92 of file jsstr.h.

Definition at line 95 of file jsstr.h.

Definition at line 94 of file jsstr.h.

Definition at line 96 of file jsstr.h.

#define JSSTRFLAG_SHIFT (   flg)    ((size_t)(flg) << JSSTRING_LENGTH_BITS)

Definition at line 93 of file jsstr.h.

#define JSSTRING_BIT (   n)    ((size_t)1 << (n))

Definition at line 99 of file jsstr.h.

#define JSSTRING_BITMASK (   n)    (JSSTRING_BIT(n) - 1)

Definition at line 100 of file jsstr.h.

Value:

Definition at line 104 of file jsstr.h.

#define JSSTRING_HAS_FLAG (   str,
  flg 
)    ((str)->length & (flg))

Definition at line 101 of file jsstr.h.

Definition at line 102 of file jsstr.h.

Definition at line 103 of file jsstr.h.

Value:

Definition at line 107 of file jsstr.h.

Value:
(sizeof(size_t) * JS_BITS_PER_BYTE        \
                                     - JSSTRFLAG_BITS)

Definition at line 110 of file jsstr.h.

Definition at line 112 of file jsstr.h.


Typedef Documentation

typedef enum JSCharType JSCharType

Definition at line 354 of file jsstr.h.


Enumeration Type Documentation

enum JSCharType
Enumerator:
JSCT_UNASSIGNED 
JSCT_UPPERCASE_LETTER 
JSCT_LOWERCASE_LETTER 
JSCT_TITLECASE_LETTER 
JSCT_MODIFIER_LETTER 
JSCT_OTHER_LETTER 
JSCT_NON_SPACING_MARK 
JSCT_ENCLOSING_MARK 
JSCT_COMBINING_SPACING_MARK 
JSCT_DECIMAL_DIGIT_NUMBER 
JSCT_LETTER_NUMBER 
JSCT_OTHER_NUMBER 
JSCT_SPACE_SEPARATOR 
JSCT_LINE_SEPARATOR 
JSCT_PARAGRAPH_SEPARATOR 
JSCT_CONTROL 
JSCT_FORMAT 
JSCT_PRIVATE_USE 
JSCT_SURROGATE 
JSCT_DASH_PUNCTUATION 
JSCT_START_PUNCTUATION 
JSCT_END_PUNCTUATION 
JSCT_CONNECTOR_PUNCTUATION 
JSCT_OTHER_PUNCTUATION 
JSCT_MATH_SYMBOL 
JSCT_CURRENCY_SYMBOL 
JSCT_MODIFIER_SYMBOL 
JSCT_OTHER_SYMBOL 

Definition at line 177 of file jsstr.h.


Function Documentation

jsint js_BoyerMooreHorspool ( const jschar text,
jsint  textlen,
const jschar pat,
jsint  patlen,
jsint  start 
)

Definition at line 952 of file jsstr.c.

{
    jsint i, j, k, m;
    uint8 skip[BMH_CHARSET_SIZE];
    jschar c;

    JS_ASSERT(0 < patlen && patlen <= BMH_PATLEN_MAX);
    for (i = 0; i < BMH_CHARSET_SIZE; i++)
        skip[i] = (uint8)patlen;
    m = patlen - 1;
    for (i = 0; i < m; i++) {
        c = pat[i];
        if (c >= BMH_CHARSET_SIZE)
            return BMH_BAD_PATTERN;
        skip[c] = (uint8)(m - i);
    }
    for (k = start + m;
         k < textlen;
         k += ((c = text[k]) >= BMH_CHARSET_SIZE) ? patlen : skip[c]) {
        for (i = k, j = m; ; i--, j--) {
            if (j < 0)
                return i + 1;
            if (text[i] != pat[j])
                break;
        }
    }
    return -1;
}

Here is the caller graph for this function:

intN js_CompareStrings ( JSString str1,
JSString str2 
)

Definition at line 2740 of file jsstr.c.

{
    size_t l1, l2, n, i;
    const jschar *s1, *s2;
    intN cmp;

    JS_ASSERT(str1);
    JS_ASSERT(str2);

    /* Fast case: pointer equality could be a quick win. */
    if (str1 == str2)
        return 0;

    l1 = JSSTRING_LENGTH(str1), l2 = JSSTRING_LENGTH(str2);
    s1 = JSSTRING_CHARS(str1),  s2 = JSSTRING_CHARS(str2);
    n = JS_MIN(l1, l2);
    for (i = 0; i < n; i++) {
        cmp = s1[i] - s2[i];
        if (cmp != 0)
            return cmp;

Here is the caller graph for this function:

JSString* js_ConcatStrings ( JSContext cx,
JSString left,
JSString right 
)

Definition at line 129 of file jsstr.c.

{
    size_t rn, ln, lrdist, n;
    jschar *rs, *ls, *s;
    JSDependentString *ldep;    /* non-null if left should become dependent */
    JSString *str;

    if (JSSTRING_IS_DEPENDENT(right)) {
        rn = JSSTRDEP_LENGTH(right);
        rs = JSSTRDEP_CHARS(right);
    } else {
        rn = right->length;
        rs = right->chars;
    }
    if (rn == 0)
        return left;

    if (JSSTRING_IS_DEPENDENT(left) ||
        !(*js_GetGCThingFlags(left) & GCF_MUTABLE)) {
        /* We must copy if left does not own a buffer to realloc. */
        ln = JSSTRING_LENGTH(left);
        if (ln == 0)
            return right;
        ls = JSSTRING_CHARS(left);
        s = (jschar *) JS_malloc(cx, (ln + rn + 1) * sizeof(jschar));
        if (!s)
            return NULL;
        js_strncpy(s, ls, ln);
        ldep = NULL;
    } else {
        /* We can realloc left's space and make it depend on our result. */
        ln = left->length;
        if (ln == 0)
            return right;
        ls = left->chars;
        s = (jschar *) JS_realloc(cx, ls, (ln + rn + 1) * sizeof(jschar));
        if (!s)
            return NULL;

        /* Take care: right could depend on left! */
        lrdist = (size_t)(rs - ls);
        if (lrdist < ln)
            rs = s + lrdist;
        left->chars = ls = s;
        ldep = JSSTRDEP(left);
    }

    js_strncpy(s + ln, rs, rn);
    n = ln + rn;
    s[n] = 0;
    str = js_NewString(cx, s, n, GCF_MUTABLE);
    if (!str) {
        /* Out of memory: clean up any space we (re-)allocated. */
        if (!ldep) {
            JS_free(cx, s);
        } else {
            s = JS_realloc(cx, ls, (ln + 1) * sizeof(jschar));
            if (s)
                left->chars = s;
        }
    } else {
        /* Morph left into a dependent prefix if we realloc'd its buffer. */
        if (ldep) {
            JSPREFIX_SET_LENGTH(ldep, ln);
            JSPREFIX_SET_BASE(ldep, str);
#ifdef DEBUG
          {
            JSRuntime *rt = cx->runtime;
            JS_RUNTIME_METER(rt, liveDependentStrings);
            JS_RUNTIME_METER(rt, totalDependentStrings);
            JS_LOCK_RUNTIME_VOID(rt,
                (rt->strdepLengthSum += (double)ln,
                 rt->strdepLengthSquaredSum += (double)ln * (double)ln));
          }
#endif
        }
    }

    return str;
}

Here is the call graph for this function:

Here is the caller graph for this function:

char* js_DeflateString ( JSContext cx,
const jschar chars,
size_t  length 
)

Definition at line 3092 of file jsstr.c.

{
    size_t i, size;
    char *bytes;

    size = (length + 1) * sizeof(char);
    bytes = (char *) (cx ? JS_malloc(cx, size) : malloc(size));
    if (!bytes)
        return NULL;

    for (i = 0; i < length; i++)
        bytes[i] = (char) chars[i];

Here is the call graph for this function:

Here is the caller graph for this function:

JSBool js_DeflateStringToBuffer ( JSContext cx,
const jschar chars,
size_t  charsLength,
char *  bytes,
size_t *  length 
)

Definition at line 3068 of file jsstr.c.

{
    size_t i;

    if (length > *bytesLength) {
        for (i = 0; i < *bytesLength; i++)
            bytes[i] = (char) chars[i];
        if (cx) {
            JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
                                 JSMSG_BUFFER_TOO_SMALL);
        }
        return JS_FALSE;
    }
    for (i = 0; i < length; i++)
        bytes[i] = (char) chars[i];

Here is the caller graph for this function:

JSBool js_EqualStrings ( JSString str1,
JSString str2 
)

Definition at line 2765 of file jsstr.c.

{
    size_t n;
    const jschar *s1, *s2;

    JS_ASSERT(str1);
    JS_ASSERT(str2);

    /* Fast case: pointer equality could be a quick win. */
    if (str1 == str2)
        return JS_TRUE;

    n = JSSTRING_LENGTH(str1);
    if (n != JSSTRING_LENGTH(str2))
        return JS_FALSE;

    if (n == 0)
        return JS_TRUE;

    s1 = JSSTRING_CHARS(str1), s2 = JSSTRING_CHARS(str2);
    do {
        if (*s1 != *s2)
            return JS_FALSE;
        ++s1, ++s2;
    } while (--n != 0);

Here is the caller graph for this function:

void js_FinalizeString ( JSContext cx,
JSString str 
)

Definition at line 2609 of file jsstr.c.

{
void js_FinalizeStringRT ( JSRuntime rt,
JSString str 
)

Definition at line 2615 of file jsstr.c.

{
    JSBool valid;

    JS_RUNTIME_UNMETER(rt, liveStrings);
    if (JSSTRING_IS_DEPENDENT(str)) {
        /* If JSSTRFLAG_DEPENDENT is set, this string must be valid. */
        JS_ASSERT(JSSTRDEP_BASE(str));
        JS_RUNTIME_UNMETER(rt, liveDependentStrings);
        valid = JS_TRUE;
    } else {
        /* A stillborn string has null chars, so is not valid. */
        valid = (str->chars != NULL);
        if (valid)
            free(str->chars);
    }
    if (valid) {
        js_PurgeDeflatedStringCache(rt, str);
        str->chars = NULL;

Here is the caller graph for this function:

Definition at line 2396 of file jsstr.c.

{
    if (rt->deflatedStringCache) {
        JS_HashTableDestroy(rt->deflatedStringCache);
        rt->deflatedStringCache = NULL;
    }
#ifdef JS_THREADSAFE
    if (rt->deflatedStringCacheLock) {
        JS_DESTROY_LOCK(rt->deflatedStringCacheLock);
        rt->deflatedStringCacheLock = NULL;

Here is the caller graph for this function:

Definition at line 2387 of file jsstr.c.

{
    JSRuntime *rt = cx->runtime;

Here is the caller graph for this function:

JS_FRIEND_API ( const char *  )

Definition at line 107 of file jsstr.c.

{
    size_t start;
    JSString *base;

    start = js_MinimizeDependentStrings(str, 0, &base);
    JS_ASSERT(!JSSTRING_IS_DEPENDENT(base));
    JS_ASSERT(start < base->length);
    return base->chars + start;
}

Here is the call graph for this function:

char* js_GetStringBytes ( JSRuntime rt,
JSString str 
)

Definition at line 3155 of file jsstr.c.

{
    JSHashTable *cache;
    char *bytes;
    JSHashNumber hash;
    JSHashEntry *he, **hep;

    JS_ACQUIRE_LOCK(rt->deflatedStringCacheLock);

    cache = GetDeflatedStringCache(rt);
    if (!cache) {
        bytes = NULL;
    } else {
        hash = js_hash_string_pointer(str);
        hep = JS_HashTableRawLookup(cache, hash, str);
        he = *hep;
        if (he) {
            bytes = (char *) he->value;

            /* Try to catch failure to JS_ShutDown between runtime epochs. */
            JS_ASSERT((*bytes == '\0' && JSSTRING_LENGTH(str) == 0) ||
                      *bytes == (char) JSSTRING_CHARS(str)[0]);
        } else {
            bytes = js_DeflateString(NULL, JSSTRING_CHARS(str),
                                           JSSTRING_LENGTH(str));
            if (bytes) {
                if (JS_HashTableRawAdd(cache, hep, hash, str, bytes)) {
#ifdef DEBUG
                    rt->deflatedStringCacheBytes += JSSTRING_LENGTH(str);
#endif
                } else {
                    free(bytes);
                    bytes = NULL;
                }
            }
        }
    }

Here is the caller graph for this function:

Definition at line 119 of file jsstr.c.

{
    if (JSSTRING_IS_DEPENDENT(str) && !js_UndependString(NULL, str))
        return NULL;

    *js_GetGCThingFlags(str) &= ~GCF_MUTABLE;
    return str->chars;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 2727 of file jsstr.c.

{
    JSHashNumber h;
    const jschar *s;
    size_t n;

    h = 0;
    for (s = JSSTRING_CHARS(str), n = JSSTRING_LENGTH(str); n; s++, n--)

Here is the caller graph for this function:

jschar* js_InflateString ( JSContext cx,
const char *  bytes,
size_t *  length 
)

Definition at line 3050 of file jsstr.c.

{
    jschar *chars;
    size_t i, length = *bytesLength;

    chars = (jschar *) JS_malloc(cx, (length + 1) * sizeof(jschar));
    if (!chars) {
        *bytesLength = 0;
        return NULL;
    }
    for (i = 0; i < length; i++)
        chars[i] = (unsigned char) bytes[i];
    chars[length] = 0;

Here is the caller graph for this function:

JSBool js_InflateStringToBuffer ( JSContext cx,
const char *  bytes,
size_t  length,
jschar chars,
size_t *  charsLength 
)

Definition at line 3029 of file jsstr.c.

{
    size_t i;

    if (length > *charsLength) {
        for (i = 0; i < *charsLength; i++)
            chars[i] = (unsigned char) bytes[i];
        if (cx) {
            JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
                                 JSMSG_BUFFER_TOO_SMALL);
        }
        return JS_FALSE;
    }
    for (i = 0; i < length; i++)
        chars[i] = (unsigned char) bytes[i];

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 2345 of file jsstr.c.

{
    JSRuntime *rt;
    JSString *empty;
    JSAtom *atom;

    rt = cx->runtime;

    /* Initialize string cache */
#ifdef JS_THREADSAFE
    JS_ASSERT(!rt->deflatedStringCacheLock);
    rt->deflatedStringCacheLock = JS_NEW_LOCK();
    if (!rt->deflatedStringCacheLock)
        return JS_FALSE;
#endif

    /* Make a permanently locked empty string. */
    JS_ASSERT(!rt->emptyString);
    empty = js_NewStringCopyN(cx, js_empty_ucstr, 0, GCF_LOCK);
    if (!empty)
        goto bad;

    /* Atomize it for scripts that use '' + x to convert x to string. */
    atom = js_AtomizeString(cx, empty, ATOM_PINNED);
    if (!atom)
        goto bad;

    rt->emptyString = empty;
    rt->atomState.emptyAtom = atom;

    return JS_TRUE;

  bad:
#ifdef JS_THREADSAFE
    JS_DESTROY_LOCK(rt->deflatedStringCacheLock);
    rt->deflatedStringCacheLock = NULL;
#endif

Here is the caller graph for this function:

Definition at line 2411 of file jsstr.c.

{
    JSObject *proto;

    /* Define the escape, unescape functions in the global object. */
    if (!JS_DefineFunctions(cx, obj, string_functions))
        return NULL;

    proto = JS_InitClass(cx, obj, NULL, &js_StringClass, String, 1,
                         string_props, string_methods,
                         NULL, string_static_methods);
    if (!proto)
        return NULL;
    OBJ_SET_SLOT(cx, proto, JSSLOT_PRIVATE,

Here is the caller graph for this function:

size_t js_MinimizeDependentStrings ( JSString str,
int  level,
JSString **  basep 
)

Definition at line 76 of file jsstr.c.

{
    JSString *base;
    size_t start, length;

    JS_ASSERT(JSSTRING_IS_DEPENDENT(str));
    base = JSSTRDEP_BASE(str);
    start = JSSTRDEP_START(str);
    if (JSSTRING_IS_DEPENDENT(base)) {
        if (level < JSSTRDEP_RECURSION_LIMIT) {
            start += js_MinimizeDependentStrings(base, level + 1, &base);
        } else {
            do {
                start += JSSTRDEP_START(base);
                base = JSSTRDEP_BASE(base);
            } while (JSSTRING_IS_DEPENDENT(base));
        }
        if (start == 0) {
            JS_ASSERT(JSSTRING_IS_PREFIX(str));
            JSPREFIX_SET_BASE(str, base);
        } else if (start <= JSSTRDEP_START_MASK) {
            length = JSSTRDEP_LENGTH(str);
            JSSTRDEP_SET_START_AND_LENGTH(str, start, length);
            JSSTRDEP_SET_BASE(str, base);
        }
    }
    *basep = base;
    return start;
}

Here is the call graph for this function:

Here is the caller graph for this function:

JSString* js_NewDependentString ( JSContext cx,
JSString base,
size_t  start,
size_t  length,
uintN  gcflag 
)

Definition at line 2458 of file jsstr.c.

{
    JSDependentString *ds;

    if (length == 0)
        return cx->runtime->emptyString;

    if (start == 0 && length == JSSTRING_LENGTH(base))
        return base;

    if (start > JSSTRDEP_START_MASK ||
        (start != 0 && length > JSSTRDEP_LENGTH_MASK)) {
        return js_NewStringCopyN(cx, JSSTRING_CHARS(base) + start, length,
                                 gcflag);
    }

    ds = (JSDependentString *)
         js_NewGCThing(cx, gcflag | GCX_MUTABLE_STRING, sizeof(JSString));
    if (!ds)
        return NULL;
    if (start == 0) {
        JSPREFIX_SET_LENGTH(ds, length);
        JSPREFIX_SET_BASE(ds, base);
    } else {
        JSSTRDEP_SET_START_AND_LENGTH(ds, start, length);
        JSSTRDEP_SET_BASE(ds, base);
    }
#ifdef DEBUG
  {
    JSRuntime *rt = cx->runtime;
    JS_RUNTIME_METER(rt, liveDependentStrings);
    JS_RUNTIME_METER(rt, totalDependentStrings);
    JS_RUNTIME_METER(rt, liveStrings);
    JS_RUNTIME_METER(rt, totalStrings);
    JS_LOCK_RUNTIME_VOID(rt,
        (rt->strdepLengthSum += (double)length,
         rt->strdepLengthSquaredSum += (double)length * (double)length));
    JS_LOCK_RUNTIME_VOID(rt,
        (rt->lengthSum += (double)length,
         rt->lengthSquaredSum += (double)length * (double)length));
  }

Here is the caller graph for this function:

JSString* js_NewString ( JSContext cx,
jschar chars,
size_t  length,
uintN  gcflag 
)

Definition at line 2430 of file jsstr.c.

{
    JSString *str;

    if (length > JSSTRING_LENGTH_MASK) {
        JS_ReportOutOfMemory(cx);
        return NULL;
    }

    str = (JSString *) js_NewGCThing(cx, gcflag | GCX_STRING, sizeof(JSString));
    if (!str)
        return NULL;
    str->length = length;
    str->chars = chars;
#ifdef DEBUG
  {
    JSRuntime *rt = cx->runtime;
    JS_RUNTIME_METER(rt, liveStrings);
    JS_RUNTIME_METER(rt, totalStrings);
    JS_LOCK_RUNTIME_VOID(rt,
        (rt->lengthSum += (double)length,
         rt->lengthSquaredSum += (double)length * (double)length));
  }

Here is the caller graph for this function:

JSString* js_NewStringCopyN ( JSContext cx,
const jschar s,
size_t  n,
uintN  gcflag 
)

Definition at line 2544 of file jsstr.c.

{
    jschar *news;
    JSString *str;

    news = (jschar *)JS_malloc(cx, (n + 1) * sizeof(jschar));
    if (!news)
        return NULL;
    js_strncpy(news, s, n);
    news[n] = 0;
    str = js_NewString(cx, news, n, gcflag);
    if (!str)

Here is the call graph for this function:

Here is the caller graph for this function:

JSString* js_NewStringCopyZ ( JSContext cx,
const jschar s,
uintN  gcflag 
)

Definition at line 2561 of file jsstr.c.

{
    size_t n, m;
    jschar *news;
    JSString *str;

    n = js_strlen(s);
    m = (n + 1) * sizeof(jschar);
    news = (jschar *) JS_malloc(cx, m);
    if (!news)
        return NULL;
    memcpy(news, s, m);
    str = js_NewString(cx, news, n, gcflag);
    if (!str)

Here is the caller graph for this function:

int js_OneUcs4ToUtf8Char ( uint8 utf8Buffer,
uint32  ucs4Char 
)

Definition at line 4756 of file jsstr.c.

{
    int utf8Length = 1;

    JS_ASSERT(ucs4Char <= 0x7FFFFFFF);
    if (ucs4Char < 0x80) {
        *utf8Buffer = (uint8)ucs4Char;
    } else {
        int i;
        uint32 a = ucs4Char >> 11;
        utf8Length = 2;
        while (a) {
            a >>= 5;
            utf8Length++;
        }
        i = utf8Length;
        while (--i) {
            utf8Buffer[i] = (uint8)((ucs4Char & 0x3F) | 0x80);
            ucs4Char >>= 6;
        }
        *utf8Buffer = (uint8)(0x100 - (1 << (8-utf8Length)) + ucs4Char);

Here is the caller graph for this function:

Definition at line 2586 of file jsstr.c.

{
    JSHashNumber hash;
    JSHashEntry *he, **hep;

    if (!rt->deflatedStringCache)
        return;

    hash = js_hash_string_pointer(str);
    JS_ACQUIRE_LOCK(rt->deflatedStringCacheLock);
    hep = JS_HashTableRawLookup(rt->deflatedStringCache, hash, str);
    he = *hep;
    if (he) {
#ifdef DEBUG
        rt->deflatedStringCacheBytes -= JSSTRING_LENGTH(str);
#endif
        free(he->value);
        JS_HashTableRawRemove(rt->deflatedStringCache, hep, he);

Here is the caller graph for this function:

JSBool js_SetStringBytes ( JSRuntime rt,
JSString str,
char *  bytes,
size_t  length 
)

Definition at line 3127 of file jsstr.c.

{
    JSHashTable *cache;
    JSBool ok;
    JSHashNumber hash;
    JSHashEntry **hep;

    JS_ACQUIRE_LOCK(rt->deflatedStringCacheLock);

    cache = GetDeflatedStringCache(rt);
    if (!cache) {
        ok = JS_FALSE;
    } else {
        hash = js_hash_string_pointer(str);
        hep = JS_HashTableRawLookup(cache, hash, str);
        JS_ASSERT(*hep == NULL);
        ok = JS_HashTableRawAdd(cache, hep, hash, str, bytes) != NULL;
#ifdef DEBUG
        if (ok)
            rt->deflatedStringCacheBytes += length;
#endif
    }

Here is the caller graph for this function:

Definition at line 2827 of file jsstr.c.

{
    /* JS_ISSPACE is false on a null. */
    while (JS_ISSPACE(*s))

Here is the caller graph for this function:

JSBool js_str_escape ( JSContext cx,
JSObject obj,
uintN  argc,
jsval argv,
jsval rval 
)

Definition at line 310 of file jsstr.c.

{
    JSString *str;
    size_t i, ni, length, newlength;
    const jschar *chars;
    jschar *newchars;
    jschar ch;
    jsint mask;
    jsdouble d;
    const char digits[] = {'0', '1', '2', '3', '4', '5', '6', '7',
                           '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };

    mask = URL_XALPHAS | URL_XPALPHAS | URL_PATH;
    if (argc > 1) {
        if (!js_ValueToNumber(cx, argv[1], &d))
            return JS_FALSE;
        if (!JSDOUBLE_IS_FINITE(d) ||
            (mask = (jsint)d) != d ||
            mask & ~(URL_XALPHAS | URL_XPALPHAS | URL_PATH))
        {
            char numBuf[12];
            JS_snprintf(numBuf, sizeof numBuf, "%lx", (unsigned long) mask);
            JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
                                 JSMSG_BAD_STRING_MASK, numBuf);
            return JS_FALSE;
        }
    }

    str = js_ValueToString(cx, argv[0]);
    if (!str)
        return JS_FALSE;
    argv[0] = STRING_TO_JSVAL(str);

    chars = JSSTRING_CHARS(str);
    length = newlength = JSSTRING_LENGTH(str);

    /* Take a first pass and see how big the result string will need to be. */
    for (i = 0; i < length; i++) {
        if ((ch = chars[i]) < 128 && IS_OK(ch, mask))
            continue;
        if (ch < 256) {
            if (mask == URL_XPALPHAS && ch == ' ')
                continue;   /* The character will be encoded as '+' */
            newlength += 2; /* The character will be encoded as %XX */
        } else {
            newlength += 5; /* The character will be encoded as %uXXXX */
        }

        /*
         * This overflow test works because newlength is incremented by at
         * most 5 on each iteration.
         */
        if (newlength < length) {
            JS_ReportOutOfMemory(cx);
            return JS_FALSE;
        }
    }

    if (newlength >= ~(size_t)0 / sizeof(jschar)) {
        JS_ReportOutOfMemory(cx);
        return JS_FALSE;
    }

    newchars = (jschar *) JS_malloc(cx, (newlength + 1) * sizeof(jschar));
    if (!newchars)
        return JS_FALSE;
    for (i = 0, ni = 0; i < length; i++) {
        if ((ch = chars[i]) < 128 && IS_OK(ch, mask)) {
            newchars[ni++] = ch;
        } else if (ch < 256) {
            if (mask == URL_XPALPHAS && ch == ' ') {
                newchars[ni++] = '+'; /* convert spaces to pluses */
            } else {
                newchars[ni++] = '%';
                newchars[ni++] = digits[ch >> 4];
                newchars[ni++] = digits[ch & 0xF];
            }
        } else {
            newchars[ni++] = '%';
            newchars[ni++] = 'u';
            newchars[ni++] = digits[ch >> 12];
            newchars[ni++] = digits[(ch & 0xF00) >> 8];
            newchars[ni++] = digits[(ch & 0xF0) >> 4];
            newchars[ni++] = digits[ch & 0xF];
        }
    }
    JS_ASSERT(ni == newlength);
    newchars[newlength] = 0;

    str = js_NewString(cx, newchars, newlength, 0);
    if (!str) {
        JS_free(cx, newchars);
        return JS_FALSE;
    }
    *rval = STRING_TO_JSVAL(str);
    return JS_TRUE;
}

Here is the call graph for this function:

jschar* js_strchr ( const jschar s,
jschar  c 
)

Definition at line 2805 of file jsstr.c.

{
    while (*s != 0) {
        if (*s == c)
            return (jschar *)s;
        s++;

Here is the caller graph for this function:

jschar* js_strchr_limit ( const jschar s,
jschar  c,
const jschar limit 
)

Definition at line 2816 of file jsstr.c.

{
    while (s < limit) {
        if (*s == c)
            return (jschar *)s;
        s++;

Here is the caller graph for this function:

JSObject* js_StringToObject ( JSContext cx,
JSString str 
)

Definition at line 2639 of file jsstr.c.

{
    JSObject *obj;

    obj = js_NewObject(cx, &js_StringClass, NULL, NULL);
    if (!obj)
        return NULL;

Here is the caller graph for this function:

size_t js_strlen ( const jschar s)

Definition at line 2795 of file jsstr.c.

{
    const jschar *t;

    for (t = s; *t != 0; t++)

Here is the caller graph for this function:

Definition at line 215 of file jsstr.c.

{
    size_t n, size;
    jschar *s;

    if (JSSTRING_IS_DEPENDENT(str)) {
        n = JSSTRDEP_LENGTH(str);
        size = (n + 1) * sizeof(jschar);
        s = (jschar *) (cx ? JS_malloc(cx, size) : malloc(size));
        if (!s)
            return NULL;

        js_strncpy(s, JSSTRDEP_CHARS(str), n);
        s[n] = 0;
        str->length = n;
        str->chars = s;

#ifdef DEBUG
        if (cx) {
            JSRuntime *rt = cx->runtime;
            JS_RUNTIME_UNMETER(rt, liveDependentStrings);
            JS_RUNTIME_UNMETER(rt, totalDependentStrings);
            JS_LOCK_RUNTIME_VOID(rt,
                (rt->strdepLengthSum -= (double)n,
                 rt->strdepLengthSquaredSum -= (double)n * (double)n));
        }
#endif
    }

    return str->chars;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

Definition at line 4358 of file jsstr.c.

Definition at line 483 of file jsstr.c.

Definition at line 485 of file jsstr.c.

Definition at line 502 of file jsstr.c.

Definition at line 503 of file jsstr.c.

Definition at line 484 of file jsstr.c.

Definition at line 486 of file jsstr.c.

Definition at line 478 of file jsstr.c.

Definition at line 601 of file jsstr.c.

Definition at line 479 of file jsstr.c.

Definition at line 481 of file jsstr.c.

Definition at line 3244 of file jsstr.c.

Definition at line 3377 of file jsstr.c.

Definition at line 357 of file jsstr.h.

Definition at line 357 of file jsstr.h.