⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jsstr.h

📁 java script test programing source code
💻 H
📖 第 1 页 / 共 2 页
字号:
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- * * ***** BEGIN LICENSE BLOCK ***** * Version: MPL 1.1/GPL 2.0/LGPL 2.1 * * The contents of this file are subject to the Mozilla Public License Version * 1.1 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * http://www.mozilla.org/MPL/ * * Software distributed under the License is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License * for the specific language governing rights and limitations under the * License. * * The Original Code is Mozilla Communicator client code, released * March 31, 1998. * * The Initial Developer of the Original Code is * Netscape Communications Corporation. * Portions created by the Initial Developer are Copyright (C) 1998 * the Initial Developer. All Rights Reserved. * * Contributor(s): * * Alternatively, the contents of this file may be used under the terms of * either of the GNU General Public License Version 2 or later (the "GPL"), * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), * in which case the provisions of the GPL or the LGPL are applicable instead * of those above. If you wish to allow use of your version of this file only * under the terms of either the GPL or the LGPL, and not to allow others to * use your version of this file under the terms of the MPL, indicate your * decision by deleting the provisions above and replace them with the notice * and other provisions required by the GPL or the LGPL. If you do not delete * the provisions above, a recipient may use your version of this file under * the terms of any one of the MPL, the GPL or the LGPL. * * ***** END LICENSE BLOCK ***** */#ifndef jsstr_h___#define jsstr_h___/* * JS string type implementation. * * A JS string is a counted array of unicode characters.  To support handoff * of API client memory, the chars are allocated separately from the length, * necessitating a pointer after the count, to form a separately allocated * string descriptor.  String descriptors are GC'ed, while their chars are * allocated from the malloc heap. * * When a string is treated as an object (by following it with . or []), the * runtime wraps it with a JSObject whose valueOf method returns the unwrapped * string descriptor. */#include <ctype.h>#include "jspubtd.h"#include "jsprvtd.h"#include "jshash.h"JS_BEGIN_EXTERN_C/* * The original GC-thing "string" type, a flat character string owned by its * GC-thing descriptor.  The chars member points to a vector having byte size * (length + 1) * sizeof(jschar), terminated at index length by a zero jschar. * The terminator is purely a backstop, in case the chars pointer flows out to * native code that requires \u0000 termination. * * NB: Always use the JSSTRING_LENGTH and JSSTRING_CHARS accessor macros, * unless you guard str->member uses with !JSSTRING_IS_DEPENDENT(str). */struct JSString {    size_t          length;    jschar          *chars;};/* * Overlay structure for a string that depends on another string's characters. * Distinguished by the JSSTRFLAG_DEPENDENT bit being set in length.  The base * member may point to another dependent string if JSSTRING_CHARS has not been * called yet.  The length chars in a dependent string are stored starting at * base->chars + start, and are not necessarily zero-terminated.  If start is * 0, it is not stored, length is a full size_t (minus the JSSTRFLAG_* bits in * the high two positions), and the JSSTRFLAG_PREFIX flag is set. */struct JSDependentString {    size_t          length;    JSString        *base;};/* Definitions for flags stored in the high order bits of JSString.length. */#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)/* Universal JSString type inquiry and accessor macros. */#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)         (JSSTRING_IS_DEPENDENT(str)               \                                     ? JSSTRDEP_CHARS(str)                    \                                     : (str)->chars)#define JSSTRING_LENGTH(str)        (JSSTRING_IS_DEPENDENT(str)               \                                     ? JSSTRDEP_LENGTH(str)                   \                                     : (str)->length)#define JSSTRING_LENGTH_BITS        (sizeof(size_t) * JS_BITS_PER_BYTE        \                                     - JSSTRFLAG_BITS)#define JSSTRING_LENGTH_MASK        JSSTRING_BITMASK(JSSTRING_LENGTH_BITS)/* Specific JSDependentString shift/mask accessor and mutator macros. */#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)         (JSSTRING_IS_PREFIX(str) ? 0              \                                     : ((JSSTRDEP(str)->length                \                                         >> JSSTRDEP_START_SHIFT)             \                                        & JSSTRDEP_START_MASK))#define JSSTRDEP_LENGTH(str)        (JSSTRDEP(str)->length                    \                                     & (JSSTRING_IS_PREFIX(str)               \                                        ? JSSTRING_LENGTH_MASK                \                                        : JSSTRDEP_LENGTH_MASK))#define JSSTRDEP_SET_START_AND_LENGTH(str,off,len)                            \    (JSSTRDEP(str)->length = JSSTRFLAG_DEPENDENT                              \                           | ((off) << JSSTRDEP_START_SHIFT)                  \                           | (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)                                                   \    (JSSTRING_IS_DEPENDENT(JSSTRDEP_BASE(str))                                \     ? js_GetDependentStringChars(str)                                        \     : JSSTRDEP_BASE(str)->chars + JSSTRDEP_START(str))extern size_tjs_MinimizeDependentStrings(JSString *str, int level, JSString **basep);extern jschar *js_GetDependentStringChars(JSString *str);extern jschar *js_GetStringChars(JSString *str);extern JSString *js_ConcatStrings(JSContext *cx, JSString *left, JSString *right);extern const jschar *js_UndependString(JSContext *cx, JSString *str);struct JSSubString {    size_t          length;    const jschar    *chars;};extern jschar      js_empty_ucstr[];extern JSSubString js_EmptySubString;/* Unicode character attribute lookup tables. */extern const uint8 js_X[];extern const uint8 js_Y[];extern const uint32 js_A[];/* Enumerated Unicode general category types. */typedef 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} JSCharType;/* Character classifying and mapping macros, based on java.lang.Character. */#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)   ((((1 << JSCT_UPPERCASE_LETTER) |                     \                           (1 << JSCT_LOWERCASE_LETTER) |                     \                           (1 << JSCT_TITLECASE_LETTER) |                     \                           (1 << JSCT_MODIFIER_LETTER) |                      \                           (1 << JSCT_OTHER_LETTER))                          \                          >> JS_CTYPE(c)) & 1)#define JS_ISALNUM(c)   ((((1 << JSCT_UPPERCASE_LETTER) |                     \                           (1 << JSCT_LOWERCASE_LETTER) |                     \                           (1 << JSCT_TITLECASE_LETTER) |                     \                           (1 << JSCT_MODIFIER_LETTER) |                      \                           (1 << JSCT_OTHER_LETTER) |                         \                           (1 << JSCT_DECIMAL_DIGIT_NUMBER))                  \                          >> JS_CTYPE(c)) & 1)/* A unicode letter, suitable for use in an identifier. */#define JS_ISLETTER(c)   ((((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)/* * 'IdentifierPart' from ECMA grammar, is Unicode letter or combining mark or * digit or connector punctuation. */#define JS_ISIDPART(c)  ((((1 << JSCT_UPPERCASE_LETTER) |                     \                           (1 << JSCT_LOWERCASE_LETTER) |                     \                           (1 << JSCT_TITLECASE_LETTER) |                     \                           (1 << JSCT_MODIFIER_LETTER) |                      \                           (1 << JSCT_OTHER_LETTER) |                         \                           (1 << JSCT_LETTER_NUMBER) |                        \                           (1 << JSCT_NON_SPACING_MARK) |                     \                           (1 << JSCT_COMBINING_SPACING_MARK) |               \                           (1 << JSCT_DECIMAL_DIGIT_NUMBER) |                 \                           (1 << JSCT_CONNECTOR_PUNCTUATION))                 \                          >> JS_CTYPE(c)) & 1)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -