Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: couchdeveloper/JPJson
base: b22db0314d
...
head fork: couchdeveloper/JPJson
compare: 12f238092e
Checking mergeability… Don't worry, you can still create the pull request.
  • 3 commits
  • 9 files changed
  • 0 commit comments
  • 1 contributor
View
2  Bench/Bench.xcodeproj/xcshareddata/xcschemes/Bench JPJsonParser.xcscheme
@@ -30,7 +30,7 @@
displayScale = "1.00"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
- buildConfiguration = "Release"
+ buildConfiguration = "Debug"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
allowLocationSimulation = "YES">
View
34 Bench/JPJsonParser/main.mm
@@ -992,7 +992,7 @@ int main (int argc, const char * argv[])
#if defined (DEBUG)
int N = 1;
#else
- int N = 1000;
+ int N = 10000;
#endif
@@ -1005,22 +1005,22 @@ int main (int argc, const char * argv[])
NSLog(@"Start Bench");
bench_JPJsonParser1a(JSON_TEST_FILE, N);
- bench_JPJsonParserString1(JSON_TEST_FILE,N);
- bench_JPJsonParser1a(JSON_TEST_FILE, N);
- bench_JPJsonParser1b(JSON_TEST_FILE, N);
- bench_JPJsonParser1x(JSON_TEST_FILE, N);
- bench_JPJsonParser1d(JSON_TEST_FILE, N);
- bench_JPJsonParser2(JSON_TEST_FILE, N);
- bench_JPAsyncJsonParser(JSON_TEST_FILE, N);
-#if defined (USE_JSONKit)
- bench_JSONKit1(JSON_TEST_FILE, N);
- bench_JSONKit2(JSON_TEST_FILE, N);
- bench_JSONKitString1(JSON_TEST_FILE, N);
-#endif
-#if 1
- bench_NSJSONSerialization1(JSON_TEST_FILE, N);
- bench_NSJSONSerialization2(JSON_TEST_FILE, N);
-#endif
+// bench_JPJsonParserString1(JSON_TEST_FILE,N);
+// bench_JPJsonParser1a(JSON_TEST_FILE, N);
+// bench_JPJsonParser1b(JSON_TEST_FILE, N);
+// bench_JPJsonParser1x(JSON_TEST_FILE, N);
+// bench_JPJsonParser1d(JSON_TEST_FILE, N);
+// bench_JPJsonParser2(JSON_TEST_FILE, N);
+// bench_JPAsyncJsonParser(JSON_TEST_FILE, N);
+//#if defined (USE_JSONKit)
+// bench_JSONKit1(JSON_TEST_FILE, N);
+// bench_JSONKit2(JSON_TEST_FILE, N);
+// bench_JSONKitString1(JSON_TEST_FILE, N);
+//#endif
+//#if 1
+// bench_NSJSONSerialization1(JSON_TEST_FILE, N);
+// bench_NSJSONSerialization2(JSON_TEST_FILE, N);
+//#endif
[pool drain];
return 0;
}
View
7 CHANGES.md
@@ -66,3 +66,10 @@
* JPJsonWriter: fixed a bug in converting NSNumber objects whose underlaying type equals BOOL and whose address is not equal `kCFBooleanTrue` or not equal `kCFBooleanFalse`.
+
+
+### Version 0.5 beta
+
+#### Bug fixes
+
+* Fixed a minor bug in Sample6, introduced due to an API change.
View
156 Examples/FoundationExamples/FoundationExamples.xcodeproj/project.pbxproj
@@ -15,6 +15,7 @@
A126814E145588A400131E77 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = A126814D145588A400131E77 /* main.m */; };
A12681581455892400131E77 /* JsonValidatorSemanticActions.m in Sources */ = {isa = PBXBuildFile; fileRef = A12681571455892400131E77 /* JsonValidatorSemanticActions.m */; };
A1314AE015530FA500CC4910 /* sample_json.json in CopyFiles */ = {isa = PBXBuildFile; fileRef = A1314ADE15530F7F00CC4910 /* sample_json.json */; };
+ A14C058F15BA80F0006E4790 /* JPJson.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A1977E41156B9A4B0074D9B2 /* JPJson.framework */; };
A15E63671456D4EC000F22F6 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A1F001371440A27E007A72A9 /* Foundation.framework */; };
A15E636A1456D4EC000F22F6 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = A15E63691456D4EC000F22F6 /* main.m */; };
A15E63781456D649000F22F6 /* JsonPathSemanticActions.mm in Sources */ = {isa = PBXBuildFile; fileRef = A15E63771456D649000F22F6 /* JsonPathSemanticActions.mm */; };
@@ -37,7 +38,6 @@
A1D4608E1582428C004D330F /* sample_json.json in CopyFiles */ = {isa = PBXBuildFile; fileRef = A1314ADE15530F7F00CC4910 /* sample_json.json */; };
A1D4608F1582428C004D330F /* Test-UTF8.json in CopyFiles */ = {isa = PBXBuildFile; fileRef = A1D4607F158241AF004D330F /* Test-UTF8.json */; };
A1D460901582428C004D330F /* Test-UTF8-esc.json in CopyFiles */ = {isa = PBXBuildFile; fileRef = A1D46081158241C8004D330F /* Test-UTF8-esc.json */; };
- A1D46093158244B7004D330F /* JPJson.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A1977E41156B9A4B0074D9B2 /* JPJson.framework */; };
A1D46094158244BE004D330F /* JPJson.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A1977E41156B9A4B0074D9B2 /* JPJson.framework */; };
A1D46096158244D3004D330F /* libjson.A.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = A1D46095158244D3004D330F /* libjson.A.dylib */; };
A1F0014B1440A2A0007A72A9 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A1F001371440A27E007A72A9 /* Foundation.framework */; };
@@ -141,7 +141,7 @@
A15E636C1456D4EC000F22F6 /* Sample10-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Sample10-Prefix.pch"; sourceTree = "<group>"; };
A15E63761456D649000F22F6 /* JsonPathSemanticActions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JsonPathSemanticActions.h; sourceTree = "<group>"; };
A15E63771456D649000F22F6 /* JsonPathSemanticActions.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = JsonPathSemanticActions.mm; sourceTree = "<group>"; };
- A177549415B6DF3200462E72 /* libjson.a */ = {isa = PBXFileReference; lastKnownFileType = file; name = libjson.a; path = "../../Libraries/Mac OS X Libraries/build/Release/libjson.a"; sourceTree = "<group>"; };
+ A177549415B6DF3200462E72 /* libjson.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libjson.a; path = "../../Libraries/Mac OS X Libraries/build/Release/libjson.a"; sourceTree = "<group>"; };
A17DD7AA146AE72E000AD974 /* libjson.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libjson.a; path = "../../../../../Library/Developer/Xcode/DerivedData/Json-hiazqngtzsfxawgakamtpamfsytx/Build/Products/Debug/libjson.a"; sourceTree = "<group>"; };
A1977E33156B86FE0074D9B2 /* Sample6 */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = Sample6; sourceTree = BUILT_PRODUCTS_DIR; };
A1977E37156B86FE0074D9B2 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
@@ -178,7 +178,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
- A1D46093158244B7004D330F /* JPJson.framework in Frameworks */,
+ A14C058F15BA80F0006E4790 /* JPJson.framework in Frameworks */,
A126813814557F4A00131E77 /* Foundation.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
@@ -640,6 +640,7 @@
isa = XCBuildConfiguration;
buildSettings = {
HEADER_SEARCH_PATHS = "\"$(BUILT_PRODUCTS_DIR)\"";
+ OTHER_CFLAGS = "-v";
OTHER_LDFLAGS = (
"-ObjC",
"-lstdc++",
@@ -652,6 +653,7 @@
isa = XCBuildConfiguration;
buildSettings = {
HEADER_SEARCH_PATHS = "\"$(BUILT_PRODUCTS_DIR)\"";
+ OTHER_CFLAGS = "-v";
OTHER_LDFLAGS = (
"-ObjC",
"-lstdc++",
@@ -665,7 +667,6 @@
buildSettings = {
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "Sample4/Sample4-Prefix.pch";
- HEADER_SEARCH_PATHS = "\"$(BUILT_PRODUCTS_DIR)\"";
OTHER_LDFLAGS = (
"-ObjC",
"-lstdc++",
@@ -679,7 +680,6 @@
buildSettings = {
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "Sample4/Sample4-Prefix.pch";
- HEADER_SEARCH_PATHS = "\"$(BUILT_PRODUCTS_DIR)\"";
OTHER_LDFLAGS = (
"-ObjC",
"-lstdc++",
@@ -716,6 +716,144 @@
};
name = Release;
};
+ A14C058615BA7ABD006E4790 /* Dist */ = {
+ isa = XCBuildConfiguration;
+ baseConfigurationReference = A1CFB9321510C8CA0010942D /* common.xcconfig */;
+ buildSettings = {
+ ALWAYS_SEARCH_USER_PATHS = NO;
+ ARCHS = "$(ARCHS_STANDARD_64_BIT)";
+ COPY_PHASE_STRIP = YES;
+ DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
+ GCC_C_LANGUAGE_STANDARD = gnu99;
+ GCC_ENABLE_OBJC_EXCEPTIONS = YES;
+ GCC_PREPROCESSOR_DEFINITIONS = (
+ NS_BLOCK_ASSERTIONS,
+ NDEBUG,
+ "__ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES=0",
+ );
+ GCC_PREPROCESSOR_DEFINITIONS_NOT_USED_IN_PRECOMPS = "";
+ GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
+ GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
+ GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES;
+ GCC_WARN_ABOUT_RETURN_TYPE = YES;
+ GCC_WARN_UNUSED_VARIABLE = YES;
+ MACOSX_DEPLOYMENT_TARGET = 10.7;
+ OTHER_LDFLAGS = "-lstdc++";
+ SDKROOT = macosx;
+ };
+ name = Dist;
+ };
+ A14C058715BA7ABD006E4790 /* Dist */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ FRAMEWORK_SEARCH_PATHS = "$(inherited)";
+ GCC_OPTIMIZATION_LEVEL = 3;
+ GCC_PRECOMPILE_PREFIX_HEADER = YES;
+ GCC_PREFIX_HEADER = "Sample1/Sample1-Prefix.pch";
+ HEADER_SEARCH_PATHS = "\"$(BUILT_PRODUCTS_DIR)\"";
+ LIBRARY_SEARCH_PATHS = "$(BUILT_PRODUCTS_DIR)";
+ OTHER_CFLAGS = "-v";
+ OTHER_LDFLAGS = (
+ "-lstdc++",
+ "-ObjC",
+ );
+ PRODUCT_NAME = "$(TARGET_NAME)";
+ };
+ name = Dist;
+ };
+ A14C058815BA7ABD006E4790 /* Dist */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ FRAMEWORK_SEARCH_PATHS = "$(inherited)";
+ GCC_OPTIMIZATION_LEVEL = 3;
+ GCC_PRECOMPILE_PREFIX_HEADER = YES;
+ GCC_PREFIX_HEADER = "Sample2/Sample2-Prefix.pch";
+ HEADER_SEARCH_PATHS = "\"$(BUILT_PRODUCTS_DIR)\"";
+ OTHER_LDFLAGS = (
+ "-lstdc++",
+ "-ObjC",
+ );
+ PRODUCT_NAME = "$(TARGET_NAME)";
+ };
+ name = Dist;
+ };
+ A14C058915BA7ABD006E4790 /* Dist */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ HEADER_SEARCH_PATHS = "\"$(BUILT_PRODUCTS_DIR)\"";
+ OTHER_CFLAGS = "-v";
+ OTHER_LDFLAGS = (
+ "-ObjC",
+ "-lstdc++",
+ );
+ PRODUCT_NAME = "$(TARGET_NAME)";
+ };
+ name = Dist;
+ };
+ A14C058A15BA7ABD006E4790 /* Dist */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ FRAMEWORK_SEARCH_PATHS = "$(SYMROOT)/Release";
+ GCC_PRECOMPILE_PREFIX_HEADER = YES;
+ GCC_PREFIX_HEADER = "Sample4/Sample4-Prefix.pch";
+ OTHER_LDFLAGS = (
+ "-ObjC",
+ "-lstdc++",
+ );
+ PRODUCT_NAME = "$(TARGET_NAME)";
+ };
+ name = Dist;
+ };
+ A14C058B15BA7ABD006E4790 /* Dist */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ GCC_PRECOMPILE_PREFIX_HEADER = YES;
+ GCC_PREFIX_HEADER = "Sample5/Sample5-Prefix.pch";
+ HEADER_SEARCH_PATHS = "\"$(BUILT_PRODUCTS_DIR)\"";
+ OTHER_LDFLAGS = (
+ "-ObjC",
+ "-lstdc++",
+ );
+ PRODUCT_NAME = "$(TARGET_NAME)";
+ };
+ name = Dist;
+ };
+ A14C058C15BA7ABD006E4790 /* Dist */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ CLANG_ENABLE_OBJC_ARC = YES;
+ CLANG_WARN_OBJCPP_ARC_ABI = YES;
+ GCC_PRECOMPILE_PREFIX_HEADER = YES;
+ GCC_PREFIX_HEADER = "Sample6/Sample6-Prefix.pch";
+ GCC_WARN_UNINITIALIZED_AUTOS = YES;
+ HEADER_SEARCH_PATHS = "\"$(BUILT_PRODUCTS_DIR)\"";
+ OTHER_LDFLAGS = (
+ "-lstdc++",
+ "-ObjC",
+ );
+ PRODUCT_NAME = "$(TARGET_NAME)";
+ };
+ name = Dist;
+ };
+ A14C058D15BA7ABD006E4790 /* Dist */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ FRAMEWORK_SEARCH_PATHS = "$(inherited)";
+ GCC_PRECOMPILE_PREFIX_HEADER = YES;
+ GCC_PREFIX_HEADER = "Sample10/Sample10-Prefix.pch";
+ HEADER_SEARCH_PATHS = (
+ "$(BUILT_PRODUCTS_DIR)",
+ "$(JP_ROOT)",
+ "$(BOOST_HEADER_SEARCH_PATHS)",
+ );
+ OTHER_LDFLAGS = (
+ "-ObjC",
+ "-lstdc++",
+ );
+ PRODUCT_NAME = "$(TARGET_NAME)";
+ };
+ name = Dist;
+ };
A15E636F1456D4EC000F22F6 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
@@ -923,6 +1061,7 @@
buildConfigurations = (
A126812314556BB500131E77 /* Debug */,
A126812414556BB500131E77 /* Release */,
+ A14C058915BA7ABD006E4790 /* Dist */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
@@ -932,6 +1071,7 @@
buildConfigurations = (
A126814114557F4A00131E77 /* Debug */,
A126814214557F4A00131E77 /* Release */,
+ A14C058A15BA7ABD006E4790 /* Dist */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
@@ -941,6 +1081,7 @@
buildConfigurations = (
A1268154145588A400131E77 /* Debug */,
A1268155145588A400131E77 /* Release */,
+ A14C058B15BA7ABD006E4790 /* Dist */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
@@ -950,6 +1091,7 @@
buildConfigurations = (
A15E636F1456D4EC000F22F6 /* Debug */,
A15E63701456D4EC000F22F6 /* Release */,
+ A14C058D15BA7ABD006E4790 /* Dist */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
@@ -959,6 +1101,7 @@
buildConfigurations = (
A1977E3D156B86FE0074D9B2 /* Debug */,
A1977E3E156B86FE0074D9B2 /* Release */,
+ A14C058C15BA7ABD006E4790 /* Dist */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
@@ -968,6 +1111,7 @@
buildConfigurations = (
A199EFE3144480D200B53269 /* Debug */,
A199EFE4144480D200B53269 /* Release */,
+ A14C058815BA7ABD006E4790 /* Dist */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
@@ -977,6 +1121,7 @@
buildConfigurations = (
A1F001401440A27E007A72A9 /* Debug */,
A1F001411440A27E007A72A9 /* Release */,
+ A14C058615BA7ABD006E4790 /* Dist */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
@@ -986,6 +1131,7 @@
buildConfigurations = (
A1F001541440A2A0007A72A9 /* Debug */,
A1F001551440A2A0007A72A9 /* Release */,
+ A14C058715BA7ABD006E4790 /* Dist */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
View
3  Examples/FoundationExamples/FoundationExamples.xcodeproj/xcshareddata/xcschemes/Sample3.xcscheme
@@ -44,9 +44,10 @@
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
- buildConfiguration = "Debug"
+ buildConfiguration = "Dist"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
+ enableOpenGLFrameCaptureMode = "0"
allowLocationSimulation = "YES">
<BuildableProductRunnable>
<BuildableReference
View
3  Examples/FoundationExamples/FoundationExamples.xcodeproj/xcshareddata/xcschemes/Sample4.xcscheme
@@ -44,9 +44,10 @@
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
- buildConfiguration = "Debug"
+ buildConfiguration = "Dist"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
+ enableOpenGLFrameCaptureMode = "0"
allowLocationSimulation = "YES">
<BuildableProductRunnable>
<BuildableReference
View
87 Examples/FoundationExamples/Sample6/main.m
@@ -6,7 +6,7 @@
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//
-#if !__has_feature(objc_arc)
+#if !__has_feature(objc_arc)
#error This Objective-C file shall be compiled with ARC enabled.
#endif
@@ -15,6 +15,8 @@
#import "JPJson/JPJsonWriter.h"
#import "JPJson/JPJsonWriterExtensions.h"
+#include <time.h>
+
// Objectives:
//
@@ -22,7 +24,7 @@
// Helper category for creating a RFC3339DateFormatter
-@implementation NSDateFormatter (RFC3339DateFormatter)
+@implementation NSDateFormatter (RFC3339DateFormatter)
+(NSDateFormatter*) rfc3339DateFormatter {
NSDateFormatter* rfc3339DateFormatter = [[NSDateFormatter alloc] init];
NSLocale* enUSPOSIXLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"];
@@ -44,24 +46,37 @@ +(NSDateFormatter*) rfc3339DateFormatter {
//
// A NSDate object may be serialized as a formatted date string. So, in order to
// make this work - we just ned to define a Category for NSDate and implement the
-// JPJsonSerializableProtocol.
+// JPJsonSerializableProtocol.
//
// Serializing a NSDate involves to convert the date into a string with an
// appropriate format. The format purposfully meets RFC 3339. Then we just serialize
-// the string using the JPJsonSerializableProtocol. The JPJsonSerializableProtocol
+// the string using the JPJsonSerializableProtocol. The JPJsonSerializableProtocol
// is already implemented for a NSString by the JPJson library.
//
@interface NSDate (JPJsonWriterExtension) <JPJsonSerializableProtocol>
@end
-@implementation NSDate (JPJsonWriterExtension)
-- (NSInteger) JPJson_serializeTo:(id<JPJsonStreambufferProtocol>) buffer
- encoding:(JPUnicodeEncoding)encoding
- options:(JPJsonWriterOptions)options
- level:(NSUInteger)level
+@implementation NSDate (JPJsonWriterExtension)
+- (int) JPJson_serializeTo:(id<JPJsonStreambufferProtocol>) buffer
+ encoding:(JPUnicodeEncoding)encoding
+ options:(JPJsonWriterOptions)options
+ level:(int)level
{
+#if 0 /* Using a NSDateFormatter */
NSDateFormatter* rfc3339DateFormatter = [NSDateFormatter rfc3339DateFormatter];
- id<JPJsonSerializableProtocol> dateString = (id<JPJsonSerializableProtocol>)[rfc3339DateFormatter stringFromDate:self];
- return [dateString JPJson_serializeTo:buffer encoding:encoding options:options level:level];
+ id<JPJsonSerializableProtocol> dateString = (id<JPJsonSerializableProtocol>)[rfc3339DateFormatter stringFromDate:self];
+ return [dateString JPJson_serializeTo:buffer encoding:encoding options:options level:level];
+#else
+ /* Use time utilities from ISO C (or POSIX, C99 UNIX Spec)*/
+ struct tm* timeinfo;
+ char buf[64];
+ time_t rawtime = [self timeIntervalSince1970];
+ timeinfo = gmtime(&rawtime);
+ size_t len = strftime(buf, sizeof(buf), "%FT%TZ", timeinfo);
+ CFStringRef cfDateString = CFStringCreateWithBytesNoCopy(NULL, (const UInt8 *)buf, len, kCFStringEncodingASCII, false, kCFAllocatorNull);
+ int result = [(__bridge id)cfDateString JPJson_serializeTo:buffer encoding:encoding options:options level:level];
+ CFRelease(cfDateString);
+ return result;
+#endif
}
@end
@@ -103,7 +118,7 @@ - (id) initWithFirstName:(NSString*)firstName lastName:(NSString*)lastName dayOf
- (void) addComment:(NSString*) comment
{
- if (comment == nil)
+ if (comment == nil)
return;
if (_comments == nil) {
@@ -125,12 +140,12 @@ - (void) addComment:(NSString*) comment
// For this purpose the implementation utilizes the JPJsonWriter class method
// `serializeObjectAsJSONObject:buffer:encoding:options:level:`, which in turn
// requires that the class Person implements the `NSFastEnumeration` protocol,
-// the JPJsonSerializableProtocol, and as well responds to message `count` and
+// the JPJsonSerializableProtocol, and as well responds to message `count` and
// message `objectForKey:`
//
@interface Person (JPJsonWriterExtension) <JPJsonSerializableProtocol, NSFastEnumeration>
@end
-@implementation Person (JPJsonWriterExtension)
+@implementation Person (JPJsonWriterExtension)
- (id) objectForKey:(id)aKey {
return [self valueForKey:aKey];
@@ -140,27 +155,27 @@ - (NSUInteger) count {
return 4; // return the number of properies
}
-- (NSUInteger) countByEnumeratingWithState:(NSFastEnumerationState *)state
- objects:(id __unsafe_unretained [])buffer
+- (NSUInteger) countByEnumeratingWithState:(NSFastEnumerationState *)state
+ objects:(id __unsafe_unretained [])buffer
count:(NSUInteger)len
{
static id __unsafe_unretained properties[] = {@"firstName", @"lastName", @"dayOfBirth", @"comments"};
if (state->state >= 4) {
return 0;
- }
+ }
state->itemsPtr = properties;
state->state = 4;
state->mutationsPtr = &state->extra[0];
return 4;
}
-- (NSInteger) JPJson_serializeTo:(id<JPJsonStreambufferProtocol>) buffer
- encoding:(JPUnicodeEncoding)encoding
- options:(JPJsonWriterOptions)options
- level:(NSUInteger)level
+- (int) JPJson_serializeTo:(id<JPJsonStreambufferProtocol>) buffer
+ encoding:(JPUnicodeEncoding)encoding
+ options:(JPJsonWriterOptions)options
+ level:(int)level
{
- return [JPJsonWriter serializeObjectAsJSONObject:self buffer:buffer encoding:encoding options:options level:level];
+ return [JPJsonWriter serializeObjectAsJSONObject:self buffer:buffer encoding:encoding options:options level:level];
}
@end
@@ -176,23 +191,25 @@ - (NSInteger) JPJson_serializeTo:(id<JPJsonStreambufferProtocol>) buffer
int main (int argc, const char * argv[])
{
@autoreleasepool {
-
+
+ // Date in local time zone
NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"]];
- [dateFormatter setDateFormat:@"yyyy'-'MM'-'dd"];
+ [dateFormatter setDateFormat:@"yyyy'-'MM'-'dd' 'HH:mm:ss"];
+ //[dateFormatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]];
// Create an array of Persons:
NSArray* json = [[NSArray alloc] initWithObjects:
- [[Person alloc] initWithFirstName:@"John"
- lastName:@"Appleseed"
- dayOfBirth:[dateFormatter dateFromString:@"1962-04-21"]],
- [[Person alloc] initWithFirstName:@"Pete"
- lastName:@"Pearson"
- dayOfBirth:[dateFormatter dateFromString:@"1912-10-12"]],
- [[Person alloc] initWithFirstName:@"Tab"
- lastName:@"Benoit"
- dayOfBirth:[dateFormatter dateFromString:@"1970-03-09"]],
- nil];
+ [[Person alloc] initWithFirstName:@"John"
+ lastName:@"Appleseed"
+ dayOfBirth:[dateFormatter dateFromString:@"1962-04-21 20:00:00"]],
+ [[Person alloc] initWithFirstName:@"Pete"
+ lastName:@"Pearson"
+ dayOfBirth:[dateFormatter dateFromString:@"1912-10-12 08:00:00"]],
+ [[Person alloc] initWithFirstName:@"Tab"
+ lastName:@"Benoit"
+ dayOfBirth:[dateFormatter dateFromString:@"1970-03-09 09:00:00"]],
+ nil];
Person* p0 = [json objectAtIndex:0];
[p0 addComment:@"This is a comment"];
@@ -223,7 +240,7 @@ int main (int argc, const char * argv[])
error:nil];
NSLog(@"%@:\n%@", filePath, s);
-#endif
+#endif
}
}
return 0;
View
36 Source/json/ObjC/JPJsonParser.mm
@@ -26,6 +26,7 @@
#include "json/unicode/unicode_traits.hpp"
#include "json/parser/parser_errors.hpp"
#include <dispatch/dispatch.h>
+#include <cstdlib>
#import "JPJsonParser.h"
#import "JPSemanticActionsBase.h"
#import "JPSemanticActionsBase_private.h"
@@ -304,22 +305,35 @@ + (id) parseString:(NSString*)string
// Try to get the string's content in UTF-16:
JPUnicodeEncoding encoding = JPUnicodeEncoding_Unknown;
- const void* bytes = string ? CFStringGetCharactersPtr(CFStringRef(string)) : NULL;
- size_t length = bytes ? [string length]*2 : 0; // length equals number of bytes
- if (not bytes and string) {
- bytes = CFStringGetCStringPtr(CFStringRef(string), kCFStringEncodingUTF8);
- if (not bytes) {
- // Performance may be suboptimal
- bytes = [string UTF8String];
+ bool doFreeBuffer = false;
+ const void* buffer = string ? CFStringGetCharactersPtr(CFStringRef(string)) : NULL;
+ size_t length = buffer ? CFStringGetLength(CFStringRef(string))*2 : 0; // length equals number of bytes
+ if (not buffer and string) {
+ // attempt to get the internal buffer in UTF-8:
+ buffer = CFStringGetCStringPtr(CFStringRef(string), kCFStringEncodingUTF8);
+ if (buffer) {
+ length = [string lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
+ encoding = JPUnicodeEncoding_UTF8;
+ } else {
+ // No Unicode: performance is suboptimal.
+ // Retrive the NSString's content as UTF-16 and store it into an allocated buffer:
+ // We strongly assume, the endianess is platform:
+ length = CFStringGetLength(CFStringRef(string))*2; // number of bytes
+ void* buf = malloc(length);
+ CFRange range = {0, length>>1};
+ CFStringGetCharacters(CFStringRef(string), range, (UniChar*)buf);
+ buffer = buf;
+ doFreeBuffer = true;
+ encoding = JPUnicodeEncoding_UTF16;
}
- length = [string lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
- encoding = JPUnicodeEncoding_UTF8;
}
-
- BOOL success = [JPJsonParser runWithBytes:bytes
+ BOOL success = [JPJsonParser runWithBytes:buffer
length:length
encoding:encoding
semanticActions:sa];
+ if (doFreeBuffer) {
+ free(const_cast<void*>(buffer));
+ }
id result = nil;
if (success) {
// result is owned by sa only - need to retain,autorelease it since we
View
2  Source/json/ObjC/JPJsonWriter.mm
@@ -1106,7 +1106,7 @@ @implementation NSString (JPJsonWriter)
- (int) JPJson_serializeTo:(id<JPJsonStreambufferProtocol>) streambuf
encoding:(JPUnicodeEncoding) encoding
options:(JPJsonWriterOptions) options
- level:(int) level;
+ level:(int) level
{
assert(encoding == JPUnicodeEncoding_UTF8);
assert(streambuf);

No commit comments for this range

Something went wrong with that request. Please try again.