/[jscoverage]/trunk/js/jsstr.h
ViewVC logotype

Diff of /trunk/js/jsstr.h

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 506 by siliconforks, Sat Sep 26 23:15:22 2009 UTC revision 507 by siliconforks, Sun Jan 10 07:23:34 2010 UTC
# Line 1  Line 1 
1  /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-  /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2   *   *
3   * ***** BEGIN LICENSE BLOCK *****   * ***** BEGIN LICENSE BLOCK *****
4   * Version: MPL 1.1/GPL 2.0/LGPL 2.1   * Version: MPL 1.1/GPL 2.0/LGPL 2.1
# Line 51  Line 51 
51  #include <ctype.h>  #include <ctype.h>
52  #include "jspubtd.h"  #include "jspubtd.h"
53  #include "jsprvtd.h"  #include "jsprvtd.h"
54    #include "jslock.h"
55    
56  JS_BEGIN_EXTERN_C  JS_BEGIN_EXTERN_C
57    
58    #define JSSTRING_BIT(n)             ((size_t)1 << (n))
59    #define JSSTRING_BITMASK(n)         (JSSTRING_BIT(n) - 1)
60    
61    #ifdef __cplusplus /* Allow inclusion from LiveConnect C files. */
62    class TraceRecorder;
63    #endif
64    
65    enum {
66        UNIT_STRING_LIMIT        = 256U,
67        INT_STRING_LIMIT         = 256U
68    };
69    
70    extern jschar *
71    js_GetDependentStringChars(JSString *str);
72    
73  /*  /*
74   * The GC-thing "string" type.   * The GC-thing "string" type.
75   *   *
76   * When the JSSTRFLAG_DEPENDENT bit of the length field is unset, the u.chars   * When the DEPENDENT bit of the mLength field is unset, the mChars field
77   * field points to a flat character array owned by its GC-thing descriptor.   * points to a flat character array owned by its GC-thing descriptor.  The
78   * The array is terminated at index length by a zero character and the size of   * array is terminated at index length by a zero character and the size of the
79   * the array in bytes is (length + 1) * sizeof(jschar). The terminator is   * array in bytes is (length + 1) * sizeof(jschar). The terminator is purely a
80   * purely a backstop, in case the chars pointer flows out to native code that   * backstop, in case the chars pointer flows out to native code that requires
81   * requires \u0000 termination.   * \u0000 termination.
82   *   *
83   * A flat string with JSSTRFLAG_MUTABLE set means that the string is accessible   * A flat string with the MUTABLE flag means that the string is accessible only
84   * only from one thread and it is possible to turn it into a dependent string   * from one thread and it is possible to turn it into a dependent string of the
85   * of the same length to optimize js_ConcatStrings. It is also possible to grow   * same length to optimize js_ConcatStrings. It is also possible to grow such a
86   * such a string, but extreme care must be taken to ensure that no other code   * string, but extreme care must be taken to ensure that no other code relies
87   * relies on the original length of the string.   * on the original length of the string.
88   *   *
89   * A flat string with JSSTRFLAG_ATOMIZED set means that the string is hashed as   * A flat string with the ATOMIZED flag means that the string is hashed as
90   * an atom. This flag is used to avoid re-hashing the already-atomized string.   * an atom. This flag is used to avoid re-hashing the already-atomized string.
91   *   *
92   * Any string with JSSTRFLAG_DEFLATED set means that the string has an entry   * Any string with the DEFLATED flag means that the string has an entry in the
93   * in the deflated string cache. The GC uses this flag to optimize string   * deflated string cache. The GC uses this flag to optimize string finalization
94   * finalization and avoid an expensive cache lookup for strings that were   * and avoid an expensive cache lookup for strings that were never deflated.
95   * never deflated.   *
96   *   * When the DEPENDENT flag is set, the string depends on characters of another
97   * When JSSTRFLAG_DEPENDENT is set, the string depends on characters of another   * string strongly referenced by the mBase field. The base member may point to
98   * string strongly referenced by the u.base field. The base member may point to   * another dependent string if chars() has not been called yet.
  * another dependent string if JSSTRING_CHARS has not been called yet.  
99   *   *
100   * JSSTRFLAG_PREFIX determines the kind of the dependent string. When the flag   * The PREFIX flag determines the kind of the dependent string. When the flag
101   * is unset, the length field encodes both starting position relative to the   * is unset, the mLength field encodes both starting position relative to the
102   * base string and the number of characters in the dependent string, see   * base string and the number of characters in the dependent string, see
103   * JSSTRDEP_START_MASK and JSSTRDEP_LENGTH_MASK macros below for details.   * DEPENDENT_START_MASK and DEPENDENT_LENGTH_MASK below for details.
104   *   *
105   * When JSSTRFLAG_PREFIX is set, the dependent string is a prefix of the base   * When the PREFIX flag is set, the dependent string is a prefix of the base
106   * string. The number of characters in the prefix is encoded using all non-flag   * string. The number of characters in the prefix is encoded using all non-flag
107   * bits of the length field and spans the same 0 .. SIZE_T_MAX/4 range as the   * bits of the mLength field and spans the same 0 .. SIZE_T_MAX/4 range as the
108   * length of the flat string.   * length of the flat string.
109   *   *
110   * NB: Always use the JSSTRING_LENGTH and JSSTRING_CHARS accessor macros.   * NB: Always use the length() and chars() accessor methods.
111   */   */
112    #ifdef __cplusplus /* Allow inclusion from LiveConnect C files. */
113    struct JSString {
114        friend class TraceRecorder;
115    
116        friend JSAtom *
117        js_AtomizeString(JSContext *cx, JSString *str, uintN flags);
118    
119        friend JSString * JS_FASTCALL
120        js_ConcatStrings(JSContext *cx, JSString *left, JSString *right);
121    
122        size_t          mLength;
123        union {
124            jschar      *mChars;
125            JSString    *mBase;
126        };
127    
128        /*
129         * Definitions for flags stored in the high order bits of mLength.
130         *
131         * PREFIX and MUTABLE are two aliases for the same bit.  PREFIX should be
132         * used only if DEPENDENT is set and MUTABLE should be used only if the
133         * string is flat.
134         *
135         * ATOMIZED is used only with flat, immutable strings.
136         */
137        enum
138    #if defined(_MSC_VER) && defined(_WIN64)
139        : size_t /* VC++ 64-bit incorrectly defaults this enum's size to int. */
140    #endif
141        {
142            DEPENDENT =     JSSTRING_BIT(JS_BITS_PER_WORD - 1),
143            PREFIX =        JSSTRING_BIT(JS_BITS_PER_WORD - 2),
144            MUTABLE =       PREFIX,
145            ATOMIZED =      JSSTRING_BIT(JS_BITS_PER_WORD - 3),
146            DEFLATED =      JSSTRING_BIT(JS_BITS_PER_WORD - 4),
147    
148    #if JS_BITS_PER_WORD > 32
149            LENGTH_BITS =   28,
150    #else
151            LENGTH_BITS =   JS_BITS_PER_WORD - 4,
152    #endif
153            LENGTH_MASK =   JSSTRING_BITMASK(LENGTH_BITS),
154    
155            /*
156             * VC++ 64-bit incorrectly produces the compiler error "Conversion to
157             * enumeration type requires an explicit cast" unless we cast to size_t
158             * here.
159             */
160            DEPENDENT_LENGTH_BITS = size_t(LENGTH_BITS) / 2,
161            DEPENDENT_LENGTH_MASK = JSSTRING_BITMASK(DEPENDENT_LENGTH_BITS),
162            DEPENDENT_START_BITS =  LENGTH_BITS - DEPENDENT_LENGTH_BITS,
163            DEPENDENT_START_SHIFT = DEPENDENT_LENGTH_BITS,
164            DEPENDENT_START_MASK =  JSSTRING_BITMASK(DEPENDENT_START_BITS)
165        };
166    
167        bool hasFlag(size_t flag) const {
168            return (mLength & flag) != 0;
169        }
170    
171      public:
172        enum
173    #if defined(_MSC_VER) && defined(_WIN64)
174        : size_t /* VC++ 64-bit incorrectly defaults this enum's size to int. */
175    #endif
176        {
177            MAX_LENGTH = LENGTH_MASK,
178            MAX_DEPENDENT_START = DEPENDENT_START_MASK,
179            MAX_DEPENDENT_LENGTH = DEPENDENT_LENGTH_MASK
180        };
181    
182        bool isDependent() const {
183            return hasFlag(DEPENDENT);
184        }
185    
186        bool isFlat() const {
187            return !isDependent();
188        }
189    
190        bool isDeflated() const {
191            return hasFlag(DEFLATED);
192        }
193    
194        void setDeflated() {
195            JS_ATOMIC_SET_MASK((jsword *) &mLength, DEFLATED);
196        }
197    
198        bool isMutable() const {
199            return !isDependent() && hasFlag(MUTABLE);
200        }
201    
202        bool isAtomized() const {
203            return !isDependent() && hasFlag(ATOMIZED);
204        }
205    
206        JS_ALWAYS_INLINE jschar *chars() {
207            return isDependent() ? dependentChars() : flatChars();
208        }
209    
210        JS_ALWAYS_INLINE size_t length() const {
211            return isDependent() ? dependentLength() : flatLength();
212        }
213    
214        JS_ALWAYS_INLINE bool empty() const {
215            return length() == 0;
216        }
217    
218        JS_ALWAYS_INLINE void getCharsAndLength(const jschar *&chars, size_t &length) {
219            if (isDependent()) {
220                length = dependentLength();
221                chars = dependentChars();
222            } else {
223                length = flatLength();
224                chars = flatChars();
225            }
226        }
227    
228        JS_ALWAYS_INLINE void getCharsAndEnd(const jschar *&chars, const jschar *&end) {
229            end = isDependent()
230                  ? dependentLength() + (chars = dependentChars())
231                  : flatLength() + (chars = flatChars());
232        }
233    
234        /* Specific flat string initializer and accessor methods. */
235        void initFlat(jschar *chars, size_t length) {
236            JS_ASSERT(length <= MAX_LENGTH);
237            mLength = length;
238            mChars = chars;
239        }
240    
241        jschar *flatChars() const {
242            JS_ASSERT(isFlat());
243            return mChars;
244        }
245    
246        size_t flatLength() const {
247            JS_ASSERT(isFlat());
248            return mLength & LENGTH_MASK;
249        }
250    
251        /*
252         * Special flat string initializer that preserves the JSSTR_DEFLATED flag.
253         * Use this method when reinitializing an existing string which may be
254         * hashed to its deflated bytes. Newborn strings must use initFlat.
255         */
256        void reinitFlat(jschar *chars, size_t length) {
257            JS_ASSERT(length <= MAX_LENGTH);
258            mLength = (mLength & DEFLATED) | (length & ~DEFLATED);
259            mChars = chars;
260        }
261    
262        /*
263         * Methods to manipulate atomized and mutable flags of flat strings. It is
264         * safe to use these without extra locking due to the following properties:
265         *
266         *   * We do not have a flatClearAtomized method, as a string remains
267         *     atomized until the GC collects it.
268         *
269         *   * A thread may call flatSetMutable only when it is the only
270         *     thread accessing the string until a later call to
271         *     flatClearMutable.
272         *
273         *   * Multiple threads can call flatClearMutable but the function actually
274         *     clears the mutable flag only when the flag is set -- in which case
275         *     only one thread can access the string (see previous property).
276         *
277         * Thus, when multiple threads access the string, JSString::flatSetAtomized
278         * is the only function that can update the mLength field of the string by
279         * changing the mutable bit from 0 to 1. We call the method only after the
280         * string has been hashed. When some threads in js_ValueToStringId see that
281         * the flag is set, it knows that the string was atomized.
282         *
283         * On the other hand, if the thread sees that the flag is unset, it could
284         * be seeing a stale value when another thread has just atomized the string
285         * and set the flag. But this can lead only to an extra call to
286         * js_AtomizeString.  This function would find that the string was already
287         * hashed and return it with the atomized bit set.
288         */
289        void flatSetAtomized() {
290            JS_ASSERT(isFlat() && !isMutable());
291            JS_STATIC_ASSERT(sizeof(mLength) == sizeof(jsword));
292            JS_ATOMIC_SET_MASK((jsword *) &mLength, ATOMIZED);
293        }
294    
295        void flatSetMutable() {
296            JS_ASSERT(isFlat() && !isAtomized());
297            mLength |= MUTABLE;
298        }
299    
300        void flatClearMutable() {
301            JS_ASSERT(isFlat());
302            if (hasFlag(MUTABLE))
303                mLength &= ~MUTABLE;
304        }
305    
306        void initDependent(JSString *bstr, size_t off, size_t len) {
307            JS_ASSERT(off <= MAX_DEPENDENT_START);
308            JS_ASSERT(len <= MAX_DEPENDENT_LENGTH);
309            mLength = DEPENDENT | (off << DEPENDENT_START_SHIFT) | len;
310            mBase = bstr;
311        }
312    
313        /* See JSString::reinitFlat. */
314        void reinitDependent(JSString *bstr, size_t off, size_t len) {
315            JS_ASSERT(off <= MAX_DEPENDENT_START);
316            JS_ASSERT(len <= MAX_DEPENDENT_LENGTH);
317            mLength = DEPENDENT | (mLength & DEFLATED) | (off << DEPENDENT_START_SHIFT) | len;
318            mBase = bstr;
319        }
320    
321        JSString *dependentBase() const {
322            JS_ASSERT(isDependent());
323            return mBase;
324        }
325    
326        bool dependentIsPrefix() const {
327            JS_ASSERT(isDependent());
328            return hasFlag(PREFIX);
329        }
330    
331        JS_ALWAYS_INLINE jschar *dependentChars() {
332            return dependentBase()->isDependent()
333                   ? js_GetDependentStringChars(this)
334                   : dependentBase()->flatChars() + dependentStart();
335        }
336    
337        JS_ALWAYS_INLINE size_t dependentStart() const {
338            return dependentIsPrefix()
339                   ? 0
340                   : ((mLength >> DEPENDENT_START_SHIFT) & DEPENDENT_START_MASK);
341        }
342    
343        JS_ALWAYS_INLINE size_t dependentLength() const {
344            JS_ASSERT(isDependent());
345            return mLength & (dependentIsPrefix() ? LENGTH_MASK : DEPENDENT_LENGTH_MASK);
346        }
347    
348        void initPrefix(JSString *bstr, size_t len) {
349            JS_ASSERT(len <= MAX_LENGTH);
350            mLength = DEPENDENT | PREFIX | len;
351            mBase = bstr;
352        }
353    
354        /* See JSString::reinitFlat. */
355        void reinitPrefix(JSString *bstr, size_t len) {
356            JS_ASSERT(len <= MAX_LENGTH);
357            mLength = DEPENDENT | PREFIX | (mLength & DEFLATED) | len;
358            mBase = bstr;
359        }
360    
361        JSString *prefixBase() const {
362            JS_ASSERT(isDependent() && dependentIsPrefix());
363            return dependentBase();
364        }
365    
366        void prefixSetBase(JSString *bstr) {
367            JS_ASSERT(isDependent() && dependentIsPrefix());
368            mBase = bstr;
369        }
370    
371        static inline bool isUnitString(void *ptr) {
372            jsuword delta = reinterpret_cast<jsuword>(ptr) -
373                            reinterpret_cast<jsuword>(unitStringTable);
374            if (delta >= UNIT_STRING_LIMIT * sizeof(JSString))
375                return false;
376    
377            /* If ptr points inside the static array, it must be well-aligned. */
378            JS_ASSERT(delta % sizeof(JSString) == 0);
379            return true;
380        }
381    
382        static inline bool isIntString(void *ptr) {
383            jsuword delta = reinterpret_cast<jsuword>(ptr) -
384                            reinterpret_cast<jsuword>(intStringTable);
385            if (delta >= INT_STRING_LIMIT * sizeof(JSString))
386                return false;
387    
388            /* If ptr points inside the static array, it must be well-aligned. */
389            JS_ASSERT(delta % sizeof(JSString) == 0);
390            return true;
391        }
392    
393        static inline bool isStatic(void *ptr) {
394            return isUnitString(ptr) || isIntString(ptr);
395        }
396    
397    #ifdef __SUNPRO_CC
398    #pragma align 8 (__1cIJSStringPunitStringTable_, __1cIJSStringOintStringTable_)
399    #endif
400    
401        static JSString unitStringTable[];
402        static JSString intStringTable[];
403        static const char *deflatedIntStringTable[];
404    
405        static JSString *unitString(jschar c);
406        static JSString *getUnitString(JSContext *cx, JSString *str, size_t index);
407        static JSString *intString(jsint i);
408    };
409    #else /* __cplusplus */
410    
411  struct JSString {  struct JSString {
412      size_t          length;      size_t          length;
413      union {      union {
# Line 271  Line 585 
585       ? js_GetDependentStringChars(str)                                        \       ? js_GetDependentStringChars(str)                                        \
586       : JSFLATSTR_CHARS(JSSTRDEP_BASE(str)) + JSSTRDEP_START(str))       : JSFLATSTR_CHARS(JSSTRDEP_BASE(str)) + JSSTRDEP_START(str))
587    
588  extern size_t  #endif /* __cplusplus */
 js_MinimizeDependentStrings(JSString *str, int level, JSString **basep);  
   
 extern jschar *  
 js_GetDependentStringChars(JSString *str);  
589    
590  extern const jschar *  extern const jschar *
591  js_GetStringChars(JSContext *cx, JSString *str);  js_GetStringChars(JSContext *cx, JSString *str);
# Line 289  Line 599 
599  extern JSBool  extern JSBool
600  js_MakeStringImmutable(JSContext *cx, JSString *str);  js_MakeStringImmutable(JSContext *cx, JSString *str);
601    
602  extern JSString* JS_FASTCALL  extern JSString * JS_FASTCALL
603  js_toLowerCase(JSContext *cx, JSString *str);  js_toLowerCase(JSContext *cx, JSString *str);
604    
605  extern JSString* JS_FASTCALL  extern JSString * JS_FASTCALL
606  js_toUpperCase(JSContext *cx, JSString *str);  js_toUpperCase(JSContext *cx, JSString *str);
607    
 typedef struct JSCharBuffer {  
     size_t          length;  
     jschar          *chars;  
 } JSCharBuffer;  
   
608  struct JSSubString {  struct JSSubString {
609      size_t          length;      size_t          length;
610      const jschar    *chars;      const jschar    *chars;
# Line 392  Line 697 
697  /* Unicode control-format characters, ignored in input */  /* Unicode control-format characters, ignored in input */
698  #define JS_ISFORMAT(c) (((1 << JSCT_FORMAT) >> JS_CTYPE(c)) & 1)  #define JS_ISFORMAT(c) (((1 << JSCT_FORMAT) >> JS_CTYPE(c)) & 1)
699    
700    #ifdef __cplusplus /* Allow inclusion from LiveConnect C files. */
701  /*  /*
702   * Per ECMA-262 15.10.2.6, these characters are the only ones that make up a   * This table is used in JS_ISWORD.  The definition has external linkage to
703   * "word", as far as a RegExp is concerned.  If we want a Unicode-friendlier   * allow the raw table data to be used in the regular expression compiler.
  * definition of "word", we should rename this macro to something regexp-y.  
704   */   */
705  #define JS_ISWORD(c)    ((c) < 128 && (isalnum(c) || (c) == '_'))  extern const bool js_alnum[];
706    #endif
707    
708    /*
709     * This macro performs testing for the regular expression word class \w, which
710     * is defined by ECMA-262 15.10.2.6 to be [0-9A-Z_a-z].  If we want a
711     * Unicode-friendlier definition of "word", we should rename this macro to
712     * something regexp-y.
713     */
714    #define JS_ISWORD(c)    ((c) < 128 && js_alnum[(c)])
715    
716  #define JS_ISIDSTART(c) (JS_ISLETTER(c) || (c) == '_' || (c) == '$')  #define JS_ISIDSTART(c) (JS_ISLETTER(c) || (c) == '_' || (c) == '$')
717  #define JS_ISIDENT(c)   (JS_ISIDPART(c) || (c) == '_' || (c) == '$')  #define JS_ISIDENT(c)   (JS_ISIDPART(c) || (c) == '_' || (c) == '$')
# Line 412  Line 726 
726    
727  #define JS_ISDIGIT(c)   (JS_CTYPE(c) == JSCT_DECIMAL_DIGIT_NUMBER)  #define JS_ISDIGIT(c)   (JS_CTYPE(c) == JSCT_DECIMAL_DIGIT_NUMBER)
728    
729  /* XXXbe unify on A/X/Y tbls, avoid ctype.h? */  #ifdef __cplusplus /* Allow inclusion from LiveConnect C files. */
730  /* XXXbe fs, etc. ? */  static inline bool
731  #define JS_ISSPACE(c)   ((JS_CCODE(c) & 0x00070000) == 0x00040000)  #else
732    static JSBool
733    #endif
734    JS_ISSPACE(jschar c)
735    {
736        unsigned w = c;
737    
738        if (w < 256)
739            return (w <= ' ' && (w == ' ' || (9 <= w && w <= 0xD))) || w == 0xA0;
740    
741        return (JS_CCODE(w) & 0x00070000) == 0x00040000;
742    }
743    
744  #define JS_ISPRINT(c)   ((c) < 128 && isprint(c))  #define JS_ISPRINT(c)   ((c) < 128 && isprint(c))
745    
746  #define JS_ISUPPER(c)   (JS_CTYPE(c) == JSCT_UPPERCASE_LETTER)  #define JS_ISUPPER(c)   (JS_CTYPE(c) == JSCT_UPPERCASE_LETTER)
# Line 444  Line 770 
770  extern JSBool  extern JSBool
771  js_InitDeflatedStringCache(JSRuntime *rt);  js_InitDeflatedStringCache(JSRuntime *rt);
772    
 /*  
  * Maximum character code for which we will create a pinned unit string on  
  * demand -- see JSRuntime.unitStrings in jscntxt.h.  
  */  
 #define UNIT_STRING_LIMIT 256U  
   
 /*  
  * Get the independent string containing only character code at index in str  
  * (backstopped with a zero character as usual for independent strings).  
  */  
 extern JSString *  
 js_GetUnitString(JSContext *cx, JSString *str, size_t index);  
   
 /*  
  * Get the independent string containing only the character code c, which must  
  * be less than UNIT_STRING_LIMIT.  
  */  
 extern JSString *  
 js_GetUnitStringForChar(JSContext *cx, jschar c);  
   
 extern void  
 js_FinishUnitStrings(JSRuntime *rt);  
   
773  extern void  extern void
774  js_FinishRuntimeStringState(JSContext *cx);  js_FinishRuntimeStringState(JSContext *cx);
775    
# Line 491  Line 794 
794  extern JSString *  extern JSString *
795  js_NewString(JSContext *cx, jschar *chars, size_t length);  js_NewString(JSContext *cx, jschar *chars, size_t length);
796    
797    /*
798     * GC-allocate a string descriptor and steal the char buffer held by |cb|.
799     * This function takes responsibility for adding the terminating '\0' required
800     * by js_NewString.
801     */
802    #ifdef __cplusplus /* Allow inclusion from LiveConnect C files. */
803    extern JSString *
804    js_NewStringFromCharBuffer(JSContext *cx, JSCharBuffer &cb);
805    #endif
806    
807  extern JSString *  extern JSString *
808  js_NewDependentString(JSContext *cx, JSString *base, size_t start,  js_NewDependentString(JSContext *cx, JSString *base, size_t start,
809                        size_t length);                        size_t length);
# Line 504  Line 817 
817  js_NewStringCopyZ(JSContext *cx, const jschar *s);  js_NewStringCopyZ(JSContext *cx, const jschar *s);
818    
819  /*  /*
  * Free the chars held by str when it is finalized by the GC. When type is  
  * less then zero, it denotes an internal string. Otherwise it denotes the  
  * type of the external string allocated with JS_NewExternalString.  
  *  
  * This function always needs rt but can live with null cx.  
  */  
 extern void  
 js_FinalizeStringRT(JSRuntime *rt, JSString *str, intN type, JSContext *cx);  
   
 /*  
820   * Convert a value to a printable C string.   * Convert a value to a printable C string.
821   */   */
822  typedef JSString *(*JSValueToStringFun)(JSContext *cx, jsval v);  typedef JSString *(*JSValueToStringFun)(JSContext *cx, jsval v);
# Line 535  Line 838 
838  js_ValueToString(JSContext *cx, jsval v);  js_ValueToString(JSContext *cx, jsval v);
839    
840  /*  /*
841     * This function implements E-262-3 section 9.8, toString. Convert the given
842     * value to a string of jschars appended to the given buffer. On error, the
843     * passed buffer may have partial results appended.
844     */
845    #ifdef __cplusplus /* Allow inclusion from LiveConnect C files. */
846    extern JS_FRIEND_API(JSBool)
847    js_ValueToCharBuffer(JSContext *cx, jsval v, JSCharBuffer &cb);
848    #endif
849    
850    /*
851   * Convert a value to its source expression, returning null after reporting   * Convert a value to its source expression, returning null after reporting
852   * an error, otherwise returning a new string reference.   * an error, otherwise returning a new string reference.
853   */   */
# Line 564  Line 877 
877    
878  /*  /*
879   * Boyer-Moore-Horspool superlinear search for pat:patlen in text:textlen.   * Boyer-Moore-Horspool superlinear search for pat:patlen in text:textlen.
880   * The patlen argument must be positive and no greater than BMH_PATLEN_MAX.   * The patlen argument must be positive and no greater than sBMHPatLenMax.
  * The start argument tells where in text to begin the search.  
881   *   *
882   * Return the index of pat in text, or -1 if not found.   * Return the index of pat in text, or -1 if not found.
883   */   */
884  #define BMH_CHARSET_SIZE 256    /* ISO-Latin-1 */  static const jsuint sBMHCharSetSize = 256; /* ISO-Latin-1 */
885  #define BMH_PATLEN_MAX   255    /* skip table element is uint8 */  static const jsuint sBMHPatLenMax   = 255; /* skip table element is uint8 */
886    static const jsint  sBMHBadPattern  = -2;  /* return value if pat is not ISO-Latin-1 */
 #define BMH_BAD_PATTERN  (-2)   /* return value if pat is not ISO-Latin-1 */  
887    
888  extern jsint  extern jsint
889  js_BoyerMooreHorspool(const jschar *text, jsint textlen,  js_BoyerMooreHorspool(const jschar *text, jsuint textlen,
890                        const jschar *pat, jsint patlen,                        const jschar *pat, jsuint patlen);
                       jsint start);  
891    
892  extern size_t  extern size_t
893  js_strlen(const jschar *s);  js_strlen(const jschar *s);
# Line 593  Line 903 
903  /*  /*
904   * Return s advanced past any Unicode white space characters.   * Return s advanced past any Unicode white space characters.
905   */   */
906  extern const jschar *  static inline const jschar *
907  js_SkipWhiteSpace(const jschar *s, const jschar *end);  js_SkipWhiteSpace(const jschar *s, const jschar *end)
908    {
909        JS_ASSERT(s <= end);
910        while (s != end && JS_ISSPACE(*s))
911            s++;
912        return s;
913    }
914    
915  /*  /*
916   * Inflate bytes to JS chars and vice versa.  Report out of memory via cx   * Inflate bytes to JS chars and vice versa.  Report out of memory via cx
# Line 614  Line 930 
930   * number of copied chars.   * number of copied chars.
931   */   */
932  extern JSBool  extern JSBool
933  js_InflateStringToBuffer(JSContext* cx, const char *bytes, size_t length,  js_InflateStringToBuffer(JSContext *cx, const char *bytes, size_t length,
934                           jschar *chars, size_t* charsLength);                           jschar *chars, size_t *charsLength);
935    
936  /*  /*
937   * Get number of bytes in the deflated sequence of characters.   * Get number of bytes in the deflated sequence of characters.
# Line 631  Line 947 
947   * number of copied bytes.   * number of copied bytes.
948   */   */
949  extern JSBool  extern JSBool
950  js_DeflateStringToBuffer(JSContext* cx, const jschar *chars,  js_DeflateStringToBuffer(JSContext *cx, const jschar *chars,
951                           size_t charsLength, char *bytes, size_t* length);                           size_t charsLength, char *bytes, size_t *length);
952    
953  /*  /*
954   * Associate bytes with str in the deflated string cache, returning true on   * Associate bytes with str in the deflated string cache, returning true on
# Line 658  Line 974 
974                jsval *rval);                jsval *rval);
975    
976  extern JSBool  extern JSBool
977  js_StringReplaceHelper(JSContext *cx, uintN argc, JSObject *lambda,  js_str_toString(JSContext *cx, uintN argc, jsval *vp);
                        JSString *repstr, jsval *vp);  
978    
979  /*  /*
980   * Convert one UCS-4 char and write it into a UTF-8 buffer, which must be at   * Convert one UCS-4 char and write it into a UTF-8 buffer, which must be at

Legend:
Removed from v.506  
changed lines
  Added in v.507

  ViewVC Help
Powered by ViewVC 1.1.24