You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by sh...@apache.org on 2012/06/20 22:39:15 UTC
[2/2] Fixes CB-647 - Prefix/Namespace common native libraries
http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/ec1aa060/CordovaLib/Classes/JSON/JSONKit.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/JSON/JSONKit.m b/CordovaLib/Classes/JSON/JSONKit.m
index b9488b2..e944bf3 100644
--- a/CordovaLib/Classes/JSON/JSONKit.m
+++ b/CordovaLib/Classes/JSON/JSONKit.m
@@ -128,330 +128,330 @@
#define __has_feature(x) 0
#endif
-#ifdef JK_ENABLE_CF_TRANSFER_OWNERSHIP_CALLBACKS
-#warning As of JSONKit v1.4, JK_ENABLE_CF_TRANSFER_OWNERSHIP_CALLBACKS is no longer required. It is no longer a valid option.
+#ifdef CDVJK_ENABLE_CF_TRANSFER_OWNERSHIP_CALLBACKS
+#warning As of CDVJSONKit v1.4, CDVJK_ENABLE_CF_TRANSFER_OWNERSHIP_CALLBACKS is no longer required. It is no longer a valid option.
#endif
#ifdef __OBJC_GC__
-#error JSONKit does not support Objective-C Garbage Collection
+#error CDVJSONKit does not support Objective-C Garbage Collection
#endif
#if __has_feature(objc_arc)
-#error JSONKit does not support Objective-C Automatic Reference Counting (ARC)
+#error CDVJSONKit does not support Objective-C Automatic Reference Counting (ARC)
#endif
// The following checks are really nothing more than sanity checks.
-// JSONKit technically has a few problems from a "strictly C99 conforming" standpoint, though they are of the pedantic nitpicking variety.
+// CDVJSONKit technically has a few problems from a "strictly C99 conforming" standpoint, though they are of the pedantic nitpicking variety.
// In practice, though, for the compilers and architectures we can reasonably expect this code to be compiled for, these pedantic nitpicks aren't really a problem.
// Since we're limited as to what we can do with pre-processor #if checks, these checks are not nearly as through as they should be.
#if (UINT_MAX != 0xffffffffU) || (INT_MIN != (-0x7fffffff-1)) || (ULLONG_MAX != 0xffffffffffffffffULL) || (LLONG_MIN != (-0x7fffffffffffffffLL-1LL))
-#error JSONKit requires the C 'int' and 'long long' types to be 32 and 64 bits respectively.
+#error CDVJSONKit requires the C 'int' and 'long long' types to be 32 and 64 bits respectively.
#endif
#if !defined(__LP64__) && ((UINT_MAX != ULONG_MAX) || (INT_MAX != LONG_MAX) || (INT_MIN != LONG_MIN) || (WORD_BIT != LONG_BIT))
-#error JSONKit requires the C 'int' and 'long' types to be the same on 32-bit architectures.
+#error CDVJSONKit requires the C 'int' and 'long' types to be the same on 32-bit architectures.
#endif
// Cocoa / Foundation uses NS*Integer as the type for a lot of arguments. We make sure that NS*Integer is something we are expecting and is reasonably compatible with size_t / ssize_t
#if (NSUIntegerMax != ULONG_MAX) || (NSIntegerMax != LONG_MAX) || (NSIntegerMin != LONG_MIN)
-#error JSONKit requires NSInteger and NSUInteger to be the same size as the C 'long' type.
+#error CDVJSONKit requires NSInteger and NSUInteger to be the same size as the C 'long' type.
#endif
#if (NSUIntegerMax != SIZE_MAX) || (NSIntegerMax != SSIZE_MAX)
-#error JSONKit requires NSInteger and NSUInteger to be the same size as the C 'size_t' type.
+#error CDVJSONKit requires NSInteger and NSUInteger to be the same size as the C 'size_t' type.
#endif
// For DJB hash.
-#define JK_HASH_INIT (1402737925UL)
+#define CDVJK_HASH_INIT (1402737925UL)
// Use __builtin_clz() instead of trailingBytesForUTF8[] table lookup.
-#define JK_FAST_TRAILING_BYTES
+#define CDVJK_FAST_TRAILING_BYTES
-// JK_CACHE_SLOTS must be a power of 2. Default size is 1024 slots.
-#define JK_CACHE_SLOTS_BITS (10)
-#define JK_CACHE_SLOTS (1UL << JK_CACHE_SLOTS_BITS)
-// JK_CACHE_PROBES is the number of probe attempts.
-#define JK_CACHE_PROBES (4UL)
-// JK_INIT_CACHE_AGE must be (1 << AGE) - 1
-#define JK_INIT_CACHE_AGE (0)
+// CDVJK_CACHE_SLOTS must be a power of 2. Default size is 1024 slots.
+#define CDVJK_CACHE_SLOTS_BITS (10)
+#define CDVJK_CACHE_SLOTS (1UL << CDVJK_CACHE_SLOTS_BITS)
+// CDVJK_CACHE_PROBES is the number of probe attempts.
+#define CDVJK_CACHE_PROBES (4UL)
+// CDVJK_INIT_CACHE_AGE must be (1 << AGE) - 1
+#define CDVJK_INIT_CACHE_AGE (0)
-// JK_TOKENBUFFER_SIZE is the default stack size for the temporary buffer used to hold "non-simple" strings (i.e., contains \ escapes)
-#define JK_TOKENBUFFER_SIZE (1024UL * 2UL)
+// CDVJK_TOKENBUFFER_SIZE is the default stack size for the temporary buffer used to hold "non-simple" strings (i.e., contains \ escapes)
+#define CDVJK_TOKENBUFFER_SIZE (1024UL * 2UL)
-// JK_STACK_OBJS is the default number of spaces reserved on the stack for temporarily storing pointers to Obj-C objects before they can be transferred to a NSArray / NSDictionary.
-#define JK_STACK_OBJS (1024UL * 1UL)
+// CDVJK_STACK_OBJS is the default number of spaces reserved on the stack for temporarily storing pointers to Obj-C objects before they can be transferred to a NSArray / NSDictionary.
+#define CDVJK_STACK_OBJS (1024UL * 1UL)
-#define JK_JSONBUFFER_SIZE (1024UL * 4UL)
-#define JK_UTF8BUFFER_SIZE (1024UL * 16UL)
+#define CDVJK_JSONBUFFER_SIZE (1024UL * 4UL)
+#define CDVJK_UTF8BUFFER_SIZE (1024UL * 16UL)
-#define JK_ENCODE_CACHE_SLOTS (1024UL)
+#define CDVJK_ENCODE_CACHE_SLOTS (1024UL)
#if defined (__GNUC__) && (__GNUC__ >= 4)
-#define JK_ATTRIBUTES(attr, ...) __attribute__((attr, ##__VA_ARGS__))
-#define JK_EXPECTED(cond, expect) __builtin_expect((long)(cond), (expect))
-#define JK_EXPECT_T(cond) JK_EXPECTED(cond, 1U)
-#define JK_EXPECT_F(cond) JK_EXPECTED(cond, 0U)
-#define JK_PREFETCH(ptr) __builtin_prefetch(ptr)
+#define CDVJK_ATTRIBUTES(attr, ...) __attribute__((attr, ##__VA_ARGS__))
+#define CDVJK_EXPECTED(cond, expect) __builtin_expect((long)(cond), (expect))
+#define CDVJK_EXPECT_T(cond) CDVJK_EXPECTED(cond, 1U)
+#define CDVJK_EXPECT_F(cond) CDVJK_EXPECTED(cond, 0U)
+#define CDVJK_PREFETCH(ptr) __builtin_prefetch(ptr)
#else // defined (__GNUC__) && (__GNUC__ >= 4)
-#define JK_ATTRIBUTES(attr, ...)
-#define JK_EXPECTED(cond, expect) (cond)
-#define JK_EXPECT_T(cond) (cond)
-#define JK_EXPECT_F(cond) (cond)
-#define JK_PREFETCH(ptr)
+#define CDVJK_ATTRIBUTES(attr, ...)
+#define CDVJK_EXPECTED(cond, expect) (cond)
+#define CDVJK_EXPECT_T(cond) (cond)
+#define CDVJK_EXPECT_F(cond) (cond)
+#define CDVJK_PREFETCH(ptr)
#endif // defined (__GNUC__) && (__GNUC__ >= 4)
-#define JK_STATIC_INLINE static __inline__ JK_ATTRIBUTES(always_inline)
-#define JK_ALIGNED(arg) JK_ATTRIBUTES(aligned(arg))
-#define JK_UNUSED_ARG JK_ATTRIBUTES(unused)
-#define JK_WARN_UNUSED JK_ATTRIBUTES(warn_unused_result)
-#define JK_WARN_UNUSED_CONST JK_ATTRIBUTES(warn_unused_result, const)
-#define JK_WARN_UNUSED_PURE JK_ATTRIBUTES(warn_unused_result, pure)
-#define JK_WARN_UNUSED_SENTINEL JK_ATTRIBUTES(warn_unused_result, sentinel)
-#define JK_NONNULL_ARGS(arg, ...) JK_ATTRIBUTES(nonnull(arg, ##__VA_ARGS__))
-#define JK_WARN_UNUSED_NONNULL_ARGS(arg, ...) JK_ATTRIBUTES(warn_unused_result, nonnull(arg, ##__VA_ARGS__))
-#define JK_WARN_UNUSED_CONST_NONNULL_ARGS(arg, ...) JK_ATTRIBUTES(warn_unused_result, const, nonnull(arg, ##__VA_ARGS__))
-#define JK_WARN_UNUSED_PURE_NONNULL_ARGS(arg, ...) JK_ATTRIBUTES(warn_unused_result, pure, nonnull(arg, ##__VA_ARGS__))
+#define CDVJK_STATIC_INLINE static __inline__ CDVJK_ATTRIBUTES(always_inline)
+#define CDVJK_ALIGNED(arg) CDVJK_ATTRIBUTES(aligned(arg))
+#define CDVJK_UNUSED_ARG CDVJK_ATTRIBUTES(unused)
+#define CDVJK_WARN_UNUSED CDVJK_ATTRIBUTES(warn_unused_result)
+#define CDVJK_WARN_UNUSED_CONST CDVJK_ATTRIBUTES(warn_unused_result, const)
+#define CDVJK_WARN_UNUSED_PURE CDVJK_ATTRIBUTES(warn_unused_result, pure)
+#define CDVJK_WARN_UNUSED_SENTINEL CDVJK_ATTRIBUTES(warn_unused_result, sentinel)
+#define CDVJK_NONNULL_ARGS(arg, ...) CDVJK_ATTRIBUTES(nonnull(arg, ##__VA_ARGS__))
+#define CDVJK_WARN_UNUSED_NONNULL_ARGS(arg, ...) CDVJK_ATTRIBUTES(warn_unused_result, nonnull(arg, ##__VA_ARGS__))
+#define CDVJK_WARN_UNUSED_CONST_NONNULL_ARGS(arg, ...) CDVJK_ATTRIBUTES(warn_unused_result, const, nonnull(arg, ##__VA_ARGS__))
+#define CDVJK_WARN_UNUSED_PURE_NONNULL_ARGS(arg, ...) CDVJK_ATTRIBUTES(warn_unused_result, pure, nonnull(arg, ##__VA_ARGS__))
#if defined (__GNUC__) && (__GNUC__ >= 4) && (__GNUC_MINOR__ >= 3)
-#define JK_ALLOC_SIZE_NON_NULL_ARGS_WARN_UNUSED(as, nn, ...) JK_ATTRIBUTES(warn_unused_result, nonnull(nn, ##__VA_ARGS__), alloc_size(as))
+#define CDVJK_ALLOC_SIZE_NON_NULL_ARGS_WARN_UNUSED(as, nn, ...) CDVJK_ATTRIBUTES(warn_unused_result, nonnull(nn, ##__VA_ARGS__), alloc_size(as))
#else // defined (__GNUC__) && (__GNUC__ >= 4) && (__GNUC_MINOR__ >= 3)
-#define JK_ALLOC_SIZE_NON_NULL_ARGS_WARN_UNUSED(as, nn, ...) JK_ATTRIBUTES(warn_unused_result, nonnull(nn, ##__VA_ARGS__))
+#define CDVJK_ALLOC_SIZE_NON_NULL_ARGS_WARN_UNUSED(as, nn, ...) CDVJK_ATTRIBUTES(warn_unused_result, nonnull(nn, ##__VA_ARGS__))
#endif // defined (__GNUC__) && (__GNUC__ >= 4) && (__GNUC_MINOR__ >= 3)
-@class JKArray, JKDictionaryEnumerator, JKDictionary;
+@class CDVJKArray, CDVJKDictionaryEnumerator, CDVJKDictionary;
enum {
- JSONNumberStateStart = 0,
- JSONNumberStateFinished = 1,
- JSONNumberStateError = 2,
- JSONNumberStateWholeNumberStart = 3,
- JSONNumberStateWholeNumberMinus = 4,
- JSONNumberStateWholeNumberZero = 5,
- JSONNumberStateWholeNumber = 6,
- JSONNumberStatePeriod = 7,
- JSONNumberStateFractionalNumberStart = 8,
- JSONNumberStateFractionalNumber = 9,
- JSONNumberStateExponentStart = 10,
- JSONNumberStateExponentPlusMinus = 11,
- JSONNumberStateExponent = 12,
+ CDVJSONNumberStateStart = 0,
+ CDVJSONNumberStateFinished = 1,
+ CDVJSONNumberStateError = 2,
+ CDVJSONNumberStateWholeNumberStart = 3,
+ CDVJSONNumberStateWholeNumberMinus = 4,
+ CDVJSONNumberStateWholeNumberZero = 5,
+ CDVJSONNumberStateWholeNumber = 6,
+ CDVJSONNumberStatePeriod = 7,
+ CDVJSONNumberStateFractionalNumberStart = 8,
+ CDVJSONNumberStateFractionalNumber = 9,
+ CDVJSONNumberStateExponentStart = 10,
+ CDVJSONNumberStateExponentPlusMinus = 11,
+ CDVJSONNumberStateExponent = 12,
};
enum {
- JSONStringStateStart = 0,
- JSONStringStateParsing = 1,
- JSONStringStateFinished = 2,
- JSONStringStateError = 3,
- JSONStringStateEscape = 4,
- JSONStringStateEscapedUnicode1 = 5,
- JSONStringStateEscapedUnicode2 = 6,
- JSONStringStateEscapedUnicode3 = 7,
- JSONStringStateEscapedUnicode4 = 8,
- JSONStringStateEscapedUnicodeSurrogate1 = 9,
- JSONStringStateEscapedUnicodeSurrogate2 = 10,
- JSONStringStateEscapedUnicodeSurrogate3 = 11,
- JSONStringStateEscapedUnicodeSurrogate4 = 12,
- JSONStringStateEscapedNeedEscapeForSurrogate = 13,
- JSONStringStateEscapedNeedEscapedUForSurrogate = 14,
+ CDVJSONStringStateStart = 0,
+ CDVJSONStringStateParsing = 1,
+ CDVJSONStringStateFinished = 2,
+ CDVJSONStringStateError = 3,
+ CDVJSONStringStateEscape = 4,
+ CDVJSONStringStateEscapedUnicode1 = 5,
+ CDVJSONStringStateEscapedUnicode2 = 6,
+ CDVJSONStringStateEscapedUnicode3 = 7,
+ CDVJSONStringStateEscapedUnicode4 = 8,
+ CDVJSONStringStateEscapedUnicodeSurrogate1 = 9,
+ CDVJSONStringStateEscapedUnicodeSurrogate2 = 10,
+ CDVJSONStringStateEscapedUnicodeSurrogate3 = 11,
+ CDVJSONStringStateEscapedUnicodeSurrogate4 = 12,
+ CDVJSONStringStateEscapedNeedEscapeForSurrogate = 13,
+ CDVJSONStringStateEscapedNeedEscapedUForSurrogate = 14,
};
enum {
- JKParseAcceptValue = (1 << 0),
- JKParseAcceptComma = (1 << 1),
- JKParseAcceptEnd = (1 << 2),
- JKParseAcceptValueOrEnd = (JKParseAcceptValue | JKParseAcceptEnd),
- JKParseAcceptCommaOrEnd = (JKParseAcceptComma | JKParseAcceptEnd),
+ CDVJKParseAcceptValue = (1 << 0),
+ CDVJKParseAcceptComma = (1 << 1),
+ CDVJKParseAcceptEnd = (1 << 2),
+ CDVJKParseAcceptValueOrEnd = (CDVJKParseAcceptValue | CDVJKParseAcceptEnd),
+ CDVJKParseAcceptCommaOrEnd = (CDVJKParseAcceptComma | CDVJKParseAcceptEnd),
};
enum {
- JKClassUnknown = 0,
- JKClassString = 1,
- JKClassNumber = 2,
- JKClassArray = 3,
- JKClassDictionary = 4,
- JKClassNull = 5,
+ CDVJKClassUnknown = 0,
+ CDVJKClassString = 1,
+ CDVJKClassNumber = 2,
+ CDVJKClassArray = 3,
+ CDVJKClassDictionary = 4,
+ CDVJKClassNull = 5,
};
enum {
- JKManagedBufferOnStack = 1,
- JKManagedBufferOnHeap = 2,
- JKManagedBufferLocationMask = (0x3),
- JKManagedBufferLocationShift = (0),
+ CDVJKManagedBufferOnStack = 1,
+ CDVJKManagedBufferOnHeap = 2,
+ CDVJKManagedBufferLocationMask = (0x3),
+ CDVJKManagedBufferLocationShift = (0),
- JKManagedBufferMustFree = (1 << 2),
+ CDVJKManagedBufferMustFree = (1 << 2),
};
-typedef JKFlags JKManagedBufferFlags;
+typedef CDVJKFlags CDVJKManagedBufferFlags;
enum {
- JKObjectStackOnStack = 1,
- JKObjectStackOnHeap = 2,
- JKObjectStackLocationMask = (0x3),
- JKObjectStackLocationShift = (0),
+ CDVJKObjectStackOnStack = 1,
+ CDVJKObjectStackOnHeap = 2,
+ CDVJKObjectStackLocationMask = (0x3),
+ CDVJKObjectStackLocationShift = (0),
- JKObjectStackMustFree = (1 << 2),
+ CDVJKObjectStackMustFree = (1 << 2),
};
-typedef JKFlags JKObjectStackFlags;
+typedef CDVJKFlags CDVJKObjectStackFlags;
enum {
- JKTokenTypeInvalid = 0,
- JKTokenTypeNumber = 1,
- JKTokenTypeString = 2,
- JKTokenTypeObjectBegin = 3,
- JKTokenTypeObjectEnd = 4,
- JKTokenTypeArrayBegin = 5,
- JKTokenTypeArrayEnd = 6,
- JKTokenTypeSeparator = 7,
- JKTokenTypeComma = 8,
- JKTokenTypeTrue = 9,
- JKTokenTypeFalse = 10,
- JKTokenTypeNull = 11,
- JKTokenTypeWhiteSpace = 12,
+ CDVJKTokenTypeInvalid = 0,
+ CDVJKTokenTypeNumber = 1,
+ CDVJKTokenTypeString = 2,
+ CDVJKTokenTypeObjectBegin = 3,
+ CDVJKTokenTypeObjectEnd = 4,
+ CDVJKTokenTypeArrayBegin = 5,
+ CDVJKTokenTypeArrayEnd = 6,
+ CDVJKTokenTypeSeparator = 7,
+ CDVJKTokenTypeComma = 8,
+ CDVJKTokenTypeTrue = 9,
+ CDVJKTokenTypeFalse = 10,
+ CDVJKTokenTypeNull = 11,
+ CDVJKTokenTypeWhiteSpace = 12,
};
-typedef NSUInteger JKTokenType;
+typedef NSUInteger CDVJKTokenType;
// These are prime numbers to assist with hash slot probing.
enum {
- JKValueTypeNone = 0,
- JKValueTypeString = 5,
- JKValueTypeLongLong = 7,
- JKValueTypeUnsignedLongLong = 11,
- JKValueTypeDouble = 13,
+ CDVJKValueTypeNone = 0,
+ CDVJKValueTypeString = 5,
+ CDVJKValueTypeLongLong = 7,
+ CDVJKValueTypeUnsignedLongLong = 11,
+ CDVJKValueTypeDouble = 13,
};
-typedef NSUInteger JKValueType;
+typedef NSUInteger CDVJKValueType;
enum {
- JKEncodeOptionAsData = 1,
- JKEncodeOptionAsString = 2,
- JKEncodeOptionAsTypeMask = 0x7,
- JKEncodeOptionCollectionObj = (1 << 3),
- JKEncodeOptionStringObj = (1 << 4),
- JKEncodeOptionStringObjTrimQuotes = (1 << 5),
+ CDVJKEncodeOptionAsData = 1,
+ CDVJKEncodeOptionAsString = 2,
+ CDVJKEncodeOptionAsTypeMask = 0x7,
+ CDVJKEncodeOptionCollectionObj = (1 << 3),
+ CDVJKEncodeOptionStringObj = (1 << 4),
+ CDVJKEncodeOptionStringObjTrimQuotes = (1 << 5),
};
-typedef NSUInteger JKEncodeOptionType;
-
-typedef NSUInteger JKHash;
-
-typedef struct JKTokenCacheItem JKTokenCacheItem;
-typedef struct JKTokenCache JKTokenCache;
-typedef struct JKTokenValue JKTokenValue;
-typedef struct JKParseToken JKParseToken;
-typedef struct JKPtrRange JKPtrRange;
-typedef struct JKObjectStack JKObjectStack;
-typedef struct JKBuffer JKBuffer;
-typedef struct JKConstBuffer JKConstBuffer;
-typedef struct JKConstPtrRange JKConstPtrRange;
-typedef struct JKRange JKRange;
-typedef struct JKManagedBuffer JKManagedBuffer;
-typedef struct JKFastClassLookup JKFastClassLookup;
-typedef struct JKEncodeCache JKEncodeCache;
-typedef struct JKEncodeState JKEncodeState;
-typedef struct JKObjCImpCache JKObjCImpCache;
-typedef struct JKHashTableEntry JKHashTableEntry;
+typedef NSUInteger CDVJKEncodeOptionType;
+
+typedef NSUInteger CDVJKHash;
+
+typedef struct CDVJKTokenCacheItem CDVJKTokenCacheItem;
+typedef struct CDVJKTokenCache CDVJKTokenCache;
+typedef struct CDVJKTokenValue CDVJKTokenValue;
+typedef struct CDVJKParseToken CDVJKParseToken;
+typedef struct CDVJKPtrRange CDVJKPtrRange;
+typedef struct CDVJKObjectStack CDVJKObjectStack;
+typedef struct CDVJKBuffer CDVJKBuffer;
+typedef struct CDVJKConstBuffer CDVJKConstBuffer;
+typedef struct CDVJKConstPtrRange CDVJKConstPtrRange;
+typedef struct CDVJKRange CDVJKRange;
+typedef struct CDVJKManagedBuffer CDVJKManagedBuffer;
+typedef struct CDVJKFastClassLookup CDVJKFastClassLookup;
+typedef struct CDVJKEncodeCache CDVJKEncodeCache;
+typedef struct CDVJKEncodeState CDVJKEncodeState;
+typedef struct CDVJKObjCImpCache CDVJKObjCImpCache;
+typedef struct CDVJKHashTableEntry CDVJKHashTableEntry;
typedef id (*NSNumberAllocImp)(id receiver, SEL selector);
typedef id (*NSNumberInitWithUnsignedLongLongImp)(id receiver, SEL selector, unsigned long long value);
-typedef id (*JKClassFormatterIMP)(id receiver, SEL selector, id object);
+typedef id (*CDVJKClassFormatterIMP)(id receiver, SEL selector, id object);
#ifdef __BLOCKS__
-typedef id (^JKClassFormatterBlock)(id formatObject);
+typedef id (^CDVJKClassFormatterBlock)(id formatObject);
#endif
-struct JKPtrRange {
+struct CDVJKPtrRange {
unsigned char *ptr;
size_t length;
};
-struct JKConstPtrRange {
+struct CDVJKConstPtrRange {
const unsigned char *ptr;
size_t length;
};
-struct JKRange {
+struct CDVJKRange {
size_t location, length;
};
-struct JKManagedBuffer {
- JKPtrRange bytes;
- JKManagedBufferFlags flags;
+struct CDVJKManagedBuffer {
+ CDVJKPtrRange bytes;
+ CDVJKManagedBufferFlags flags;
size_t roundSizeUpToMultipleOf;
};
-struct JKObjectStack {
+struct CDVJKObjectStack {
void **objects, **keys;
CFHashCode *cfHashes;
size_t count, index, roundSizeUpToMultipleOf;
- JKObjectStackFlags flags;
+ CDVJKObjectStackFlags flags;
};
-struct JKBuffer {
- JKPtrRange bytes;
+struct CDVJKBuffer {
+ CDVJKPtrRange bytes;
};
-struct JKConstBuffer {
- JKConstPtrRange bytes;
+struct CDVJKConstBuffer {
+ CDVJKConstPtrRange bytes;
};
-struct JKTokenValue {
- JKConstPtrRange ptrRange;
- JKValueType type;
- JKHash hash;
+struct CDVJKTokenValue {
+ CDVJKConstPtrRange ptrRange;
+ CDVJKValueType type;
+ CDVJKHash hash;
union {
long long longLongValue;
unsigned long long unsignedLongLongValue;
double doubleValue;
} number;
- JKTokenCacheItem *cacheItem;
+ CDVJKTokenCacheItem *cacheItem;
};
-struct JKParseToken {
- JKConstPtrRange tokenPtrRange;
- JKTokenType type;
- JKTokenValue value;
- JKManagedBuffer tokenBuffer;
+struct CDVJKParseToken {
+ CDVJKConstPtrRange tokenPtrRange;
+ CDVJKTokenType type;
+ CDVJKTokenValue value;
+ CDVJKManagedBuffer tokenBuffer;
};
-struct JKTokenCacheItem {
+struct CDVJKTokenCacheItem {
void *object;
- JKHash hash;
+ CDVJKHash hash;
CFHashCode cfHash;
size_t size;
unsigned char *bytes;
- JKValueType type;
+ CDVJKValueType type;
};
-struct JKTokenCache {
- JKTokenCacheItem *items;
+struct CDVJKTokenCache {
+ CDVJKTokenCacheItem *items;
size_t count;
unsigned int prng_lfsr;
- unsigned char age[JK_CACHE_SLOTS];
+ unsigned char age[CDVJK_CACHE_SLOTS];
};
-struct JKObjCImpCache {
+struct CDVJKObjCImpCache {
Class NSNumberClass;
NSNumberAllocImp NSNumberAlloc;
NSNumberInitWithUnsignedLongLongImp NSNumberInitWithUnsignedLongLong;
};
-struct JKParseState {
- JKParseOptionFlags parseOptionFlags;
- JKConstBuffer stringBuffer;
+struct CDVJKParseState {
+ CDVJKParseOptionFlags parseOptionFlags;
+ CDVJKConstBuffer stringBuffer;
size_t atIndex, lineNumber, lineStartIndex;
size_t prev_atIndex, prev_lineNumber, prev_lineStartIndex;
- JKParseToken token;
- JKObjectStack objectStack;
- JKTokenCache cache;
- JKObjCImpCache objCImpCache;
+ CDVJKParseToken token;
+ CDVJKObjectStack objectStack;
+ CDVJKTokenCache cache;
+ CDVJKObjCImpCache objCImpCache;
NSError *error;
int errorIsPrev;
BOOL mutableCollections;
};
-struct JKFastClassLookup {
+struct CDVJKFastClassLookup {
void *stringClass;
void *numberClass;
void *arrayClass;
@@ -459,48 +459,48 @@ struct JKFastClassLookup {
void *nullClass;
};
-struct JKEncodeCache {
+struct CDVJKEncodeCache {
id object;
size_t offset;
size_t length;
};
-struct JKEncodeState {
- JKManagedBuffer utf8ConversionBuffer;
- JKManagedBuffer stringBuffer;
+struct CDVJKEncodeState {
+ CDVJKManagedBuffer utf8ConversionBuffer;
+ CDVJKManagedBuffer stringBuffer;
size_t atIndex;
- JKFastClassLookup fastClassLookup;
- JKEncodeCache cache[JK_ENCODE_CACHE_SLOTS];
- JKSerializeOptionFlags serializeOptionFlags;
- JKEncodeOptionType encodeOption;
+ CDVJKFastClassLookup fastClassLookup;
+ CDVJKEncodeCache cache[CDVJK_ENCODE_CACHE_SLOTS];
+ CDVJKSerializeOptionFlags serializeOptionFlags;
+ CDVJKEncodeOptionType encodeOption;
size_t depth;
NSError *error;
id classFormatterDelegate;
SEL classFormatterSelector;
- JKClassFormatterIMP classFormatterIMP;
+ CDVJKClassFormatterIMP classFormatterIMP;
#ifdef __BLOCKS__
- JKClassFormatterBlock classFormatterBlock;
+ CDVJKClassFormatterBlock classFormatterBlock;
#endif
};
-// This is a JSONKit private class.
-@interface JKSerializer : NSObject {
- JKEncodeState *encodeState;
+// This is a CDVJSONKit private class.
+@interface CDVJKSerializer : NSObject {
+ CDVJKEncodeState *encodeState;
}
#ifdef __BLOCKS__
-#define JKSERIALIZER_BLOCKS_PROTO id(^)(id object)
+#define CDVJKSERIALIZER_BLOCKS_PROTO id(^)(id object)
#else
-#define JKSERIALIZER_BLOCKS_PROTO id
+#define CDVJKSERIALIZER_BLOCKS_PROTO id
#endif
-+ (id)serializeObject:(id)object options:(JKSerializeOptionFlags)optionFlags encodeOption:(JKEncodeOptionType)encodeOption block:(JKSERIALIZER_BLOCKS_PROTO)block delegate:(id)delegate selector:(SEL)selector error:(NSError **)error;
-- (id)serializeObject:(id)object options:(JKSerializeOptionFlags)optionFlags encodeOption:(JKEncodeOptionType)encodeOption block:(JKSERIALIZER_BLOCKS_PROTO)block delegate:(id)delegate selector:(SEL)selector error:(NSError **)error;
++ (id)serializeObject:(id)object options:(CDVJKSerializeOptionFlags)optionFlags encodeOption:(CDVJKEncodeOptionType)encodeOption block:(CDVJKSERIALIZER_BLOCKS_PROTO)block delegate:(id)delegate selector:(SEL)selector error:(NSError **)error;
+- (id)serializeObject:(id)object options:(CDVJKSerializeOptionFlags)optionFlags encodeOption:(CDVJKEncodeOptionType)encodeOption block:(CDVJKSERIALIZER_BLOCKS_PROTO)block delegate:(id)delegate selector:(SEL)selector error:(NSError **)error;
- (void)releaseState;
@end
-struct JKHashTableEntry {
+struct CDVJKHashTableEntry {
NSUInteger keyHash;
id key, object;
};
@@ -528,7 +528,7 @@ typedef enum {
#define UNI_SUR_LOW_END (UTF32)0xDFFF
-#if !defined(JK_FAST_TRAILING_BYTES)
+#if !defined(CDVJK_FAST_TRAILING_BYTES)
static const char trailingBytesForUTF8[256] = {
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
@@ -544,112 +544,112 @@ static const char trailingBytesForUTF8[256] = {
static const UTF32 offsetsFromUTF8[6] = { 0x00000000UL, 0x00003080UL, 0x000E2080UL, 0x03C82080UL, 0xFA082080UL, 0x82082080UL };
static const UTF8 firstByteMark[7] = { 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC };
-#define JK_AT_STRING_PTR(x) (&((x)->stringBuffer.bytes.ptr[(x)->atIndex]))
-#define JK_END_STRING_PTR(x) (&((x)->stringBuffer.bytes.ptr[(x)->stringBuffer.bytes.length]))
+#define CDVJK_AT_STRING_PTR(x) (&((x)->stringBuffer.bytes.ptr[(x)->atIndex]))
+#define CDVJK_END_STRING_PTR(x) (&((x)->stringBuffer.bytes.ptr[(x)->stringBuffer.bytes.length]))
-static JKArray *_JKArrayCreate(id *objects, NSUInteger count, BOOL mutableCollection);
-static void _JKArrayInsertObjectAtIndex(JKArray *array, id newObject, NSUInteger objectIndex);
-static void _JKArrayReplaceObjectAtIndexWithObject(JKArray *array, NSUInteger objectIndex, id newObject);
-static void _JKArrayRemoveObjectAtIndex(JKArray *array, NSUInteger objectIndex);
+static CDVJKArray *_CDVJKArrayCreate(id *objects, NSUInteger count, BOOL mutableCollection);
+static void _CDVJKArrayInsertObjectAtIndex(CDVJKArray *array, id newObject, NSUInteger objectIndex);
+static void _CDVJKArrayReplaceObjectAtIndexWithObject(CDVJKArray *array, NSUInteger objectIndex, id newObject);
+static void _CDVJKArrayRemoveObjectAtIndex(CDVJKArray *array, NSUInteger objectIndex);
-static NSUInteger _JKDictionaryCapacityForCount(NSUInteger count);
-static JKDictionary *_JKDictionaryCreate(id *keys, NSUInteger *keyHashes, id *objects, NSUInteger count, BOOL mutableCollection);
-static JKHashTableEntry *_JKDictionaryHashEntry(JKDictionary *dictionary);
-static NSUInteger _JKDictionaryCapacity(JKDictionary *dictionary);
-static void _JKDictionaryResizeIfNeccessary(JKDictionary *dictionary);
-static void _JKDictionaryRemoveObjectWithEntry(JKDictionary *dictionary, JKHashTableEntry *entry);
-static void _JKDictionaryAddObject(JKDictionary *dictionary, NSUInteger keyHash, id key, id object);
-static JKHashTableEntry *_JKDictionaryHashTableEntryForKey(JKDictionary *dictionary, id aKey);
+static NSUInteger _CDVJKDictionaryCapacityForCount(NSUInteger count);
+static CDVJKDictionary *_CDVJKDictionaryCreate(id *keys, NSUInteger *keyHashes, id *objects, NSUInteger count, BOOL mutableCollection);
+static CDVJKHashTableEntry *_CDVJKDictionaryHashEntry(CDVJKDictionary *dictionary);
+static NSUInteger _CDVJKDictionaryCapacity(CDVJKDictionary *dictionary);
+static void _CDVJKDictionaryResizeIfNeccessary(CDVJKDictionary *dictionary);
+static void _CDVJKDictionaryRemoveObjectWithEntry(CDVJKDictionary *dictionary, CDVJKHashTableEntry *entry);
+static void _CDVJKDictionaryAddObject(CDVJKDictionary *dictionary, NSUInteger keyHash, id key, id object);
+static CDVJKHashTableEntry *_CDVJKDictionaryHashTableEntryForKey(CDVJKDictionary *dictionary, id aKey);
-static void _JSONDecoderCleanup(JSONDecoder *decoder);
+static void _JSONDecoderCleanup(CDVJSONDecoder *decoder);
-static id _NSStringObjectFromJSONString(NSString *jsonString, JKParseOptionFlags parseOptionFlags, NSError **error, BOOL mutableCollection);
+static id _NSStringObjectFromJSONString(NSString *jsonString, CDVJKParseOptionFlags parseOptionFlags, NSError **error, BOOL mutableCollection);
-static void jk_managedBuffer_release(JKManagedBuffer *managedBuffer);
-static void jk_managedBuffer_setToStackBuffer(JKManagedBuffer *managedBuffer, unsigned char *ptr, size_t length);
-static unsigned char *jk_managedBuffer_resize(JKManagedBuffer *managedBuffer, size_t newSize);
-static void jk_objectStack_release(JKObjectStack *objectStack);
-static void jk_objectStack_setToStackBuffer(JKObjectStack *objectStack, void **objects, void **keys, CFHashCode *cfHashes, size_t count);
-static int jk_objectStack_resize(JKObjectStack *objectStack, size_t newCount);
+static void jk_managedBuffer_release(CDVJKManagedBuffer *managedBuffer);
+static void jk_managedBuffer_setToStackBuffer(CDVJKManagedBuffer *managedBuffer, unsigned char *ptr, size_t length);
+static unsigned char *jk_managedBuffer_resize(CDVJKManagedBuffer *managedBuffer, size_t newSize);
+static void jk_objectStack_release(CDVJKObjectStack *objectStack);
+static void jk_objectStack_setToStackBuffer(CDVJKObjectStack *objectStack, void **objects, void **keys, CFHashCode *cfHashes, size_t count);
+static int jk_objectStack_resize(CDVJKObjectStack *objectStack, size_t newCount);
-static void jk_error(JKParseState *parseState, NSString *format, ...);
-static int jk_parse_string(JKParseState *parseState);
-static int jk_parse_number(JKParseState *parseState);
-static size_t jk_parse_is_newline(JKParseState *parseState, const unsigned char *atCharacterPtr);
-JK_STATIC_INLINE int jk_parse_skip_newline(JKParseState *parseState);
-JK_STATIC_INLINE void jk_parse_skip_whitespace(JKParseState *parseState);
-static int jk_parse_next_token(JKParseState *parseState);
-static void jk_error_parse_accept_or3(JKParseState *parseState, int state, NSString *or1String, NSString *or2String, NSString *or3String);
-static void *jk_create_dictionary(JKParseState *parseState, size_t startingObjectIndex);
-static void *jk_parse_dictionary(JKParseState *parseState);
-static void *jk_parse_array(JKParseState *parseState);
-static void *jk_object_for_token(JKParseState *parseState);
-static void *jk_cachedObjects(JKParseState *parseState);
-JK_STATIC_INLINE void jk_cache_age(JKParseState *parseState);
-JK_STATIC_INLINE void jk_set_parsed_token(JKParseState *parseState, const unsigned char *ptr, size_t length, JKTokenType type, size_t advanceBy);
+static void jk_error(CDVJKParseState *parseState, NSString *format, ...);
+static int jk_parse_string(CDVJKParseState *parseState);
+static int jk_parse_number(CDVJKParseState *parseState);
+static size_t jk_parse_is_newline(CDVJKParseState *parseState, const unsigned char *atCharacterPtr);
+CDVJK_STATIC_INLINE int jk_parse_skip_newline(CDVJKParseState *parseState);
+CDVJK_STATIC_INLINE void jk_parse_skip_whitespace(CDVJKParseState *parseState);
+static int jk_parse_next_token(CDVJKParseState *parseState);
+static void jk_error_parse_accept_or3(CDVJKParseState *parseState, int state, NSString *or1String, NSString *or2String, NSString *or3String);
+static void *jk_create_dictionary(CDVJKParseState *parseState, size_t startingObjectIndex);
+static void *jk_parse_dictionary(CDVJKParseState *parseState);
+static void *jk_parse_array(CDVJKParseState *parseState);
+static void *jk_object_for_token(CDVJKParseState *parseState);
+static void *jk_cachedObjects(CDVJKParseState *parseState);
+CDVJK_STATIC_INLINE void jk_cache_age(CDVJKParseState *parseState);
+CDVJK_STATIC_INLINE void jk_set_parsed_token(CDVJKParseState *parseState, const unsigned char *ptr, size_t length, CDVJKTokenType type, size_t advanceBy);
-static void jk_encode_error(JKEncodeState *encodeState, NSString *format, ...);
-static int jk_encode_printf(JKEncodeState *encodeState, JKEncodeCache *cacheSlot, size_t startingAtIndex, id object, const char *format, ...);
-static int jk_encode_write(JKEncodeState *encodeState, JKEncodeCache *cacheSlot, size_t startingAtIndex, id object, const char *format);
-static int jk_encode_writePrettyPrintWhiteSpace(JKEncodeState *encodeState);
-static int jk_encode_write1slow(JKEncodeState *encodeState, ssize_t depthChange, const char *format);
-static int jk_encode_write1fast(JKEncodeState *encodeState, ssize_t depthChange JK_UNUSED_ARG, const char *format);
-static int jk_encode_writen(JKEncodeState *encodeState, JKEncodeCache *cacheSlot, size_t startingAtIndex, id object, const char *format, size_t length);
-JK_STATIC_INLINE JKHash jk_encode_object_hash(void *objectPtr);
-JK_STATIC_INLINE void jk_encode_updateCache(JKEncodeState *encodeState, JKEncodeCache *cacheSlot, size_t startingAtIndex, id object);
-static int jk_encode_add_atom_to_buffer(JKEncodeState *encodeState, void *objectPtr);
+static void jk_encode_error(CDVJKEncodeState *encodeState, NSString *format, ...);
+static int jk_encode_printf(CDVJKEncodeState *encodeState, CDVJKEncodeCache *cacheSlot, size_t startingAtIndex, id object, const char *format, ...);
+static int jk_encode_write(CDVJKEncodeState *encodeState, CDVJKEncodeCache *cacheSlot, size_t startingAtIndex, id object, const char *format);
+static int jk_encode_writePrettyPrintWhiteSpace(CDVJKEncodeState *encodeState);
+static int jk_encode_write1slow(CDVJKEncodeState *encodeState, ssize_t depthChange, const char *format);
+static int jk_encode_write1fast(CDVJKEncodeState *encodeState, ssize_t depthChange CDVJK_UNUSED_ARG, const char *format);
+static int jk_encode_writen(CDVJKEncodeState *encodeState, CDVJKEncodeCache *cacheSlot, size_t startingAtIndex, id object, const char *format, size_t length);
+CDVJK_STATIC_INLINE CDVJKHash jk_encode_object_hash(void *objectPtr);
+CDVJK_STATIC_INLINE void jk_encode_updateCache(CDVJKEncodeState *encodeState, CDVJKEncodeCache *cacheSlot, size_t startingAtIndex, id object);
+static int jk_encode_add_atom_to_buffer(CDVJKEncodeState *encodeState, void *objectPtr);
-#define jk_encode_write1(es, dc, f) (JK_EXPECT_F(_jk_encode_prettyPrint) ? jk_encode_write1slow(es, dc, f) : jk_encode_write1fast(es, dc, f))
+#define jk_encode_write1(es, dc, f) (CDVJK_EXPECT_F(_jk_encode_prettyPrint) ? jk_encode_write1slow(es, dc, f) : jk_encode_write1fast(es, dc, f))
-JK_STATIC_INLINE size_t jk_min(size_t a, size_t b);
-JK_STATIC_INLINE size_t jk_max(size_t a, size_t b);
-JK_STATIC_INLINE JKHash calculateHash(JKHash currentHash, unsigned char c);
+CDVJK_STATIC_INLINE size_t jk_min(size_t a, size_t b);
+CDVJK_STATIC_INLINE size_t jk_max(size_t a, size_t b);
+CDVJK_STATIC_INLINE CDVJKHash calculateHash(CDVJKHash currentHash, unsigned char c);
-// JSONKit v1.4 used both a JKArray : NSArray and JKMutableArray : NSMutableArray, and the same for the dictionary collection type.
+// CDVJSONKit v1.4 used both a CDVJKArray : NSArray and CDVJKMutableArray : NSMutableArray, and the same for the dictionary collection type.
// However, Louis Gerbarg (via cocoa-dev) pointed out that Cocoa / Core Foundation actually implements only a single class that inherits from the
// mutable version, and keeps an ivar bit for whether or not that instance is mutable. This means that the immutable versions of the collection
// classes receive the mutating methods, but this is handled by having those methods throw an exception when the ivar bit is set to immutable.
-// We adopt the same strategy here. It's both cleaner and gets rid of the method swizzling hackery used in JSONKit v1.4.
+// We adopt the same strategy here. It's both cleaner and gets rid of the method swizzling hackery used in CDVJSONKit v1.4.
// This is a workaround for issue #23 https://github.com/johnezang/JSONKit/pull/23
// Basically, there seem to be a problem with using +load in static libraries on iOS. However, __attribute__ ((constructor)) does work correctly.
// Since we do not require anything "special" that +load provides, and we can accomplish the same thing using __attribute__ ((constructor)), the +load logic was moved here.
-static Class _JKArrayClass = NULL;
-static size_t _JKArrayInstanceSize = 0UL;
-static Class _JKDictionaryClass = NULL;
-static size_t _JKDictionaryInstanceSize = 0UL;
+static Class _CDVJKArrayClass = NULL;
+static size_t _CDVJKArrayInstanceSize = 0UL;
+static Class _CDVJKDictionaryClass = NULL;
+static size_t _CDVJKDictionaryInstanceSize = 0UL;
-// For JSONDecoder...
-static Class _jk_NSNumberClass = NULL;
-static NSNumberAllocImp _jk_NSNumberAllocImp = NULL;
-static NSNumberInitWithUnsignedLongLongImp _jk_NSNumberInitWithUnsignedLongLongImp = NULL;
+// For CDVJSONDecoder...
+static Class _CDVjk_NSNumberClass = NULL;
+static NSNumberAllocImp _CDVjk_NSNumberAllocImp = NULL;
+static NSNumberInitWithUnsignedLongLongImp _CDVjk_NSNumberInitWithUnsignedLongLongImp = NULL;
extern void jk_collectionClassLoadTimeInitialization(void) __attribute__ ((constructor));
void jk_collectionClassLoadTimeInitialization(void) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; // Though technically not required, the run time environment at load time initialization may be less than ideal.
- _JKArrayClass = objc_getClass("JKArray");
- _JKArrayInstanceSize = jk_max(16UL, class_getInstanceSize(_JKArrayClass));
+ _CDVJKArrayClass = objc_getClass("CDVJKArray");
+ _CDVJKArrayInstanceSize = jk_max(16UL, class_getInstanceSize(_CDVJKArrayClass));
- _JKDictionaryClass = objc_getClass("JKDictionary");
- _JKDictionaryInstanceSize = jk_max(16UL, class_getInstanceSize(_JKDictionaryClass));
+ _CDVJKDictionaryClass = objc_getClass("CDVJKDictionary");
+ _CDVJKDictionaryInstanceSize = jk_max(16UL, class_getInstanceSize(_CDVJKDictionaryClass));
- // For JSONDecoder...
- _jk_NSNumberClass = [NSNumber class];
- _jk_NSNumberAllocImp = (NSNumberAllocImp)[NSNumber methodForSelector:@selector(alloc)];
+ // For CDVJSONDecoder...
+ _CDVjk_NSNumberClass = [NSNumber class];
+ _CDVjk_NSNumberAllocImp = (NSNumberAllocImp)[NSNumber methodForSelector:@selector(alloc)];
// Hacktacular. Need to do it this way due to the nature of class clusters.
id temp_NSNumber = [NSNumber alloc];
- _jk_NSNumberInitWithUnsignedLongLongImp = (NSNumberInitWithUnsignedLongLongImp)[temp_NSNumber methodForSelector:@selector(initWithUnsignedLongLong:)];
+ _CDVjk_NSNumberInitWithUnsignedLongLongImp = (NSNumberInitWithUnsignedLongLongImp)[temp_NSNumber methodForSelector:@selector(initWithUnsignedLongLong:)];
[[temp_NSNumber init] release];
temp_NSNumber = NULL;
@@ -658,30 +658,30 @@ void jk_collectionClassLoadTimeInitialization(void) {
#pragma mark -
-@interface JKArray : NSMutableArray <NSCopying, NSMutableCopying, NSFastEnumeration> {
+@interface CDVJKArray : NSMutableArray <NSCopying, NSMutableCopying, NSFastEnumeration> {
id *objects;
NSUInteger count, capacity, mutations;
}
@end
-@implementation JKArray
+@implementation CDVJKArray
+ (id)allocWithZone:(NSZone *)zone
{
#pragma unused(zone)
- [NSException raise:NSInvalidArgumentException format:@"*** - [%@ %@]: The %@ class is private to JSONKit and should not be used in this fashion.", NSStringFromClass([self class]), NSStringFromSelector(_cmd), NSStringFromClass([self class])];
+ [NSException raise:NSInvalidArgumentException format:@"*** - [%@ %@]: The %@ class is private to CDVJSONKit and should not be used in this fashion.", NSStringFromClass([self class]), NSStringFromSelector(_cmd), NSStringFromClass([self class])];
return(NULL);
}
-static JKArray *_JKArrayCreate(id *objects, NSUInteger count, BOOL mutableCollection) {
- NSCParameterAssert((objects != NULL) && (_JKArrayClass != NULL) && (_JKArrayInstanceSize > 0UL));
- JKArray *array = NULL;
- if(JK_EXPECT_T((array = (JKArray *)calloc(1UL, _JKArrayInstanceSize)) != NULL)) { // Directly allocate the JKArray instance via calloc.
- array->isa = _JKArrayClass;
+static CDVJKArray *_CDVJKArrayCreate(id *objects, NSUInteger count, BOOL mutableCollection) {
+ NSCParameterAssert((objects != NULL) && (_CDVJKArrayClass != NULL) && (_CDVJKArrayInstanceSize > 0UL));
+ CDVJKArray *array = NULL;
+ if(CDVJK_EXPECT_T((array = (CDVJKArray *)calloc(1UL, _CDVJKArrayInstanceSize)) != NULL)) { // Directly allocate the CDVJKArray instance via calloc.
+ array->isa = _CDVJKArrayClass;
if((array = [array init]) == NULL) { return(NULL); }
array->capacity = count;
array->count = count;
- if(JK_EXPECT_F((array->objects = (id *)malloc(sizeof(id) * array->capacity)) == NULL)) { [array autorelease]; return(NULL); }
+ if(CDVJK_EXPECT_F((array->objects = (id *)malloc(sizeof(id) * array->capacity)) == NULL)) { [array autorelease]; return(NULL); }
memcpy(array->objects, objects, array->capacity * sizeof(id));
array->mutations = (mutableCollection == NO) ? 0UL : 1UL;
}
@@ -689,7 +689,7 @@ static JKArray *_JKArrayCreate(id *objects, NSUInteger count, BOOL mutableCollec
}
// Note: The caller is responsible for -retaining the object that is to be added.
-static void _JKArrayInsertObjectAtIndex(JKArray *array, id newObject, NSUInteger objectIndex) {
+static void _CDVJKArrayInsertObjectAtIndex(CDVJKArray *array, id newObject, NSUInteger objectIndex) {
NSCParameterAssert((array != NULL) && (array->objects != NULL) && (array->count <= array->capacity) && (objectIndex <= array->count) && (newObject != NULL));
if(!((array != NULL) && (array->objects != NULL) && (objectIndex <= array->count) && (newObject != NULL))) { [newObject autorelease]; return; }
if((array->count + 1UL) >= array->capacity) {
@@ -705,7 +705,7 @@ static void _JKArrayInsertObjectAtIndex(JKArray *array, id newObject, NSUInteger
}
// Note: The caller is responsible for -retaining the object that is to be added.
-static void _JKArrayReplaceObjectAtIndexWithObject(JKArray *array, NSUInteger objectIndex, id newObject) {
+static void _CDVJKArrayReplaceObjectAtIndexWithObject(CDVJKArray *array, NSUInteger objectIndex, id newObject) {
NSCParameterAssert((array != NULL) && (array->objects != NULL) && (array->count <= array->capacity) && (objectIndex < array->count) && (array->objects[objectIndex] != NULL) && (newObject != NULL));
if(!((array != NULL) && (array->objects != NULL) && (objectIndex < array->count) && (array->objects[objectIndex] != NULL) && (newObject != NULL))) { [newObject autorelease]; return; }
CFRelease(array->objects[objectIndex]);
@@ -713,7 +713,7 @@ static void _JKArrayReplaceObjectAtIndexWithObject(JKArray *array, NSUInteger ob
array->objects[objectIndex] = newObject;
}
-static void _JKArrayRemoveObjectAtIndex(JKArray *array, NSUInteger objectIndex) {
+static void _CDVJKArrayRemoveObjectAtIndex(CDVJKArray *array, NSUInteger objectIndex) {
NSCParameterAssert((array != NULL) && (array->objects != NULL) && (array->count > 0UL) && (array->count <= array->capacity) && (objectIndex < array->count) && (array->objects[objectIndex] != NULL));
if(!((array != NULL) && (array->objects != NULL) && (array->count > 0UL) && (array->count <= array->capacity) && (objectIndex < array->count) && (array->objects[objectIndex] != NULL))) { return; }
CFRelease(array->objects[objectIndex]);
@@ -724,9 +724,9 @@ static void _JKArrayRemoveObjectAtIndex(JKArray *array, NSUInteger objectIndex)
- (void)dealloc
{
- if(JK_EXPECT_T(objects != NULL)) {
+ if(CDVJK_EXPECT_T(objects != NULL)) {
NSUInteger atObject = 0UL;
- for(atObject = 0UL; atObject < count; atObject++) { if(JK_EXPECT_T(objects[atObject] != NULL)) { CFRelease(objects[atObject]); objects[atObject] = NULL; } }
+ for(atObject = 0UL; atObject < count; atObject++) { if(CDVJK_EXPECT_T(objects[atObject] != NULL)) { CFRelease(objects[atObject]); objects[atObject] = NULL; } }
free(objects); objects = NULL;
}
@@ -757,11 +757,11 @@ static void _JKArrayRemoveObjectAtIndex(JKArray *array, NSUInteger objectIndex)
- (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state objects:(id *)stackbuf count:(NSUInteger)len
{
NSParameterAssert((state != NULL) && (stackbuf != NULL) && (len > 0UL) && (objects != NULL) && (count <= capacity));
- if(JK_EXPECT_F(state->state == 0UL)) { state->mutationsPtr = (unsigned long *)&mutations; state->itemsPtr = stackbuf; }
- if(JK_EXPECT_F(state->state >= count)) { return(0UL); }
+ if(CDVJK_EXPECT_F(state->state == 0UL)) { state->mutationsPtr = (unsigned long *)&mutations; state->itemsPtr = stackbuf; }
+ if(CDVJK_EXPECT_F(state->state >= count)) { return(0UL); }
NSUInteger enumeratedCount = 0UL;
- while(JK_EXPECT_T(enumeratedCount < len) && JK_EXPECT_T(state->state < count)) { NSParameterAssert(objects[state->state] != NULL); stackbuf[enumeratedCount++] = objects[state->state++]; }
+ while(CDVJK_EXPECT_T(enumeratedCount < len) && CDVJK_EXPECT_T(state->state < count)) { NSParameterAssert(objects[state->state] != NULL); stackbuf[enumeratedCount++] = objects[state->state++]; }
return(enumeratedCount);
}
@@ -776,7 +776,7 @@ static void _JKArrayRemoveObjectAtIndex(JKArray *array, NSUInteger objectIndex)
#else
anObject = [anObject retain];
#endif
- _JKArrayInsertObjectAtIndex(self, anObject, objectIndex);
+ _CDVJKArrayInsertObjectAtIndex(self, anObject, objectIndex);
mutations = (mutations == NSUIntegerMax) ? 1UL : mutations + 1UL;
}
@@ -784,7 +784,7 @@ static void _JKArrayRemoveObjectAtIndex(JKArray *array, NSUInteger objectIndex)
{
if(mutations == 0UL) { [NSException raise:NSInternalInconsistencyException format:@"*** -[%@ %@]: mutating method sent to immutable object", NSStringFromClass([self class]), NSStringFromSelector(_cmd)]; }
if(objectIndex >= count) { [NSException raise:NSRangeException format:@"*** -[%@ %@]: index (%lu) beyond bounds (%lu)", NSStringFromClass([self class]), NSStringFromSelector(_cmd), objectIndex, count]; }
- _JKArrayRemoveObjectAtIndex(self, objectIndex);
+ _CDVJKArrayRemoveObjectAtIndex(self, objectIndex);
mutations = (mutations == NSUIntegerMax) ? 1UL : mutations + 1UL;
}
@@ -798,7 +798,7 @@ static void _JKArrayRemoveObjectAtIndex(JKArray *array, NSUInteger objectIndex)
#else
anObject = [anObject retain];
#endif
- _JKArrayReplaceObjectAtIndexWithObject(self, objectIndex, anObject);
+ _CDVJKArrayReplaceObjectAtIndexWithObject(self, objectIndex, anObject);
mutations = (mutations == NSUIntegerMax) ? 1UL : mutations + 1UL;
}
@@ -818,20 +818,20 @@ static void _JKArrayRemoveObjectAtIndex(JKArray *array, NSUInteger objectIndex)
#pragma mark -
-@interface JKDictionaryEnumerator : NSEnumerator {
+@interface CDVJKDictionaryEnumerator : NSEnumerator {
id collection;
NSUInteger nextObject;
}
-- (id)initWithJKDictionary:(JKDictionary *)initDictionary;
+- (id)initWithJKDictionary:(CDVJKDictionary *)initDictionary;
- (NSArray *)allObjects;
- (id)nextObject;
@end
-@implementation JKDictionaryEnumerator
+@implementation CDVJKDictionaryEnumerator
-- (id)initWithJKDictionary:(JKDictionary *)initDictionary
+- (id)initWithJKDictionary:(CDVJKDictionary *)initDictionary
{
NSParameterAssert(initDictionary != NULL);
if((self = [super init]) == NULL) { return(NULL); }
@@ -858,9 +858,9 @@ static void _JKArrayRemoveObjectAtIndex(JKArray *array, NSUInteger objectIndex)
- (id)nextObject
{
- NSParameterAssert((collection != NULL) && (_JKDictionaryHashEntry(collection) != NULL));
- JKHashTableEntry *entry = _JKDictionaryHashEntry(collection);
- NSUInteger capacity = _JKDictionaryCapacity(collection);
+ NSParameterAssert((collection != NULL) && (_CDVJKDictionaryHashEntry(collection) != NULL));
+ CDVJKHashTableEntry *entry = _CDVJKDictionaryHashEntry(collection);
+ NSUInteger capacity = _CDVJKDictionaryCapacity(collection);
id returnObject = NULL;
if(entry != NULL) { while((nextObject < capacity) && ((returnObject = entry[nextObject++].key) == NULL)) { /* ... */ } }
@@ -871,22 +871,22 @@ static void _JKArrayRemoveObjectAtIndex(JKArray *array, NSUInteger objectIndex)
@end
#pragma mark -
-@interface JKDictionary : NSMutableDictionary <NSCopying, NSMutableCopying, NSFastEnumeration> {
+@interface CDVJKDictionary : NSMutableDictionary <NSCopying, NSMutableCopying, NSFastEnumeration> {
NSUInteger count, capacity, mutations;
- JKHashTableEntry *entry;
+ CDVJKHashTableEntry *entry;
}
@end
-@implementation JKDictionary
+@implementation CDVJKDictionary
+ (id)allocWithZone:(NSZone *)zone
{
#pragma unused(zone)
- [NSException raise:NSInvalidArgumentException format:@"*** - [%@ %@]: The %@ class is private to JSONKit and should not be used in this fashion.", NSStringFromClass([self class]), NSStringFromSelector(_cmd), NSStringFromClass([self class])];
+ [NSException raise:NSInvalidArgumentException format:@"*** - [%@ %@]: The %@ class is private to CDVJSONKit and should not be used in this fashion.", NSStringFromClass([self class]), NSStringFromSelector(_cmd), NSStringFromClass([self class])];
return(NULL);
}
-// These values are taken from Core Foundation CF-550 CFBasicHash.m. As a bonus, they align very well with our JKHashTableEntry struct too.
+// These values are taken from Core Foundation CF-550 CFBasicHash.m. As a bonus, they align very well with our CDVJKHashTableEntry struct too.
static const NSUInteger jk_dictionaryCapacities[] = {
0UL, 3UL, 7UL, 13UL, 23UL, 41UL, 71UL, 127UL, 191UL, 251UL, 383UL, 631UL, 1087UL, 1723UL,
2803UL, 4523UL, 7351UL, 11959UL, 19447UL, 31231UL, 50683UL, 81919UL, 132607UL,
@@ -895,46 +895,46 @@ static const NSUInteger jk_dictionaryCapacities[] = {
111638519UL, 180634607UL, 292272623UL, 472907251UL
};
-static NSUInteger _JKDictionaryCapacityForCount(NSUInteger count) {
+static NSUInteger _CDVJKDictionaryCapacityForCount(NSUInteger count) {
NSUInteger bottom = 0UL, top = sizeof(jk_dictionaryCapacities) / sizeof(NSUInteger), mid = 0UL, tableSize = lround(floor((count) * 1.33));
while(top > bottom) { mid = (top + bottom) / 2UL; if(jk_dictionaryCapacities[mid] < tableSize) { bottom = mid + 1UL; } else { top = mid; } }
return(jk_dictionaryCapacities[bottom]);
}
-static void _JKDictionaryResizeIfNeccessary(JKDictionary *dictionary) {
+static void _CDVJKDictionaryResizeIfNeccessary(CDVJKDictionary *dictionary) {
NSCParameterAssert((dictionary != NULL) && (dictionary->entry != NULL) && (dictionary->count <= dictionary->capacity));
NSUInteger capacityForCount = 0UL;
- if(dictionary->capacity < (capacityForCount = _JKDictionaryCapacityForCount(dictionary->count + 1UL))) { // resize
+ if(dictionary->capacity < (capacityForCount = _CDVJKDictionaryCapacityForCount(dictionary->count + 1UL))) { // resize
NSUInteger oldCapacity = dictionary->capacity;
#ifndef NS_BLOCK_ASSERTIONS
NSUInteger oldCount = dictionary->count;
#endif
- JKHashTableEntry *oldEntry = dictionary->entry;
- if(JK_EXPECT_F((dictionary->entry = (JKHashTableEntry *)calloc(1UL, sizeof(JKHashTableEntry) * capacityForCount)) == NULL)) { [NSException raise:NSMallocException format:@"Unable to allocate memory for hash table."]; }
+ CDVJKHashTableEntry *oldEntry = dictionary->entry;
+ if(CDVJK_EXPECT_F((dictionary->entry = (CDVJKHashTableEntry *)calloc(1UL, sizeof(CDVJKHashTableEntry) * capacityForCount)) == NULL)) { [NSException raise:NSMallocException format:@"Unable to allocate memory for hash table."]; }
dictionary->capacity = capacityForCount;
dictionary->count = 0UL;
NSUInteger idx = 0UL;
- for(idx = 0UL; idx < oldCapacity; idx++) { if(oldEntry[idx].key != NULL) { _JKDictionaryAddObject(dictionary, oldEntry[idx].keyHash, oldEntry[idx].key, oldEntry[idx].object); oldEntry[idx].keyHash = 0UL; oldEntry[idx].key = NULL; oldEntry[idx].object = NULL; } }
+ for(idx = 0UL; idx < oldCapacity; idx++) { if(oldEntry[idx].key != NULL) { _CDVJKDictionaryAddObject(dictionary, oldEntry[idx].keyHash, oldEntry[idx].key, oldEntry[idx].object); oldEntry[idx].keyHash = 0UL; oldEntry[idx].key = NULL; oldEntry[idx].object = NULL; } }
NSCParameterAssert((oldCount == dictionary->count));
free(oldEntry); oldEntry = NULL;
}
}
-static JKDictionary *_JKDictionaryCreate(id *keys, NSUInteger *keyHashes, id *objects, NSUInteger count, BOOL mutableCollection) {
- NSCParameterAssert((keys != NULL) && (keyHashes != NULL) && (objects != NULL) && (_JKDictionaryClass != NULL) && (_JKDictionaryInstanceSize > 0UL));
- JKDictionary *dictionary = NULL;
- if(JK_EXPECT_T((dictionary = (JKDictionary *)calloc(1UL, _JKDictionaryInstanceSize)) != NULL)) { // Directly allocate the JKDictionary instance via calloc.
- dictionary->isa = _JKDictionaryClass;
+static CDVJKDictionary *_CDVJKDictionaryCreate(id *keys, NSUInteger *keyHashes, id *objects, NSUInteger count, BOOL mutableCollection) {
+ NSCParameterAssert((keys != NULL) && (keyHashes != NULL) && (objects != NULL) && (_CDVJKDictionaryClass != NULL) && (_CDVJKDictionaryInstanceSize > 0UL));
+ CDVJKDictionary *dictionary = NULL;
+ if(CDVJK_EXPECT_T((dictionary = (CDVJKDictionary *)calloc(1UL, _CDVJKDictionaryInstanceSize)) != NULL)) { // Directly allocate the CDVJKDictionary instance via calloc.
+ dictionary->isa = _CDVJKDictionaryClass;
if((dictionary = [dictionary init]) == NULL) { return(NULL); }
- dictionary->capacity = _JKDictionaryCapacityForCount(count);
+ dictionary->capacity = _CDVJKDictionaryCapacityForCount(count);
dictionary->count = 0UL;
- if(JK_EXPECT_F((dictionary->entry = (JKHashTableEntry *)calloc(1UL, sizeof(JKHashTableEntry) * dictionary->capacity)) == NULL)) { [dictionary autorelease]; return(NULL); }
+ if(CDVJK_EXPECT_F((dictionary->entry = (CDVJKHashTableEntry *)calloc(1UL, sizeof(CDVJKHashTableEntry) * dictionary->capacity)) == NULL)) { [dictionary autorelease]; return(NULL); }
NSUInteger idx = 0UL;
- for(idx = 0UL; idx < count; idx++) { _JKDictionaryAddObject(dictionary, keyHashes[idx], keys[idx], objects[idx]); }
+ for(idx = 0UL; idx < count; idx++) { _CDVJKDictionaryAddObject(dictionary, keyHashes[idx], keys[idx], objects[idx]); }
dictionary->mutations = (mutableCollection == NO) ? 0UL : 1UL;
}
@@ -943,11 +943,11 @@ static JKDictionary *_JKDictionaryCreate(id *keys, NSUInteger *keyHashes, id *ob
- (void)dealloc
{
- if(JK_EXPECT_T(entry != NULL)) {
+ if(CDVJK_EXPECT_T(entry != NULL)) {
NSUInteger atEntry = 0UL;
for(atEntry = 0UL; atEntry < capacity; atEntry++) {
- if(JK_EXPECT_T(entry[atEntry].key != NULL)) { CFRelease(entry[atEntry].key); entry[atEntry].key = NULL; }
- if(JK_EXPECT_T(entry[atEntry].object != NULL)) { CFRelease(entry[atEntry].object); entry[atEntry].object = NULL; }
+ if(CDVJK_EXPECT_T(entry[atEntry].key != NULL)) { CFRelease(entry[atEntry].key); entry[atEntry].key = NULL; }
+ if(CDVJK_EXPECT_T(entry[atEntry].object != NULL)) { CFRelease(entry[atEntry].object); entry[atEntry].object = NULL; }
}
free(entry); entry = NULL;
@@ -956,17 +956,17 @@ static JKDictionary *_JKDictionaryCreate(id *keys, NSUInteger *keyHashes, id *ob
[super dealloc];
}
-static JKHashTableEntry *_JKDictionaryHashEntry(JKDictionary *dictionary) {
+static CDVJKHashTableEntry *_CDVJKDictionaryHashEntry(CDVJKDictionary *dictionary) {
NSCParameterAssert(dictionary != NULL);
return(dictionary->entry);
}
-static NSUInteger _JKDictionaryCapacity(JKDictionary *dictionary) {
+static NSUInteger _CDVJKDictionaryCapacity(CDVJKDictionary *dictionary) {
NSCParameterAssert(dictionary != NULL);
return(dictionary->capacity);
}
-static void _JKDictionaryRemoveObjectWithEntry(JKDictionary *dictionary, JKHashTableEntry *entry) {
+static void _CDVJKDictionaryRemoveObjectWithEntry(CDVJKDictionary *dictionary, CDVJKHashTableEntry *entry) {
NSCParameterAssert((dictionary != NULL) && (entry != NULL) && (entry->key != NULL) && (entry->object != NULL) && (dictionary->count > 0UL) && (dictionary->count <= dictionary->capacity));
CFRelease(entry->key); entry->key = NULL;
CFRelease(entry->object); entry->object = NULL;
@@ -977,7 +977,7 @@ static void _JKDictionaryRemoveObjectWithEntry(JKDictionary *dictionary, JKHashT
NSCParameterAssert((removeIdx < dictionary->capacity));
for(idx = 0UL; idx < dictionary->capacity; idx++) {
NSUInteger entryIdx = (removeIdx + idx + 1UL) % dictionary->capacity;
- JKHashTableEntry *atEntry = &dictionary->entry[entryIdx];
+ CDVJKHashTableEntry *atEntry = &dictionary->entry[entryIdx];
if(atEntry->key == NULL) { break; }
NSUInteger keyHash = atEntry->keyHash;
id key = atEntry->key, object = atEntry->object;
@@ -987,20 +987,20 @@ static void _JKDictionaryRemoveObjectWithEntry(JKDictionary *dictionary, JKHashT
atEntry->object = NULL;
NSUInteger addKeyEntry = keyHash % dictionary->capacity, addIdx = 0UL;
for(addIdx = 0UL; addIdx < dictionary->capacity; addIdx++) {
- JKHashTableEntry *atAddEntry = &dictionary->entry[((addKeyEntry + addIdx) % dictionary->capacity)];
- if(JK_EXPECT_T(atAddEntry->key == NULL)) { NSCParameterAssert((atAddEntry->keyHash == 0UL) && (atAddEntry->object == NULL)); atAddEntry->key = key; atAddEntry->object = object; atAddEntry->keyHash = keyHash; break; }
+ CDVJKHashTableEntry *atAddEntry = &dictionary->entry[((addKeyEntry + addIdx) % dictionary->capacity)];
+ if(CDVJK_EXPECT_T(atAddEntry->key == NULL)) { NSCParameterAssert((atAddEntry->keyHash == 0UL) && (atAddEntry->object == NULL)); atAddEntry->key = key; atAddEntry->object = object; atAddEntry->keyHash = keyHash; break; }
}
}
}
-static void _JKDictionaryAddObject(JKDictionary *dictionary, NSUInteger keyHash, id key, id object) {
+static void _CDVJKDictionaryAddObject(CDVJKDictionary *dictionary, NSUInteger keyHash, id key, id object) {
NSCParameterAssert((dictionary != NULL) && (key != NULL) && (object != NULL) && (dictionary->count < dictionary->capacity) && (dictionary->entry != NULL));
NSUInteger keyEntry = keyHash % dictionary->capacity, idx = 0UL;
for(idx = 0UL; idx < dictionary->capacity; idx++) {
NSUInteger entryIdx = (keyEntry + idx) % dictionary->capacity;
- JKHashTableEntry *atEntry = &dictionary->entry[entryIdx];
- if(JK_EXPECT_F(atEntry->keyHash == keyHash) && JK_EXPECT_T(atEntry->key != NULL) && (JK_EXPECT_F(key == atEntry->key) || JK_EXPECT_F(CFEqual(atEntry->key, key)))) { _JKDictionaryRemoveObjectWithEntry(dictionary, atEntry); }
- if(JK_EXPECT_T(atEntry->key == NULL)) { NSCParameterAssert((atEntry->keyHash == 0UL) && (atEntry->object == NULL)); atEntry->key = key; atEntry->object = object; atEntry->keyHash = keyHash; dictionary->count++; return; }
+ CDVJKHashTableEntry *atEntry = &dictionary->entry[entryIdx];
+ if(CDVJK_EXPECT_F(atEntry->keyHash == keyHash) && CDVJK_EXPECT_T(atEntry->key != NULL) && (CDVJK_EXPECT_F(key == atEntry->key) || CDVJK_EXPECT_F(CFEqual(atEntry->key, key)))) { _CDVJKDictionaryRemoveObjectWithEntry(dictionary, atEntry); }
+ if(CDVJK_EXPECT_T(atEntry->key == NULL)) { NSCParameterAssert((atEntry->keyHash == 0UL) && (atEntry->object == NULL)); atEntry->key = key; atEntry->object = object; atEntry->keyHash = keyHash; dictionary->count++; return; }
}
// We should never get here. If we do, we -release the key / object because it's our responsibility.
@@ -1013,15 +1013,15 @@ static void _JKDictionaryAddObject(JKDictionary *dictionary, NSUInteger keyHash,
return(count);
}
-static JKHashTableEntry *_JKDictionaryHashTableEntryForKey(JKDictionary *dictionary, id aKey) {
+static CDVJKHashTableEntry *_CDVJKDictionaryHashTableEntryForKey(CDVJKDictionary *dictionary, id aKey) {
NSCParameterAssert((dictionary != NULL) && (dictionary->entry != NULL) && (dictionary->count <= dictionary->capacity));
if((aKey == NULL) || (dictionary->capacity == 0UL)) { return(NULL); }
NSUInteger keyHash = CFHash(aKey), keyEntry = (keyHash % dictionary->capacity), idx = 0UL;
- JKHashTableEntry *atEntry = NULL;
+ CDVJKHashTableEntry *atEntry = NULL;
for(idx = 0UL; idx < dictionary->capacity; idx++) {
atEntry = &dictionary->entry[(keyEntry + idx) % dictionary->capacity];
- if(JK_EXPECT_T(atEntry->keyHash == keyHash) && JK_EXPECT_T(atEntry->key != NULL) && ((atEntry->key == aKey) || CFEqual(atEntry->key, aKey))) { NSCParameterAssert(atEntry->object != NULL); return(atEntry); break; }
- if(JK_EXPECT_F(atEntry->key == NULL)) { NSCParameterAssert(atEntry->object == NULL); return(NULL); break; } // If the key was in the table, we would have found it by now.
+ if(CDVJK_EXPECT_T(atEntry->keyHash == keyHash) && CDVJK_EXPECT_T(atEntry->key != NULL) && ((atEntry->key == aKey) || CFEqual(atEntry->key, aKey))) { NSCParameterAssert(atEntry->object != NULL); return(atEntry); break; }
+ if(CDVJK_EXPECT_F(atEntry->key == NULL)) { NSCParameterAssert(atEntry->object == NULL); return(NULL); break; } // If the key was in the table, we would have found it by now.
}
return(NULL);
}
@@ -1029,7 +1029,7 @@ static JKHashTableEntry *_JKDictionaryHashTableEntryForKey(JKDictionary *diction
- (id)objectForKey:(id)aKey
{
NSParameterAssert((entry != NULL) && (count <= capacity));
- JKHashTableEntry *entryForKey = _JKDictionaryHashTableEntryForKey(self, aKey);
+ CDVJKHashTableEntry *entryForKey = _CDVJKDictionaryHashTableEntryForKey(self, aKey);
return((entryForKey != NULL) ? entryForKey->object : NULL);
}
@@ -1038,10 +1038,10 @@ static JKHashTableEntry *_JKDictionaryHashTableEntryForKey(JKDictionary *diction
NSParameterAssert((entry != NULL) && (count <= capacity));
NSUInteger atEntry = 0UL; NSUInteger arrayIdx = 0UL;
for(atEntry = 0UL; atEntry < capacity; atEntry++) {
- if(JK_EXPECT_T(entry[atEntry].key != NULL)) {
+ if(CDVJK_EXPECT_T(entry[atEntry].key != NULL)) {
NSCParameterAssert((entry[atEntry].object != NULL) && (arrayIdx < count));
- if(JK_EXPECT_T(keys != NULL)) { keys[arrayIdx] = entry[atEntry].key; }
- if(JK_EXPECT_T(objects != NULL)) { objects[arrayIdx] = entry[atEntry].object; }
+ if(CDVJK_EXPECT_T(keys != NULL)) { keys[arrayIdx] = entry[atEntry].key; }
+ if(CDVJK_EXPECT_T(objects != NULL)) { objects[arrayIdx] = entry[atEntry].object; }
arrayIdx++;
}
}
@@ -1050,18 +1050,18 @@ static JKHashTableEntry *_JKDictionaryHashTableEntryForKey(JKDictionary *diction
- (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state objects:(id *)stackbuf count:(NSUInteger)len
{
NSParameterAssert((state != NULL) && (stackbuf != NULL) && (len > 0UL) && (entry != NULL) && (count <= capacity));
- if(JK_EXPECT_F(state->state == 0UL)) { state->mutationsPtr = (unsigned long *)&mutations; state->itemsPtr = stackbuf; }
- if(JK_EXPECT_F(state->state >= capacity)) { return(0UL); }
+ if(CDVJK_EXPECT_F(state->state == 0UL)) { state->mutationsPtr = (unsigned long *)&mutations; state->itemsPtr = stackbuf; }
+ if(CDVJK_EXPECT_F(state->state >= capacity)) { return(0UL); }
NSUInteger enumeratedCount = 0UL;
- while(JK_EXPECT_T(enumeratedCount < len) && JK_EXPECT_T(state->state < capacity)) { if(JK_EXPECT_T(entry[state->state].key != NULL)) { stackbuf[enumeratedCount++] = entry[state->state].key; } state->state++; }
+ while(CDVJK_EXPECT_T(enumeratedCount < len) && CDVJK_EXPECT_T(state->state < capacity)) { if(CDVJK_EXPECT_T(entry[state->state].key != NULL)) { stackbuf[enumeratedCount++] = entry[state->state].key; } state->state++; }
return(enumeratedCount);
}
- (NSEnumerator *)keyEnumerator
{
- return([[[JKDictionaryEnumerator alloc] initWithJKDictionary:self] autorelease]);
+ return([[[CDVJKDictionaryEnumerator alloc] initWithJKDictionary:self] autorelease]);
}
- (void)setObject:(id)anObject forKey:(id)aKey
@@ -1070,12 +1070,12 @@ static JKHashTableEntry *_JKDictionaryHashTableEntryForKey(JKDictionary *diction
if(aKey == NULL) { [NSException raise:NSInvalidArgumentException format:@"*** -[%@ %@]: attempt to insert nil key", NSStringFromClass([self class]), NSStringFromSelector(_cmd)]; }
if(anObject == NULL) { [NSException raise:NSInvalidArgumentException format:@"*** -[%@ %@]: attempt to insert nil value (key: %@)", NSStringFromClass([self class]), NSStringFromSelector(_cmd), aKey]; }
- _JKDictionaryResizeIfNeccessary(self);
+ _CDVJKDictionaryResizeIfNeccessary(self);
#ifndef __clang_analyzer__
aKey = [aKey copy]; // Why on earth would clang complain that this -copy "might leak",
anObject = [anObject retain]; // but this -retain doesn't!?
#endif // __clang_analyzer__
- _JKDictionaryAddObject(self, CFHash(aKey), aKey, anObject);
+ _CDVJKDictionaryAddObject(self, CFHash(aKey), aKey, anObject);
mutations = (mutations == NSUIntegerMax) ? 1UL : mutations + 1UL;
}
@@ -1083,9 +1083,9 @@ static JKHashTableEntry *_JKDictionaryHashTableEntryForKey(JKDictionary *diction
{
if(mutations == 0UL) { [NSException raise:NSInternalInconsistencyException format:@"*** -[%@ %@]: mutating method sent to immutable object", NSStringFromClass([self class]), NSStringFromSelector(_cmd)]; }
if(aKey == NULL) { [NSException raise:NSInvalidArgumentException format:@"*** -[%@ %@]: attempt to remove nil key", NSStringFromClass([self class]), NSStringFromSelector(_cmd)]; }
- JKHashTableEntry *entryForKey = _JKDictionaryHashTableEntryForKey(self, aKey);
+ CDVJKHashTableEntry *entryForKey = _CDVJKDictionaryHashTableEntryForKey(self, aKey);
if(entryForKey != NULL) {
- _JKDictionaryRemoveObjectWithEntry(self, entryForKey);
+ _CDVJKDictionaryRemoveObjectWithEntry(self, entryForKey);
mutations = (mutations == NSUIntegerMax) ? 1UL : mutations + 1UL;
}
}
@@ -1108,12 +1108,12 @@ static JKHashTableEntry *_JKDictionaryHashTableEntryForKey(JKDictionary *diction
#pragma mark -
-JK_STATIC_INLINE size_t jk_min(size_t a, size_t b) { return((a < b) ? a : b); }
-JK_STATIC_INLINE size_t jk_max(size_t a, size_t b) { return((a > b) ? a : b); }
+CDVJK_STATIC_INLINE size_t jk_min(size_t a, size_t b) { return((a < b) ? a : b); }
+CDVJK_STATIC_INLINE size_t jk_max(size_t a, size_t b) { return((a > b) ? a : b); }
-JK_STATIC_INLINE JKHash calculateHash(JKHash currentHash, unsigned char c) { return(((currentHash << 5) + currentHash) + c); }
+CDVJK_STATIC_INLINE CDVJKHash calculateHash(CDVJKHash currentHash, unsigned char c) { return(((currentHash << 5) + currentHash) + c); }
-static void jk_error(JKParseState *parseState, NSString *format, ...) {
+static void jk_error(CDVJKParseState *parseState, NSString *format, ...) {
NSCParameterAssert((parseState != NULL) && (format != NULL));
va_list varArgsList;
@@ -1126,23 +1126,23 @@ static void jk_error(JKParseState *parseState, NSString *format, ...) {
const unsigned char *lineEnd = lineStart;
const unsigned char *atCharacterPtr = NULL;
- for(atCharacterPtr = lineStart; atCharacterPtr < JK_END_STRING_PTR(parseState); atCharacterPtr++) { lineEnd = atCharacterPtr; if(jk_parse_is_newline(parseState, atCharacterPtr)) { break; } }
+ for(atCharacterPtr = lineStart; atCharacterPtr < CDVJK_END_STRING_PTR(parseState); atCharacterPtr++) { lineEnd = atCharacterPtr; if(jk_parse_is_newline(parseState, atCharacterPtr)) { break; } }
NSString *lineString = @"", *carretString = @"";
- if(lineStart < JK_END_STRING_PTR(parseState)) {
+ if(lineStart < CDVJK_END_STRING_PTR(parseState)) {
lineString = [[[NSString alloc] initWithBytes:lineStart length:(lineEnd - lineStart) encoding:NSUTF8StringEncoding] autorelease];
carretString = [NSString stringWithFormat:@"%*.*s^", (int)(parseState->atIndex - parseState->lineStartIndex), (int)(parseState->atIndex - parseState->lineStartIndex), " "];
}
#endif
if(parseState->error == NULL) {
- parseState->error = [NSError errorWithDomain:@"JKErrorDomain" code:-1L userInfo:
+ parseState->error = [NSError errorWithDomain:@"CDVJKErrorDomain" code:-1L userInfo:
[NSDictionary dictionaryWithObjectsAndKeys:
formatString, NSLocalizedDescriptionKey,
- [NSNumber numberWithUnsignedLong:parseState->atIndex], @"JKAtIndexKey",
- [NSNumber numberWithUnsignedLong:parseState->lineNumber], @"JKLineNumberKey",
- //lineString, @"JKErrorLine0Key",
- //carretString, @"JKErrorLine1Key",
+ [NSNumber numberWithUnsignedLong:parseState->atIndex], @"CDVJKAtIndexKey",
+ [NSNumber numberWithUnsignedLong:parseState->lineNumber], @"CDVJKLineNumberKey",
+ //lineString, @"CDVJKErrorLine0Key",
+ //carretString, @"CDVJKErrorLine1Key",
NULL]];
}
}
@@ -1150,41 +1150,41 @@ static void jk_error(JKParseState *parseState, NSString *format, ...) {
#pragma mark -
#pragma mark Buffer and Object Stack management functions
-static void jk_managedBuffer_release(JKManagedBuffer *managedBuffer) {
- if((managedBuffer->flags & JKManagedBufferMustFree)) {
+static void jk_managedBuffer_release(CDVJKManagedBuffer *managedBuffer) {
+ if((managedBuffer->flags & CDVJKManagedBufferMustFree)) {
if(managedBuffer->bytes.ptr != NULL) { free(managedBuffer->bytes.ptr); managedBuffer->bytes.ptr = NULL; }
- managedBuffer->flags &= ~JKManagedBufferMustFree;
+ managedBuffer->flags &= ~CDVJKManagedBufferMustFree;
}
managedBuffer->bytes.ptr = NULL;
managedBuffer->bytes.length = 0UL;
- managedBuffer->flags &= ~JKManagedBufferLocationMask;
+ managedBuffer->flags &= ~CDVJKManagedBufferLocationMask;
}
-static void jk_managedBuffer_setToStackBuffer(JKManagedBuffer *managedBuffer, unsigned char *ptr, size_t length) {
+static void jk_managedBuffer_setToStackBuffer(CDVJKManagedBuffer *managedBuffer, unsigned char *ptr, size_t length) {
jk_managedBuffer_release(managedBuffer);
managedBuffer->bytes.ptr = ptr;
managedBuffer->bytes.length = length;
- managedBuffer->flags = (managedBuffer->flags & ~JKManagedBufferLocationMask) | JKManagedBufferOnStack;
+ managedBuffer->flags = (managedBuffer->flags & ~CDVJKManagedBufferLocationMask) | CDVJKManagedBufferOnStack;
}
-static unsigned char *jk_managedBuffer_resize(JKManagedBuffer *managedBuffer, size_t newSize) {
+static unsigned char *jk_managedBuffer_resize(CDVJKManagedBuffer *managedBuffer, size_t newSize) {
size_t roundedUpNewSize = newSize;
if(managedBuffer->roundSizeUpToMultipleOf > 0UL) { roundedUpNewSize = newSize + ((managedBuffer->roundSizeUpToMultipleOf - (newSize % managedBuffer->roundSizeUpToMultipleOf)) % managedBuffer->roundSizeUpToMultipleOf); }
if((roundedUpNewSize != managedBuffer->bytes.length) && (roundedUpNewSize > managedBuffer->bytes.length)) {
- if((managedBuffer->flags & JKManagedBufferLocationMask) == JKManagedBufferOnStack) {
- NSCParameterAssert((managedBuffer->flags & JKManagedBufferMustFree) == 0);
+ if((managedBuffer->flags & CDVJKManagedBufferLocationMask) == CDVJKManagedBufferOnStack) {
+ NSCParameterAssert((managedBuffer->flags & CDVJKManagedBufferMustFree) == 0);
unsigned char *newBuffer = NULL, *oldBuffer = managedBuffer->bytes.ptr;
if((newBuffer = (unsigned char *)malloc(roundedUpNewSize)) == NULL) { return(NULL); }
memcpy(newBuffer, oldBuffer, jk_min(managedBuffer->bytes.length, roundedUpNewSize));
- managedBuffer->flags = (managedBuffer->flags & ~JKManagedBufferLocationMask) | (JKManagedBufferOnHeap | JKManagedBufferMustFree);
+ managedBuffer->flags = (managedBuffer->flags & ~CDVJKManagedBufferLocationMask) | (CDVJKManagedBufferOnHeap | CDVJKManagedBufferMustFree);
managedBuffer->bytes.ptr = newBuffer;
managedBuffer->bytes.length = roundedUpNewSize;
} else {
- NSCParameterAssert(((managedBuffer->flags & JKManagedBufferMustFree) != 0) && ((managedBuffer->flags & JKManagedBufferLocationMask) == JKManagedBufferOnHeap));
+ NSCParameterAssert(((managedBuffer->flags & CDVJKManagedBufferMustFree) != 0) && ((managedBuffer->flags & CDVJKManagedBufferLocationMask) == CDVJKManagedBufferOnHeap));
if((managedBuffer->bytes.ptr = (unsigned char *)reallocf(managedBuffer->bytes.ptr, roundedUpNewSize)) == NULL) { return(NULL); }
managedBuffer->bytes.length = roundedUpNewSize;
}
@@ -1195,7 +1195,7 @@ static unsigned char *jk_managedBuffer_resize(JKManagedBuffer *managedBuffer, si
-static void jk_objectStack_release(JKObjectStack *objectStack) {
+static void jk_objectStack_release(CDVJKObjectStack *objectStack) {
NSCParameterAssert(objectStack != NULL);
NSCParameterAssert(objectStack->index <= objectStack->count);
@@ -1206,12 +1206,12 @@ static void jk_objectStack_release(JKObjectStack *objectStack) {
}
objectStack->index = 0UL;
- if(objectStack->flags & JKObjectStackMustFree) {
- NSCParameterAssert((objectStack->flags & JKObjectStackLocationMask) == JKObjectStackOnHeap);
+ if(objectStack->flags & CDVJKObjectStackMustFree) {
+ NSCParameterAssert((objectStack->flags & CDVJKObjectStackLocationMask) == CDVJKObjectStackOnHeap);
if(objectStack->objects != NULL) { free(objectStack->objects); objectStack->objects = NULL; }
if(objectStack->keys != NULL) { free(objectStack->keys); objectStack->keys = NULL; }
if(objectStack->cfHashes != NULL) { free(objectStack->cfHashes); objectStack->cfHashes = NULL; }
- objectStack->flags &= ~JKObjectStackMustFree;
+ objectStack->flags &= ~CDVJKObjectStackMustFree;
}
objectStack->objects = NULL;
@@ -1219,24 +1219,24 @@ static void jk_objectStack_release(JKObjectStack *objectStack) {
objectStack->cfHashes = NULL;
objectStack->count = 0UL;
- objectStack->flags &= ~JKObjectStackLocationMask;
+ objectStack->flags &= ~CDVJKObjectStackLocationMask;
}
-static void jk_objectStack_setToStackBuffer(JKObjectStack *objectStack, void **objects, void **keys, CFHashCode *cfHashes, size_t count) {
+static void jk_objectStack_setToStackBuffer(CDVJKObjectStack *objectStack, void **objects, void **keys, CFHashCode *cfHashes, size_t count) {
NSCParameterAssert((objectStack != NULL) && (objects != NULL) && (keys != NULL) && (cfHashes != NULL) && (count > 0UL));
jk_objectStack_release(objectStack);
objectStack->objects = objects;
objectStack->keys = keys;
objectStack->cfHashes = cfHashes;
objectStack->count = count;
- objectStack->flags = (objectStack->flags & ~JKObjectStackLocationMask) | JKObjectStackOnStack;
+ objectStack->flags = (objectStack->flags & ~CDVJKObjectStackLocationMask) | CDVJKObjectStackOnStack;
#ifndef NS_BLOCK_ASSERTIONS
size_t idx;
for(idx = 0UL; idx < objectStack->count; idx++) { objectStack->objects[idx] = NULL; objectStack->keys[idx] = NULL; objectStack->cfHashes[idx] = 0UL; }
#endif
}
-static int jk_objectStack_resize(JKObjectStack *objectStack, size_t newCount) {
+static int jk_objectStack_resize(CDVJKObjectStack *objectStack, size_t newCount) {
size_t roundedUpNewCount = newCount;
int returnCode = 0;
@@ -1246,8 +1246,8 @@ static int jk_objectStack_resize(JKObjectStack *objectStack, size_t newCount) {
if(objectStack->roundSizeUpToMultipleOf > 0UL) { roundedUpNewCount = newCount + ((objectStack->roundSizeUpToMultipleOf - (newCount % objectStack->roundSizeUpToMultipleOf)) % objectStack->roundSizeUpToMultipleOf); }
if((roundedUpNewCount != objectStack->count) && (roundedUpNewCount > objectStack->count)) {
- if((objectStack->flags & JKObjectStackLocationMask) == JKObjectStackOnStack) {
- NSCParameterAssert((objectStack->flags & JKObjectStackMustFree) == 0);
+ if((objectStack->flags & CDVJKObjectStackLocationMask) == CDVJKObjectStackOnStack) {
+ NSCParameterAssert((objectStack->flags & CDVJKObjectStackMustFree) == 0);
if((newObjects = (void ** )calloc(1UL, roundedUpNewCount * sizeof(void * ))) == NULL) { returnCode = 1; goto errorExit; }
memcpy(newObjects, objectStack->objects, jk_min(objectStack->count, roundedUpNewCount) * sizeof(void *));
@@ -1257,13 +1257,13 @@ static int jk_objectStack_resize(JKObjectStack *objectStack, size_t newCount) {
if((newCFHashes = (CFHashCode *)calloc(1UL, roundedUpNewCount * sizeof(CFHashCode))) == NULL) { returnCode = 1; goto errorExit; }
memcpy(newCFHashes, objectStack->cfHashes, jk_min(objectStack->count, roundedUpNewCount) * sizeof(CFHashCode));
- objectStack->flags = (objectStack->flags & ~JKObjectStackLocationMask) | (JKObjectStackOnHeap | JKObjectStackMustFree);
+ objectStack->flags = (objectStack->flags & ~CDVJKObjectStackLocationMask) | (CDVJKObjectStackOnHeap | CDVJKObjectStackMustFree);
objectStack->objects = newObjects; newObjects = NULL;
objectStack->keys = newKeys; newKeys = NULL;
objectStack->cfHashes = newCFHashes; newCFHashes = NULL;
objectStack->count = roundedUpNewCount;
} else {
- NSCParameterAssert(((objectStack->flags & JKObjectStackMustFree) != 0) && ((objectStack->flags & JKObjectStackLocationMask) == JKObjectStackOnHeap));
+ NSCParameterAssert(((objectStack->flags & CDVJKObjectStackMustFree) != 0) && ((objectStack->flags & CDVJKObjectStackLocationMask) == CDVJKObjectStackOnHeap));
if((newObjects = (void ** )realloc(objectStack->objects, roundedUpNewCount * sizeof(void * ))) != NULL) { objectStack->objects = newObjects; newObjects = NULL; } else { returnCode = 1; goto errorExit; }
if((newKeys = (void ** )realloc(objectStack->keys, roundedUpNewCount * sizeof(void * ))) != NULL) { objectStack->keys = newKeys; newKeys = NULL; } else { returnCode = 1; goto errorExit; }
if((newCFHashes = (CFHashCode *)realloc(objectStack->cfHashes, roundedUpNewCount * sizeof(CFHashCode))) != NULL) { objectStack->cfHashes = newCFHashes; newCFHashes = NULL; } else { returnCode = 1; goto errorExit; }
@@ -1288,13 +1288,13 @@ static int jk_objectStack_resize(JKObjectStack *objectStack, size_t newCount) {
#pragma mark -
#pragma mark Unicode related functions
-JK_STATIC_INLINE ConversionResult isValidCodePoint(UTF32 *u32CodePoint) {
+CDVJK_STATIC_INLINE ConversionResult isValidCodePoint(UTF32 *u32CodePoint) {
ConversionResult result = conversionOK;
UTF32 ch = *u32CodePoint;
- if(JK_EXPECT_F(ch >= UNI_SUR_HIGH_START) && (JK_EXPECT_T(ch <= UNI_SUR_LOW_END))) { result = sourceIllegal; ch = UNI_REPLACEMENT_CHAR; goto finished; }
- if(JK_EXPECT_F(ch >= 0xFDD0U) && (JK_EXPECT_F(ch <= 0xFDEFU) || JK_EXPECT_F((ch & 0xFFFEU) == 0xFFFEU)) && JK_EXPECT_T(ch <= 0x10FFFFU)) { result = sourceIllegal; ch = UNI_REPLACEMENT_CHAR; goto finished; }
- if(JK_EXPECT_F(ch == 0U)) { result = sourceIllegal; ch = UNI_REPLACEMENT_CHAR; goto finished; }
+ if(CDVJK_EXPECT_F(ch >= UNI_SUR_HIGH_START) && (CDVJK_EXPECT_T(ch <= UNI_SUR_LOW_END))) { result = sourceIllegal; ch = UNI_REPLACEMENT_CHAR; goto finished; }
+ if(CDVJK_EXPECT_F(ch >= 0xFDD0U) && (CDVJK_EXPECT_F(ch <= 0xFDEFU) || CDVJK_EXPECT_F((ch & 0xFFFEU) == 0xFFFEU)) && CDVJK_EXPECT_T(ch <= 0x10FFFFU)) { result = sourceIllegal; ch = UNI_REPLACEMENT_CHAR; goto finished; }
+ if(CDVJK_EXPECT_F(ch == 0U)) { result = sourceIllegal; ch = UNI_REPLACEMENT_CHAR; goto finished; }
finished:
*u32CodePoint = ch;
@@ -1308,22 +1308,22 @@ static int isLegalUTF8(const UTF8 *source, size_t length) {
switch(length) {
default: return(0); // Everything else falls through when "true"...
- case 4: if(JK_EXPECT_F(((a = (*--srcptr)) < 0x80) || (a > 0xBF))) { return(0); }
- case 3: if(JK_EXPECT_F(((a = (*--srcptr)) < 0x80) || (a > 0xBF))) { return(0); }
- case 2: if(JK_EXPECT_F( (a = (*--srcptr)) > 0xBF )) { return(0); }
+ case 4: if(CDVJK_EXPECT_F(((a = (*--srcptr)) < 0x80) || (a > 0xBF))) { return(0); }
+ case 3: if(CDVJK_EXPECT_F(((a = (*--srcptr)) < 0x80) || (a > 0xBF))) { return(0); }
+ case 2: if(CDVJK_EXPECT_F( (a = (*--srcptr)) > 0xBF )) { return(0); }
switch(*source) { // no fall-through in this inner switch
- case 0xE0: if(JK_EXPECT_F(a < 0xA0)) { return(0); } break;
- case 0xED: if(JK_EXPECT_F(a > 0x9F)) { return(0); } break;
- case 0xF0: if(JK_EXPECT_F(a < 0x90)) { return(0); } break;
- case 0xF4: if(JK_EXPECT_F(a > 0x8F)) { return(0); } break;
- default: if(JK_EXPECT_F(a < 0x80)) { return(0); }
+ case 0xE0: if(CDVJK_EXPECT_F(a < 0xA0)) { return(0); } break;
+ case 0xED: if(CDVJK_EXPECT_F(a > 0x9F)) { return(0); } break;
+ case 0xF0: if(CDVJK_EXPECT_F(a < 0x90)) { return(0); } break;
+ case 0xF4: if(CDVJK_EXPECT_F(a > 0x8F)) { return(0); } break;
+ default: if(CDVJK_EXPECT_F(a < 0x80)) { return(0); }
}
- case 1: if(JK_EXPECT_F((JK_EXPECT_T(*source < 0xC2)) && JK_EXPECT_F(*source >= 0x80))) { return(0); }
+ case 1: if(CDVJK_EXPECT_F((CDVJK_EXPECT_T(*source < 0xC2)) && CDVJK_EXPECT_F(*source >= 0x80))) { return(0); }
}
- if(JK_EXPECT_F(*source > 0xF4)) { return(0); }
+ if(CDVJK_EXPECT_F(*source > 0xF4)) { return(0); }
return(1);
}
@@ -1333,13 +1333,13 @@ static ConversionResult ConvertSingleCodePointInUTF8(const UTF8 *sourceStart, co
const UTF8 *source = sourceStart;
UTF32 ch = 0UL;
-#if !defined(JK_FAST_TRAILING_BYTES)
+#if !defined(CDVJK_FAST_TRAILING_BYTES)
unsigned short extraBytesToRead = trailingBytesForUTF8[*source];
#else
unsigned short extraBytesToRead = __builtin_clz(((*source)^0xff) << 25);
#endif
- if(JK_EXPECT_F((source + extraBytesToRead + 1) > sourceEnd) || JK_EXPECT_F(!isLegalUTF8(source, extraBytesToRead + 1))) {
+ if(CDVJK_EXPECT_F((source + extraBytesToRead + 1) > sourceEnd) || CDVJK_EXPECT_F(!isLegalUTF8(source, extraBytesToRead + 1))) {
source++;
while((source < sourceEnd) && (((*source) & 0xc0) == 0x80) && ((source - sourceStart) < (extraBytesToRead + 1))) { source++; }
NSCParameterAssert(source <= sourceEnd);
@@ -1401,7 +1401,7 @@ static ConversionResult ConvertUTF32toUTF8 (UTF32 u32CodePoint, UTF8 **targetSta
return(result);
}
-JK_STATIC_INLINE int jk_string_add_unicodeCodePoint(JKParseState *parseState, uint32_t unicodeCodePoint, size_t *tokenBufferIdx, JKHash *stringHash) {
+CDVJK_STATIC_INLINE int jk_string_add_unicodeCodePoint(CDVJKParseState *parseState, uint32_t unicodeCodePoint, size_t *tokenBufferIdx, CDVJKHash *stringHash) {
UTF8 *u8s = &parseState->token.tokenBuffer.bytes.ptr[*tokenBufferIdx];
ConversionResult result;
@@ -1417,48 +1417,48 @@ JK_STATIC_INLINE int jk_string_add_unicodeCodePoint(JKParseState *parseState, ui
#pragma mark -
#pragma mark Decoding / parsing / deserializing functions
-static int jk_parse_string(JKParseState *parseState) {
- NSCParameterAssert((parseState != NULL) && (JK_AT_STRING_PTR(parseState) <= JK_END_STRING_PTR(parseState)));
- const unsigned char *stringStart = JK_AT_STRING_PTR(parseState) + 1;
- const unsigned char *endOfBuffer = JK_END_STRING_PTR(parseState);
+static int jk_parse_string(CDVJKParseState *parseState) {
+ NSCParameterAssert((parseState != NULL) && (CDVJK_AT_STRING_PTR(parseState) <= CDVJK_END_STRING_PTR(parseState)));
+ const unsigned char *stringStart = CDVJK_AT_STRING_PTR(parseState) + 1;
+ const unsigned char *endOfBuffer = CDVJK_END_STRING_PTR(parseState);
const unsigned char *atStringCharacter = stringStart;
unsigned char *tokenBuffer = parseState->token.tokenBuffer.bytes.ptr;
size_t tokenStartIndex = parseState->atIndex;
size_t tokenBufferIdx = 0UL;
- int onlySimpleString = 1, stringState = JSONStringStateStart;
+ int onlySimpleString = 1, stringState = CDVJSONStringStateStart;
uint16_t escapedUnicode1 = 0U, escapedUnicode2 = 0U;
uint32_t escapedUnicodeCodePoint = 0U;
- JKHash stringHash = JK_HASH_INIT;
+ CDVJKHash stringHash = CDVJK_HASH_INIT;
while(1) {
unsigned long currentChar;
- if(JK_EXPECT_F(atStringCharacter == endOfBuffer)) { /* XXX Add error message */ stringState = JSONStringStateError; goto finishedParsing; }
+ if(CDVJK_EXPECT_F(atStringCharacter == endOfBuffer)) { /* XXX Add error message */ stringState = CDVJSONStringStateError; goto finishedParsing; }
- if(JK_EXPECT_F((currentChar = *atStringCharacter++) >= 0x80UL)) {
+ if(CDVJK_EXPECT_F((currentChar = *atStringCharacter++) >= 0x80UL)) {
const unsigned char *nextValidCharacter = NULL;
UTF32 u32ch = 0U;
ConversionResult result;
- if(JK_EXPECT_F((result = ConvertSingleCodePointInUTF8(atStringCharacter - 1, endOfBuffer, (UTF8 const **)&nextValidCharacter, &u32ch)) != conversionOK)) { goto switchToSlowPath; }
+ if(CDVJK_EXPECT_F((result = ConvertSingleCodePointInUTF8(atStringCharacter - 1, endOfBuffer, (UTF8 const **)&nextValidCharacter, &u32ch)) != conversionOK)) { goto switchToSlowPath; }
stringHash = calculateHash(stringHash, currentChar);
- while(atStringCharacter < nextValidCharacter) { NSCParameterAssert(JK_AT_STRING_PTR(parseState) <= JK_END_STRING_PTR(parseState)); stringHash = calculateHash(stringHash, *atStringCharacter++); }
+ while(atStringCharacter < nextValidCharacter) { NSCParameterAssert(CDVJK_AT_STRING_PTR(parseState) <= CDVJK_END_STRING_PTR(parseState)); stringHash = calculateHash(stringHash, *atStringCharacter++); }
continue;
} else {
- if(JK_EXPECT_F(currentChar == (unsigned long)'"')) { stringState = JSONStringStateFinished; goto finishedParsing; }
+ if(CDVJK_EXPECT_F(currentChar == (unsigned long)'"')) { stringState = CDVJSONStringStateFinished; goto finishedParsing; }
- if(JK_EXPECT_F(currentChar == (unsigned long)'\\')) {
+ if(CDVJK_EXPECT_F(currentChar == (unsigned long)'\\')) {
switchToSlowPath:
onlySimpleString = 0;
- stringState = JSONStringStateParsing;
+ stringState = CDVJSONStringStateParsing;
tokenBufferIdx = (atStringCharacter - stringStart) - 1L;
- if(JK_EXPECT_F((tokenBufferIdx + 16UL) > parseState->token.tokenBuffer.bytes.length)) { if((tokenBuffer = jk_managedBuffer_resize(&parseState->token.tokenBuffer, tokenBufferIdx + 1024UL)) == NULL) { jk_error(parseState, @"Internal error: Unable to resize temporary buffer. %@ line #%ld", [NSString stringWithUTF8String:__FILE__], (long)__LINE__); stringState = JSONStringStateError; goto finishedParsing; } }
+ if(CDVJK_EXPECT_F((tokenBufferIdx + 16UL)
<TRUNCATED>