From eeef857d364f89f893cab4a519704eed4605aff2 Mon Sep 17 00:00:00 2001 From: Pete Hodgson Date: Fri, 19 Oct 2012 18:43:55 -0700 Subject: [PATCH] replace SBJSON with AnyJSON --- .gitmodules | 3 + Frank.xcodeproj/project.pbxproj | 78 ++--- lib/AnyJSON | 1 + lib/JSON/Franks_SBJSON.h | 73 ----- lib/JSON/Franks_SBJSON.m | 212 ------------- lib/JSON/Franks_SBJsonBase.h | 89 ------ lib/JSON/Franks_SBJsonBase.m | 78 ----- lib/JSON/Franks_SBJsonParser.h | 87 ------ lib/JSON/Franks_SBJsonParser.m | 475 ------------------------------ lib/JSON/Franks_SBJsonWriter.h | 129 -------- lib/JSON/Franks_SBJsonWriter.m | 237 --------------- lib/JSON/JSON.h | 50 ---- lib/JSON/NSObject+Franks_SBJSON.h | 68 ----- lib/JSON/NSObject+Franks_SBJSON.m | 53 ---- lib/JSON/NSString+Franks_SBJSON.h | 58 ---- lib/JSON/NSString+Franks_SBJSON.m | 55 ---- src/AccessibilityCheckCommand.m | 3 +- src/AppCommand.m | 4 +- src/DumpCommand.m | 7 +- src/EnginesCommand.m | 3 +- src/FranklyProtocolHelper.m | 7 +- src/JSON.h | 18 ++ src/KeyboardCommand.m | 2 +- src/MapOperationCommand.m | 5 +- src/OrientationCommand.m | 4 +- 25 files changed, 57 insertions(+), 1742 deletions(-) create mode 160000 lib/AnyJSON delete mode 100644 lib/JSON/Franks_SBJSON.h delete mode 100644 lib/JSON/Franks_SBJSON.m delete mode 100644 lib/JSON/Franks_SBJsonBase.h delete mode 100644 lib/JSON/Franks_SBJsonBase.m delete mode 100644 lib/JSON/Franks_SBJsonParser.h delete mode 100644 lib/JSON/Franks_SBJsonParser.m delete mode 100644 lib/JSON/Franks_SBJsonWriter.h delete mode 100644 lib/JSON/Franks_SBJsonWriter.m delete mode 100644 lib/JSON/JSON.h delete mode 100644 lib/JSON/NSObject+Franks_SBJSON.h delete mode 100644 lib/JSON/NSObject+Franks_SBJSON.m delete mode 100644 lib/JSON/NSString+Franks_SBJSON.h delete mode 100644 lib/JSON/NSString+Franks_SBJSON.m create mode 100644 src/JSON.h diff --git a/.gitmodules b/.gitmodules index 4c72bc3..6ac43d2 100644 --- a/.gitmodules +++ b/.gitmodules @@ -13,3 +13,6 @@ [submodule "lib/PublicAutomation"] path = lib/PublicAutomation url = https://github.com/TestingWithFrank/PublicAutomation.git +[submodule "lib/AnyJSON"] + path = lib/AnyJSON + url = https://github.com/mattt/AnyJSON.git diff --git a/Frank.xcodeproj/project.pbxproj b/Frank.xcodeproj/project.pbxproj index a1c22e1..f7e9f78 100644 --- a/Frank.xcodeproj/project.pbxproj +++ b/Frank.xcodeproj/project.pbxproj @@ -51,6 +51,8 @@ ABA9E4C815C81E7A00112290 /* DDTTYLogger.m in Sources */ = {isa = PBXBuildFile; fileRef = ABA9E4C315C81E7A00112290 /* DDTTYLogger.m */; }; ABA9E4CD15C81E8700112290 /* ContextFilterLogFormatter.m in Sources */ = {isa = PBXBuildFile; fileRef = ABA9E4CA15C81E8700112290 /* ContextFilterLogFormatter.m */; }; ABA9E4CE15C81E8700112290 /* DispatchQueueLogFormatter.m in Sources */ = {isa = PBXBuildFile; fileRef = ABA9E4CC15C81E8700112290 /* DispatchQueueLogFormatter.m */; }; + C177A4CC1632319A0081DF77 /* AnyJSON.h in Headers */ = {isa = PBXBuildFile; fileRef = C177A4CA1632319A0081DF77 /* AnyJSON.h */; }; + C177A4CD1632319A0081DF77 /* AnyJSON.m in Sources */ = {isa = PBXBuildFile; fileRef = C177A4CB1632319A0081DF77 /* AnyJSON.m */; }; C18A5EF0160D4AB400DC25F6 /* ImageCaptureRoute.h in Headers */ = {isa = PBXBuildFile; fileRef = C18A5EEE160D4AB400DC25F6 /* ImageCaptureRoute.h */; }; C18A5EF1160D4AB400DC25F6 /* ImageCaptureRoute.m in Sources */ = {isa = PBXBuildFile; fileRef = C18A5EEF160D4AB400DC25F6 /* ImageCaptureRoute.m */; }; C18A5EF5160D4AD300DC25F6 /* UIView+ImageCapture.h in Headers */ = {isa = PBXBuildFile; fileRef = C18A5EF3160D4AD300DC25F6 /* UIView+ImageCapture.h */; }; @@ -88,23 +90,10 @@ D6D05CC211C883AA0081C5A5 /* StaticResourcesRoute.m in Sources */ = {isa = PBXBuildFile; fileRef = D6D05CB011C883AA0081C5A5 /* StaticResourcesRoute.m */; }; D6D79B5D11D7FB8B003E0E60 /* Operation.h in Headers */ = {isa = PBXBuildFile; fileRef = D6D79B5B11D7FB8B003E0E60 /* Operation.h */; }; D6D79B5E11D7FB8B003E0E60 /* Operation.m in Sources */ = {isa = PBXBuildFile; fileRef = D6D79B5C11D7FB8B003E0E60 /* Operation.m */; }; - D6E7B47A11B36D42005CAA34 /* JSON.h in Headers */ = {isa = PBXBuildFile; fileRef = D6E7B46D11B36D42005CAA34 /* JSON.h */; }; D6FA01B714283C4F00576AE1 /* FranklyProtocolHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = D6FA01B714283C4F00576AE0 /* FranklyProtocolHelper.m */; }; D6FA01B714283C4F00576AE3 /* FranklyProtocolHelper.h in Headers */ = {isa = PBXBuildFile; fileRef = D6FA01B714283C4F00576AE2 /* FranklyProtocolHelper.h */; }; D6FA01B714283C4F00576AEF /* EnginesCommand.m in Sources */ = {isa = PBXBuildFile; fileRef = D6FA01B714283C4F00576AEE /* EnginesCommand.m */; }; D6FA01B714283C4F00576AF1 /* EnginesCommand.h in Headers */ = {isa = PBXBuildFile; fileRef = D6FA01B714283C4F00576AF0 /* EnginesCommand.h */; }; - FC4EC7D815ED1C8B00B1F119 /* Franks_SBJsonBase.h in Headers */ = {isa = PBXBuildFile; fileRef = FC4EC7D615ED1C8B00B1F119 /* Franks_SBJsonBase.h */; }; - FC4EC7D915ED1C8B00B1F119 /* Franks_SBJsonBase.m in Sources */ = {isa = PBXBuildFile; fileRef = FC4EC7D715ED1C8B00B1F119 /* Franks_SBJsonBase.m */; }; - FC4EC7DC15ED1CC500B1F119 /* Franks_SBJsonParser.h in Headers */ = {isa = PBXBuildFile; fileRef = FC4EC7DA15ED1CC500B1F119 /* Franks_SBJsonParser.h */; }; - FC4EC7DD15ED1CC500B1F119 /* Franks_SBJsonParser.m in Sources */ = {isa = PBXBuildFile; fileRef = FC4EC7DB15ED1CC500B1F119 /* Franks_SBJsonParser.m */; }; - FC4EC7E015ED1CFB00B1F119 /* Franks_SBJsonWriter.h in Headers */ = {isa = PBXBuildFile; fileRef = FC4EC7DE15ED1CFB00B1F119 /* Franks_SBJsonWriter.h */; }; - FC4EC7E115ED1CFB00B1F119 /* Franks_SBJsonWriter.m in Sources */ = {isa = PBXBuildFile; fileRef = FC4EC7DF15ED1CFB00B1F119 /* Franks_SBJsonWriter.m */; }; - FC4EC7E415ED1D3400B1F119 /* Franks_SBJSON.h in Headers */ = {isa = PBXBuildFile; fileRef = FC4EC7E215ED1D3400B1F119 /* Franks_SBJSON.h */; }; - FC4EC7E515ED1D3400B1F119 /* Franks_SBJSON.m in Sources */ = {isa = PBXBuildFile; fileRef = FC4EC7E315ED1D3400B1F119 /* Franks_SBJSON.m */; }; - FC4EC7EA15ED1E0A00B1F119 /* NSObject+Franks_SBJSON.h in Headers */ = {isa = PBXBuildFile; fileRef = FC4EC7E615ED1E0A00B1F119 /* NSObject+Franks_SBJSON.h */; }; - FC4EC7EB15ED1E0A00B1F119 /* NSObject+Franks_SBJSON.m in Sources */ = {isa = PBXBuildFile; fileRef = FC4EC7E715ED1E0A00B1F119 /* NSObject+Franks_SBJSON.m */; }; - FC4EC7EC15ED1E0A00B1F119 /* NSString+Franks_SBJSON.h in Headers */ = {isa = PBXBuildFile; fileRef = FC4EC7E815ED1E0A00B1F119 /* NSString+Franks_SBJSON.h */; }; - FC4EC7ED15ED1E0A00B1F119 /* NSString+Franks_SBJSON.m in Sources */ = {isa = PBXBuildFile; fileRef = FC4EC7E915ED1E0A00B1F119 /* NSString+Franks_SBJSON.m */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -201,6 +190,9 @@ ABA9E4CA15C81E8700112290 /* ContextFilterLogFormatter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ContextFilterLogFormatter.m; sourceTree = ""; }; ABA9E4CB15C81E8700112290 /* DispatchQueueLogFormatter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DispatchQueueLogFormatter.h; sourceTree = ""; }; ABA9E4CC15C81E8700112290 /* DispatchQueueLogFormatter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DispatchQueueLogFormatter.m; sourceTree = ""; }; + C177A4CA1632319A0081DF77 /* AnyJSON.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AnyJSON.h; path = AnyJSON/AnyJSON.h; sourceTree = ""; }; + C177A4CB1632319A0081DF77 /* AnyJSON.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = AnyJSON.m; path = AnyJSON/AnyJSON.m; sourceTree = ""; }; + C177A4CE163234B60081DF77 /* JSON.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = JSON.h; sourceTree = ""; }; C18A5EEE160D4AB400DC25F6 /* ImageCaptureRoute.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ImageCaptureRoute.h; sourceTree = ""; }; C18A5EEF160D4AB400DC25F6 /* ImageCaptureRoute.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ImageCaptureRoute.m; sourceTree = ""; }; C18A5EF3160D4AD300DC25F6 /* UIView+ImageCapture.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIView+ImageCapture.h"; sourceTree = ""; }; @@ -239,23 +231,10 @@ D6D05CB011C883AA0081C5A5 /* StaticResourcesRoute.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = StaticResourcesRoute.m; sourceTree = ""; }; D6D79B5B11D7FB8B003E0E60 /* Operation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Operation.h; sourceTree = ""; }; D6D79B5C11D7FB8B003E0E60 /* Operation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Operation.m; sourceTree = ""; }; - D6E7B46D11B36D42005CAA34 /* JSON.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSON.h; sourceTree = ""; }; D6FA01B714283C4F00576AE0 /* FranklyProtocolHelper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FranklyProtocolHelper.m; sourceTree = ""; }; D6FA01B714283C4F00576AE2 /* FranklyProtocolHelper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FranklyProtocolHelper.h; sourceTree = ""; }; D6FA01B714283C4F00576AEE /* EnginesCommand.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = EnginesCommand.m; sourceTree = ""; }; D6FA01B714283C4F00576AF0 /* EnginesCommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EnginesCommand.h; sourceTree = ""; }; - FC4EC7D615ED1C8B00B1F119 /* Franks_SBJsonBase.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Franks_SBJsonBase.h; sourceTree = ""; }; - FC4EC7D715ED1C8B00B1F119 /* Franks_SBJsonBase.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Franks_SBJsonBase.m; sourceTree = ""; }; - FC4EC7DA15ED1CC500B1F119 /* Franks_SBJsonParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Franks_SBJsonParser.h; sourceTree = ""; }; - FC4EC7DB15ED1CC500B1F119 /* Franks_SBJsonParser.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Franks_SBJsonParser.m; sourceTree = ""; }; - FC4EC7DE15ED1CFB00B1F119 /* Franks_SBJsonWriter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Franks_SBJsonWriter.h; sourceTree = ""; }; - FC4EC7DF15ED1CFB00B1F119 /* Franks_SBJsonWriter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Franks_SBJsonWriter.m; sourceTree = ""; }; - FC4EC7E215ED1D3400B1F119 /* Franks_SBJSON.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Franks_SBJSON.h; sourceTree = ""; }; - FC4EC7E315ED1D3400B1F119 /* Franks_SBJSON.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Franks_SBJSON.m; sourceTree = ""; }; - FC4EC7E615ED1E0A00B1F119 /* NSObject+Franks_SBJSON.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSObject+Franks_SBJSON.h"; sourceTree = ""; }; - FC4EC7E715ED1E0A00B1F119 /* NSObject+Franks_SBJSON.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSObject+Franks_SBJSON.m"; sourceTree = ""; }; - FC4EC7E815ED1E0A00B1F119 /* NSString+Franks_SBJSON.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSString+Franks_SBJSON.h"; sourceTree = ""; }; - FC4EC7E915ED1E0A00B1F119 /* NSString+Franks_SBJSON.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSString+Franks_SBJSON.m"; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -426,6 +405,15 @@ name = Products; sourceTree = ""; }; + C177A4C9163231870081DF77 /* AnyJSON */ = { + isa = PBXGroup; + children = ( + C177A4CA1632319A0081DF77 /* AnyJSON.h */, + C177A4CB1632319A0081DF77 /* AnyJSON.m */, + ); + name = AnyJSON; + sourceTree = ""; + }; C9605E6F1606C42200170F88 /* Commands */ = { isa = PBXGroup; children = ( @@ -504,6 +492,7 @@ C9605E661606BF8E00170F88 /* UIView+MapKitWorkaround.m */, C18A5F1D160D547A00DC25F6 /* UIView+PublicAutomation.m */, 00E864BA161D6E6400E01209 /* UIScrollView+FrankScrolling.m */, + C177A4CE163234B60081DF77 /* JSON.h */, ); name = Additions; sourceTree = ""; @@ -511,8 +500,8 @@ D629926711AB2CF700CE0FB0 /* lib */ = { isa = PBXGroup; children = ( + C177A4C9163231870081DF77 /* AnyJSON */, C18A5F16160D528C00DC25F6 /* PublicAutomation.xcodeproj */, - D6E7B46C11B36D42005CAA34 /* JSON */, D629926811AB2D0500CE0FB0 /* cocoahttpserver */, D67F2B3313F5F82700A0BFF1 /* LoadableCategory.h */, ); @@ -542,26 +531,6 @@ path = cocoahttpserver; sourceTree = ""; }; - D6E7B46C11B36D42005CAA34 /* JSON */ = { - isa = PBXGroup; - children = ( - FC4EC7E615ED1E0A00B1F119 /* NSObject+Franks_SBJSON.h */, - FC4EC7E715ED1E0A00B1F119 /* NSObject+Franks_SBJSON.m */, - FC4EC7E815ED1E0A00B1F119 /* NSString+Franks_SBJSON.h */, - FC4EC7E915ED1E0A00B1F119 /* NSString+Franks_SBJSON.m */, - FC4EC7E215ED1D3400B1F119 /* Franks_SBJSON.h */, - FC4EC7E315ED1D3400B1F119 /* Franks_SBJSON.m */, - FC4EC7DE15ED1CFB00B1F119 /* Franks_SBJsonWriter.h */, - FC4EC7DF15ED1CFB00B1F119 /* Franks_SBJsonWriter.m */, - FC4EC7DA15ED1CC500B1F119 /* Franks_SBJsonParser.h */, - FC4EC7DB15ED1CC500B1F119 /* Franks_SBJsonParser.m */, - FC4EC7D615ED1C8B00B1F119 /* Franks_SBJsonBase.h */, - FC4EC7D715ED1C8B00B1F119 /* Franks_SBJsonBase.m */, - D6E7B46D11B36D42005CAA34 /* JSON.h */, - ); - path = JSON; - sourceTree = ""; - }; /* End PBXGroup section */ /* Begin PBXHeadersBuildPhase section */ @@ -571,7 +540,6 @@ files = ( D6BD521E146C34BF001770B1 /* SelectorEngineRegistry.h in Headers */, AA747D9F0F9514B9006C5449 /* Frank_Prefix.pch in Headers */, - D6E7B47A11B36D42005CAA34 /* JSON.h in Headers */, D6D05CB311C883AA0081C5A5 /* DumpCommand.h in Headers */, D6D05CB511C883AA0081C5A5 /* FrankCommandRoute.h in Headers */, D6D05CB711C883AA0081C5A5 /* FrankServer.h in Headers */, @@ -596,16 +564,11 @@ AB7947BB15C4412300052B74 /* WebSocket.h in Headers */, D6FA01B714283C4F00576AF1 /* EnginesCommand.h in Headers */, A91F3AA615F6E456003F434F /* ExitCommand.h in Headers */, - FC4EC7D815ED1C8B00B1F119 /* Franks_SBJsonBase.h in Headers */, - FC4EC7DC15ED1CC500B1F119 /* Franks_SBJsonParser.h in Headers */, - FC4EC7E015ED1CFB00B1F119 /* Franks_SBJsonWriter.h in Headers */, - FC4EC7E415ED1D3400B1F119 /* Franks_SBJSON.h in Headers */, - FC4EC7EA15ED1E0A00B1F119 /* NSObject+Franks_SBJSON.h in Headers */, - FC4EC7EC15ED1E0A00B1F119 /* NSString+Franks_SBJSON.h in Headers */, C9605E641606BF2900170F88 /* KeyboardCommand.h in Headers */, C9605E6A1606BFAE00170F88 /* UIImage+Frank.h in Headers */, C18A5EF0160D4AB400DC25F6 /* ImageCaptureRoute.h in Headers */, C18A5EF5160D4AD300DC25F6 /* UIView+ImageCapture.h in Headers */, + C177A4CC1632319A0081DF77 /* AnyJSON.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -759,12 +722,6 @@ D6A1D28015A8D05E00EC056C /* UIView+Frank.m in Sources */, D6FA01B714283C4F00576AEF /* EnginesCommand.m in Sources */, A91F3AA715F6E456003F434F /* ExitCommand.m in Sources */, - FC4EC7D915ED1C8B00B1F119 /* Franks_SBJsonBase.m in Sources */, - FC4EC7DD15ED1CC500B1F119 /* Franks_SBJsonParser.m in Sources */, - FC4EC7E115ED1CFB00B1F119 /* Franks_SBJsonWriter.m in Sources */, - FC4EC7E515ED1D3400B1F119 /* Franks_SBJSON.m in Sources */, - FC4EC7EB15ED1E0A00B1F119 /* NSObject+Franks_SBJSON.m in Sources */, - FC4EC7ED15ED1E0A00B1F119 /* NSString+Franks_SBJSON.m in Sources */, C9605E651606BF2900170F88 /* KeyboardCommand.m in Sources */, C9605E671606BF8E00170F88 /* UIView+MapKitWorkaround.m in Sources */, C9605E6B1606BFAE00170F88 /* UIImage+Frank.m in Sources */, @@ -772,6 +729,7 @@ C18A5EF6160D4AD300DC25F6 /* UIView+ImageCapture.m in Sources */, C18A5F1E160D547A00DC25F6 /* UIView+PublicAutomation.m in Sources */, 00E864BC161D6E6400E01209 /* UIScrollView+FrankScrolling.m in Sources */, + C177A4CD1632319A0081DF77 /* AnyJSON.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/lib/AnyJSON b/lib/AnyJSON new file mode 160000 index 0000000..ef21ea4 --- /dev/null +++ b/lib/AnyJSON @@ -0,0 +1 @@ +Subproject commit ef21ea49dc7adc124f088a7a113f46299f4aad08 diff --git a/lib/JSON/Franks_SBJSON.h b/lib/JSON/Franks_SBJSON.h deleted file mode 100644 index 3af0f59..0000000 --- a/lib/JSON/Franks_SBJSON.h +++ /dev/null @@ -1,73 +0,0 @@ -/* - Copyright (C) 2007-2009 Stig Brautaset. All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - * Neither the name of the author nor the names of its contributors may be used - to endorse or promote products derived from this software without specific - prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE - FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#import -#import "Franks_SBJsonParser.h" -#import "Franks_SBJsonWriter.h" - -/** - @brief Facade for Franks_SBJsonWriter/Franks_SBJsonParser. - - Requests are forwarded to instances of Franks_SBJsonWriter and Franks_SBJsonParser. - */ -@interface Franks_SBJSON : Franks_SBJsonBase { - -@private - Franks_SBJsonParser *jsonParser; - Franks_SBJsonWriter *jsonWriter; -} - - -/// Return the fragment represented by the given string -- (id)fragmentWithString:(NSString*)jsonrep - error:(NSError**)error; - -/// Return the object represented by the given string -- (id)objectWithString:(NSString*)jsonrep - error:(NSError**)error; - -/// Parse the string and return the represented object (or scalar) -- (id)objectWithString:(id)value - allowScalar:(BOOL)x - error:(NSError**)error; - - -/// Return JSON representation of an array or dictionary -- (NSString*)stringWithObject:(id)value - error:(NSError**)error; - -/// Return JSON representation of any legal JSON value -- (NSString*)stringWithFragment:(id)value - error:(NSError**)error; - -/// Return JSON representation (or fragment) for the given object -- (NSString*)stringWithObject:(id)value - allowScalar:(BOOL)x - error:(NSError**)error; -@end diff --git a/lib/JSON/Franks_SBJSON.m b/lib/JSON/Franks_SBJSON.m deleted file mode 100644 index 8a2e514..0000000 --- a/lib/JSON/Franks_SBJSON.m +++ /dev/null @@ -1,212 +0,0 @@ -/* - Copyright (C) 2007-2009 Stig Brautaset. All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - * Neither the name of the author nor the names of its contributors may be used - to endorse or promote products derived from this software without specific - prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE - FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#import "Franks_SBJSON.h" - -@implementation Franks_SBJSON - -- (id)init { - self = [super init]; - if (self) { - jsonWriter = [Franks_SBJsonWriter new]; - jsonParser = [Franks_SBJsonParser new]; - [self setMaxDepth:512]; - - } - return self; -} - -- (void)dealloc { - [jsonWriter release]; - [jsonParser release]; - [super dealloc]; -} - -#pragma mark Writer - - -- (NSString *)stringWithObject:(id)obj { - NSString *repr = [jsonWriter stringWithObject:obj]; - if (repr) - return repr; - - [errorTrace release]; - errorTrace = [[jsonWriter errorTrace] mutableCopy]; - return nil; -} - -/** - Returns a string containing JSON representation of the passed in value, or nil on error. - If nil is returned and @p error is not NULL, @p *error can be interrogated to find the cause of the error. - - @param value any instance that can be represented as a JSON fragment - @param allowScalar wether to return json fragments for scalar objects - @param error used to return an error by reference (pass NULL if this is not desired) - -@deprecated Given we bill ourselves as a "strict" JSON library, this method should be removed. - */ -- (NSString*)stringWithObject:(id)value allowScalar:(BOOL)allowScalar error:(NSError**)error { - - NSString *json = allowScalar ? [jsonWriter stringWithFragment:value] : [jsonWriter stringWithObject:value]; - if (json) - return json; - - [errorTrace release]; - errorTrace = [[jsonWriter errorTrace] mutableCopy]; - - if (error) - *error = [errorTrace lastObject]; - return nil; -} - -/** - Returns a string containing JSON representation of the passed in value, or nil on error. - If nil is returned and @p error is not NULL, @p error can be interrogated to find the cause of the error. - - @param value any instance that can be represented as a JSON fragment - @param error used to return an error by reference (pass NULL if this is not desired) - - @deprecated Given we bill ourselves as a "strict" JSON library, this method should be removed. - */ -- (NSString*)stringWithFragment:(id)value error:(NSError**)error { - return [self stringWithObject:value - allowScalar:YES - error:error]; -} - -/** - Returns a string containing JSON representation of the passed in value, or nil on error. - If nil is returned and @p error is not NULL, @p error can be interrogated to find the cause of the error. - - @param value a NSDictionary or NSArray instance - @param error used to return an error by reference (pass NULL if this is not desired) - */ -- (NSString*)stringWithObject:(id)value error:(NSError**)error { - return [self stringWithObject:value - allowScalar:NO - error:error]; -} - -#pragma mark Parsing - -- (id)objectWithString:(NSString *)repr { - id obj = [jsonParser objectWithString:repr]; - if (obj) - return obj; - - [errorTrace release]; - errorTrace = [[jsonParser errorTrace] mutableCopy]; - - return nil; -} - -/** - Returns the object represented by the passed-in string or nil on error. The returned object can be - a string, number, boolean, null, array or dictionary. - - @param value the json string to parse - @param allowScalar whether to return objects for JSON fragments - @param error used to return an error by reference (pass NULL if this is not desired) - - @deprecated Given we bill ourselves as a "strict" JSON library, this method should be removed. - */ -- (id)objectWithString:(id)value allowScalar:(BOOL)allowScalar error:(NSError**)error { - - id obj = allowScalar ? [jsonParser fragmentWithString:value] : [jsonParser objectWithString:value]; - if (obj) - return obj; - - [errorTrace release]; - errorTrace = [[jsonParser errorTrace] mutableCopy]; - - if (error) - *error = [errorTrace lastObject]; - return nil; -} - -/** - Returns the object represented by the passed-in string or nil on error. The returned object can be - a string, number, boolean, null, array or dictionary. - - @param repr the json string to parse - @param error used to return an error by reference (pass NULL if this is not desired) - - @deprecated Given we bill ourselves as a "strict" JSON library, this method should be removed. - */ -- (id)fragmentWithString:(NSString*)repr error:(NSError**)error { - return [self objectWithString:repr - allowScalar:YES - error:error]; -} - -/** - Returns the object represented by the passed-in string or nil on error. The returned object - will be either a dictionary or an array. - - @param repr the json string to parse - @param error used to return an error by reference (pass NULL if this is not desired) - */ -- (id)objectWithString:(NSString*)repr error:(NSError**)error { - return [self objectWithString:repr - allowScalar:NO - error:error]; -} - - - -#pragma mark Properties - parsing - -- (NSUInteger)maxDepth { - return jsonParser.maxDepth; -} - -- (void)setMaxDepth:(NSUInteger)d { - jsonWriter.maxDepth = jsonParser.maxDepth = d; -} - - -#pragma mark Properties - writing - -- (BOOL)humanReadable { - return jsonWriter.humanReadable; -} - -- (void)setHumanReadable:(BOOL)x { - jsonWriter.humanReadable = x; -} - -- (BOOL)sortKeys { - return jsonWriter.sortKeys; -} - -- (void)setSortKeys:(BOOL)x { - jsonWriter.sortKeys = x; -} - -@end diff --git a/lib/JSON/Franks_SBJsonBase.h b/lib/JSON/Franks_SBJsonBase.h deleted file mode 100644 index bad8910..0000000 --- a/lib/JSON/Franks_SBJsonBase.h +++ /dev/null @@ -1,89 +0,0 @@ -/* - Copyright (C) 2009 Stig Brautaset. All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - * Neither the name of the author nor the names of its contributors may be used - to endorse or promote products derived from this software without specific - prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE - FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#import - -#define SBJSONErrorDomain Franks_SBJSONErrorDomain - -extern NSString * SBJSONErrorDomain; - - -enum { - EUNSUPPORTED = 1, - EPARSENUM, - EPARSE, - EFRAGMENT, - ECTRL, - EUNICODE, - EDEPTH, - EESCAPE, - ETRAILCOMMA, - ETRAILGARBAGE, - EEOF, - EINPUT -}; - - -/** - @brief Common base class for parsing & writing. - - This class contains the common error-handling code and option between the parser/writer. - */ -@interface Franks_SBJsonBase : NSObject { - NSMutableArray *errorTrace; - -@protected - NSUInteger depth, maxDepth; -} - -/** - @brief The maximum recursing depth. - - Defaults to 512. If the input is nested deeper than this the input will be deemed to be - malicious and the parser returns nil, signalling an error. ("Nested too deep".) You can - turn off this security feature by setting the maxDepth value to 0. - */ -@property NSUInteger maxDepth; - -/** - @brief Return an error trace, or nil if there was no errors. - - Note that this method returns the trace of the last method that failed. - You need to check the return value of the call you're making to figure out - if the call actually failed, before you know call this method. - */ - @property(copy,readonly) NSArray* errorTrace; - -/// @internal for use in subclasses to add errors to the stack trace -- (void)addErrorWithCode:(NSUInteger)code description:(NSString*)str; - -/// @internal for use in subclasess to clear the error before a new parsing attempt -- (void)clearErrorTrace; - -@end \ No newline at end of file diff --git a/lib/JSON/Franks_SBJsonBase.m b/lib/JSON/Franks_SBJsonBase.m deleted file mode 100644 index a276742..0000000 --- a/lib/JSON/Franks_SBJsonBase.m +++ /dev/null @@ -1,78 +0,0 @@ -/* - Copyright (C) 2009 Stig Brautaset. All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - * Neither the name of the author nor the names of its contributors may be used - to endorse or promote products derived from this software without specific - prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE - FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#import "Franks_SBJsonBase.h" -NSString * SBJSONErrorDomain = @"org.brautaset.JSON.ErrorDomain"; - - -@implementation Franks_SBJsonBase - -@synthesize errorTrace; -@synthesize maxDepth; - -- (id)init { - self = [super init]; - if (self) - self.maxDepth = 512; - return self; -} - -- (void)dealloc { - [errorTrace release]; - [super dealloc]; -} - -- (void)addErrorWithCode:(NSUInteger)code description:(NSString*)str { - NSDictionary *userInfo; - if (!errorTrace) { - errorTrace = [NSMutableArray new]; - userInfo = [NSDictionary dictionaryWithObject:str forKey:NSLocalizedDescriptionKey]; - - } else { - userInfo = [NSDictionary dictionaryWithObjectsAndKeys: - str, NSLocalizedDescriptionKey, - [errorTrace lastObject], NSUnderlyingErrorKey, - nil]; - } - - NSError *error = [NSError errorWithDomain:SBJSONErrorDomain code:code userInfo:userInfo]; - - [self willChangeValueForKey:@"errorTrace"]; - [errorTrace addObject:error]; - [self didChangeValueForKey:@"errorTrace"]; -} - -- (void)clearErrorTrace { - [self willChangeValueForKey:@"errorTrace"]; - [errorTrace release]; - errorTrace = nil; - [self didChangeValueForKey:@"errorTrace"]; -} - -@end diff --git a/lib/JSON/Franks_SBJsonParser.h b/lib/JSON/Franks_SBJsonParser.h deleted file mode 100644 index a7944ad..0000000 --- a/lib/JSON/Franks_SBJsonParser.h +++ /dev/null @@ -1,87 +0,0 @@ -/* - Copyright (C) 2009 Stig Brautaset. All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - * Neither the name of the author nor the names of its contributors may be used - to endorse or promote products derived from this software without specific - prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE - FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#import -#import "Franks_SBJsonBase.h" - -/** - @brief Options for the parser class. - - This exists so the SBJSON facade can implement the options in the parser without having to re-declare them. - */ -@protocol Franks_SBJsonParser - -/** - @brief Return the object represented by the given string. - - Returns the object represented by the passed-in string or nil on error. The returned object can be - a string, number, boolean, null, array or dictionary. - - @param repr the json string to parse - */ -- (id)objectWithString:(NSString *)repr; - -@end - - -/** - @brief The JSON parser class. - - JSON is mapped to Objective-C types in the following way: - - @li Null -> NSNull - @li String -> NSMutableString - @li Array -> NSMutableArray - @li Object -> NSMutableDictionary - @li Boolean -> NSNumber (initialised with -initWithBool:) - @li Number -> NSDecimalNumber - - Since Objective-C doesn't have a dedicated class for boolean values, these turns into NSNumber - instances. These are initialised with the -initWithBool: method, and - round-trip back to JSON properly. (They won't silently suddenly become 0 or 1; they'll be - represented as 'true' and 'false' again.) - - JSON numbers turn into NSDecimalNumber instances, - as we can thus avoid any loss of precision. (JSON allows ridiculously large numbers.) - - */ -@interface Franks_SBJsonParser : Franks_SBJsonBase { - -@private - const char *c; -} - -@end - -// don't use - exists for backwards compatibility with 2.1.x only. Will be removed in 2.3. -@interface Franks_SBJsonParser (Private) -- (id)fragmentWithString:(id)repr; -@end - - diff --git a/lib/JSON/Franks_SBJsonParser.m b/lib/JSON/Franks_SBJsonParser.m deleted file mode 100644 index cb6b326..0000000 --- a/lib/JSON/Franks_SBJsonParser.m +++ /dev/null @@ -1,475 +0,0 @@ -/* - Copyright (C) 2009 Stig Brautaset. All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - * Neither the name of the author nor the names of its contributors may be used - to endorse or promote products derived from this software without specific - prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE - FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#import "Franks_SBJsonParser.h" - -@interface Franks_SBJsonParser () - -- (BOOL)scanValue:(NSObject **)o; - -- (BOOL)scanRestOfArray:(NSMutableArray **)o; -- (BOOL)scanRestOfDictionary:(NSMutableDictionary **)o; -- (BOOL)scanRestOfNull:(NSNull **)o; -- (BOOL)scanRestOfFalse:(NSNumber **)o; -- (BOOL)scanRestOfTrue:(NSNumber **)o; -- (BOOL)scanRestOfString:(NSMutableString **)o; - -// Cannot manage without looking at the first digit -- (BOOL)scanNumber:(NSNumber **)o; - -- (BOOL)scanHexQuad:(unichar *)x; -- (BOOL)scanUnicodeChar:(unichar *)x; - -- (BOOL)scanIsAtEnd; - -@end - -#define skipWhitespace(c) while (isspace(*c)) c++ -#define skipDigits(c) while (isdigit(*c)) c++ - - -@implementation Franks_SBJsonParser - -static char ctrl[0x22]; - - -+ (void)initialize { - ctrl[0] = '\"'; - ctrl[1] = '\\'; - for (int i = 1; i < 0x20; i++) - ctrl[i+1] = i; - ctrl[0x21] = 0; -} - -/** - @deprecated This exists in order to provide fragment support in older APIs in one more version. - It should be removed in the next major version. - */ -- (id)fragmentWithString:(id)repr { - [self clearErrorTrace]; - - if (!repr) { - [self addErrorWithCode:EINPUT description:@"Input was 'nil'"]; - return nil; - } - - depth = 0; - c = [repr UTF8String]; - - id o; - if (![self scanValue:&o]) { - return nil; - } - - // We found some valid JSON. But did it also contain something else? - if (![self scanIsAtEnd]) { - [self addErrorWithCode:ETRAILGARBAGE description:@"Garbage after JSON"]; - return nil; - } - - NSAssert1(o, @"Should have a valid object from %@", repr); - return o; -} - -- (id)objectWithString:(NSString *)repr { - - id o = [self fragmentWithString:repr]; - if (!o) - return nil; - - // Check that the object we've found is a valid JSON container. - if (![o isKindOfClass:[NSDictionary class]] && ![o isKindOfClass:[NSArray class]]) { - [self addErrorWithCode:EFRAGMENT description:@"Valid fragment, but not JSON"]; - return nil; - } - - return o; -} - -/* - In contrast to the public methods, it is an error to omit the error parameter here. - */ -- (BOOL)scanValue:(NSObject **)o -{ - skipWhitespace(c); - - switch (*c++) { - case '{': - return [self scanRestOfDictionary:(NSMutableDictionary **)o]; - break; - case '[': - return [self scanRestOfArray:(NSMutableArray **)o]; - break; - case '"': - return [self scanRestOfString:(NSMutableString **)o]; - break; - case 'f': - return [self scanRestOfFalse:(NSNumber **)o]; - break; - case 't': - return [self scanRestOfTrue:(NSNumber **)o]; - break; - case 'n': - return [self scanRestOfNull:(NSNull **)o]; - break; - case '-': - case '0'...'9': - c--; // cannot verify number correctly without the first character - return [self scanNumber:(NSNumber **)o]; - break; - case '+': - [self addErrorWithCode:EPARSENUM description: @"Leading + disallowed in number"]; - return NO; - break; - case 0x0: - [self addErrorWithCode:EEOF description:@"Unexpected end of string"]; - return NO; - break; - default: - [self addErrorWithCode:EPARSE description: @"Unrecognised leading character"]; - return NO; - break; - } - - NSAssert(0, @"Should never get here"); - return NO; -} - -- (BOOL)scanRestOfTrue:(NSNumber **)o -{ - if (!strncmp(c, "rue", 3)) { - c += 3; - *o = [NSNumber numberWithBool:YES]; - return YES; - } - [self addErrorWithCode:EPARSE description:@"Expected 'true'"]; - return NO; -} - -- (BOOL)scanRestOfFalse:(NSNumber **)o -{ - if (!strncmp(c, "alse", 4)) { - c += 4; - *o = [NSNumber numberWithBool:NO]; - return YES; - } - [self addErrorWithCode:EPARSE description: @"Expected 'false'"]; - return NO; -} - -- (BOOL)scanRestOfNull:(NSNull **)o { - if (!strncmp(c, "ull", 3)) { - c += 3; - *o = [NSNull null]; - return YES; - } - [self addErrorWithCode:EPARSE description: @"Expected 'null'"]; - return NO; -} - -- (BOOL)scanRestOfArray:(NSMutableArray **)o { - if (maxDepth && ++depth > maxDepth) { - [self addErrorWithCode:EDEPTH description: @"Nested too deep"]; - return NO; - } - - *o = [NSMutableArray arrayWithCapacity:8]; - - for (; *c ;) { - id v; - - skipWhitespace(c); - if (*c == ']' && c++) { - depth--; - return YES; - } - - if (![self scanValue:&v]) { - [self addErrorWithCode:EPARSE description:@"Expected value while parsing array"]; - return NO; - } - - [*o addObject:v]; - - skipWhitespace(c); - if (*c == ',' && c++) { - skipWhitespace(c); - if (*c == ']') { - [self addErrorWithCode:ETRAILCOMMA description: @"Trailing comma disallowed in array"]; - return NO; - } - } - } - - [self addErrorWithCode:EEOF description: @"End of input while parsing array"]; - return NO; -} - -- (BOOL)scanRestOfDictionary:(NSMutableDictionary **)o -{ - if (maxDepth && ++depth > maxDepth) { - [self addErrorWithCode:EDEPTH description: @"Nested too deep"]; - return NO; - } - - *o = [NSMutableDictionary dictionaryWithCapacity:7]; - - for (; *c ;) { - id k, v; - - skipWhitespace(c); - if (*c == '}' && c++) { - depth--; - return YES; - } - - if (!(*c == '\"' && c++ && [self scanRestOfString:&k])) { - [self addErrorWithCode:EPARSE description: @"Object key string expected"]; - return NO; - } - - skipWhitespace(c); - if (*c != ':') { - [self addErrorWithCode:EPARSE description: @"Expected ':' separating key and value"]; - return NO; - } - - c++; - if (![self scanValue:&v]) { - NSString *string = [NSString stringWithFormat:@"Object value expected for key: %@", k]; - [self addErrorWithCode:EPARSE description: string]; - return NO; - } - - [*o setObject:v forKey:k]; - - skipWhitespace(c); - if (*c == ',' && c++) { - skipWhitespace(c); - if (*c == '}') { - [self addErrorWithCode:ETRAILCOMMA description: @"Trailing comma disallowed in object"]; - return NO; - } - } - } - - [self addErrorWithCode:EEOF description: @"End of input while parsing object"]; - return NO; -} - -- (BOOL)scanRestOfString:(NSMutableString **)o -{ - *o = [NSMutableString stringWithCapacity:16]; - do { - // First see if there's a portion we can grab in one go. - // Doing this caused a massive speedup on the long string. - size_t len = strcspn(c, ctrl); - if (len) { - // check for - id t = [[NSString alloc] initWithBytesNoCopy:(char*)c - length:len - encoding:NSUTF8StringEncoding - freeWhenDone:NO]; - if (t) { - [*o appendString:t]; - [t release]; - c += len; - } - } - - if (*c == '"') { - c++; - return YES; - - } else if (*c == '\\') { - unichar uc = *++c; - switch (uc) { - case '\\': - case '/': - case '"': - break; - - case 'b': uc = '\b'; break; - case 'n': uc = '\n'; break; - case 'r': uc = '\r'; break; - case 't': uc = '\t'; break; - case 'f': uc = '\f'; break; - - case 'u': - c++; - if (![self scanUnicodeChar:&uc]) { - [self addErrorWithCode:EUNICODE description: @"Broken unicode character"]; - return NO; - } - c--; // hack. - break; - default: - [self addErrorWithCode:EESCAPE description: [NSString stringWithFormat:@"Illegal escape sequence '0x%x'", uc]]; - return NO; - break; - } - CFStringAppendCharacters((CFMutableStringRef)*o, &uc, 1); - c++; - - } else if (*c < 0x20) { - [self addErrorWithCode:ECTRL description: [NSString stringWithFormat:@"Unescaped control character '0x%x'", *c]]; - return NO; - - } else { - NSLog(@"should not be able to get here"); - } - } while (*c); - - [self addErrorWithCode:EEOF description:@"Unexpected EOF while parsing string"]; - return NO; -} - -- (BOOL)scanUnicodeChar:(unichar *)x -{ - unichar hi, lo; - - if (![self scanHexQuad:&hi]) { - [self addErrorWithCode:EUNICODE description: @"Missing hex quad"]; - return NO; - } - - if (hi >= 0xd800) { // high surrogate char? - if (hi < 0xdc00) { // yes - expect a low char - - if (!(*c == '\\' && ++c && *c == 'u' && ++c && [self scanHexQuad:&lo])) { - [self addErrorWithCode:EUNICODE description: @"Missing low character in surrogate pair"]; - return NO; - } - - if (lo < 0xdc00 || lo >= 0xdfff) { - [self addErrorWithCode:EUNICODE description:@"Invalid low surrogate char"]; - return NO; - } - - hi = (hi - 0xd800) * 0x400 + (lo - 0xdc00) + 0x10000; - - } else if (hi < 0xe000) { - [self addErrorWithCode:EUNICODE description:@"Invalid high character in surrogate pair"]; - return NO; - } - } - - *x = hi; - return YES; -} - -- (BOOL)scanHexQuad:(unichar *)x -{ - *x = 0; - for (int i = 0; i < 4; i++) { - unichar uc = *c; - c++; - int d = (uc >= '0' && uc <= '9') - ? uc - '0' : (uc >= 'a' && uc <= 'f') - ? (uc - 'a' + 10) : (uc >= 'A' && uc <= 'F') - ? (uc - 'A' + 10) : -1; - if (d == -1) { - [self addErrorWithCode:EUNICODE description:@"Missing hex digit in quad"]; - return NO; - } - *x *= 16; - *x += d; - } - return YES; -} - -- (BOOL)scanNumber:(NSNumber **)o -{ - const char *ns = c; - - // The logic to test for validity of the number formatting is relicensed - // from JSON::XS with permission from its author Marc Lehmann. - // (Available at the CPAN: http://search.cpan.org/dist/JSON-XS/ .) - - if ('-' == *c) - c++; - - if ('0' == *c && c++) { - if (isdigit(*c)) { - [self addErrorWithCode:EPARSENUM description: @"Leading 0 disallowed in number"]; - return NO; - } - - } else if (!isdigit(*c) && c != ns) { - [self addErrorWithCode:EPARSENUM description: @"No digits after initial minus"]; - return NO; - - } else { - skipDigits(c); - } - - // Fractional part - if ('.' == *c && c++) { - - if (!isdigit(*c)) { - [self addErrorWithCode:EPARSENUM description: @"No digits after decimal point"]; - return NO; - } - skipDigits(c); - } - - // Exponential part - if ('e' == *c || 'E' == *c) { - c++; - - if ('-' == *c || '+' == *c) - c++; - - if (!isdigit(*c)) { - [self addErrorWithCode:EPARSENUM description: @"No digits after exponent"]; - return NO; - } - skipDigits(c); - } - - id str = [[NSString alloc] initWithBytesNoCopy:(char*)ns - length:c - ns - encoding:NSUTF8StringEncoding - freeWhenDone:NO]; - [str autorelease]; - if (str && (*o = [NSDecimalNumber decimalNumberWithString:str])) - return YES; - - [self addErrorWithCode:EPARSENUM description: @"Failed creating decimal instance"]; - return NO; -} - -- (BOOL)scanIsAtEnd -{ - skipWhitespace(c); - return !*c; -} - - -@end diff --git a/lib/JSON/Franks_SBJsonWriter.h b/lib/JSON/Franks_SBJsonWriter.h deleted file mode 100644 index c44b0ed..0000000 --- a/lib/JSON/Franks_SBJsonWriter.h +++ /dev/null @@ -1,129 +0,0 @@ -/* - Copyright (C) 2009 Stig Brautaset. All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - * Neither the name of the author nor the names of its contributors may be used - to endorse or promote products derived from this software without specific - prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE - FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#import -#import "Franks_SBJsonBase.h" - -/** - @brief Options for the writer class. - - This exists so the Franks_SBJSON facade can implement the options in the writer without having to re-declare them. - */ -@protocol Franks_SBJsonWriter - -/** - @brief Whether we are generating human-readable (multiline) JSON. - - Set whether or not to generate human-readable JSON. The default is NO, which produces - JSON without any whitespace. (Except inside strings.) If set to YES, generates human-readable - JSON with linebreaks after each array value and dictionary key/value pair, indented two - spaces per nesting level. - */ -@property BOOL humanReadable; - -/** - @brief Whether or not to sort the dictionary keys in the output. - - If this is set to YES, the dictionary keys in the JSON output will be in sorted order. - (This is useful if you need to compare two structures, for example.) The default is NO. - */ -@property BOOL sortKeys; - -/** - @brief Return JSON representation (or fragment) for the given object. - - Returns a string containing JSON representation of the passed in value, or nil on error. - If nil is returned and @p error is not NULL, @p *error can be interrogated to find the cause of the error. - - @param value any instance that can be represented as a JSON fragment - - */ -- (NSString*)stringWithObject:(id)value; - -@end - - -/** - @brief The JSON writer class. - - Objective-C types are mapped to JSON types in the following way: - - @li NSNull -> Null - @li NSString -> String - @li NSArray -> Array - @li NSDictionary -> Object - @li NSNumber (-initWithBool:) -> Boolean - @li NSNumber -> Number - - In JSON the keys of an object must be strings. NSDictionary keys need - not be, but attempting to convert an NSDictionary with non-string keys - into JSON will throw an exception. - - NSNumber instances created with the +initWithBool: method are - converted into the JSON boolean "true" and "false" values, and vice - versa. Any other NSNumber instances are converted to a JSON number the - way you would expect. - - */ -@interface Franks_SBJsonWriter : Franks_SBJsonBase { - -@private - BOOL sortKeys, humanReadable; -} - -@end - -// don't use - exists for backwards compatibility. Will be removed in 2.3. -@interface Franks_SBJsonWriter (Private) -- (NSString*)stringWithFragment:(id)value; -@end - -/** - @brief Allows generation of JSON for otherwise unsupported classes. - - If you have a custom class that you want to create a JSON representation for you can implement - this method in your class. It should return a representation of your object defined - in terms of objects that can be translated into JSON. For example, a Person - object might implement it like this: - - @code - - (id)jsonProxyObject { - return [NSDictionary dictionaryWithObjectsAndKeys: - name, @"name", - phone, @"phone", - email, @"email", - nil]; - } - @endcode - - */ -@interface NSObject (SBProxyForJson) -- (id)proxyForJson; -@end - diff --git a/lib/JSON/Franks_SBJsonWriter.m b/lib/JSON/Franks_SBJsonWriter.m deleted file mode 100644 index 915eacf..0000000 --- a/lib/JSON/Franks_SBJsonWriter.m +++ /dev/null @@ -1,237 +0,0 @@ -/* - Copyright (C) 2009 Stig Brautaset. All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - * Neither the name of the author nor the names of its contributors may be used - to endorse or promote products derived from this software without specific - prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE - FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#import "Franks_SBJsonWriter.h" - -@interface Franks_SBJsonWriter () - -- (BOOL)appendValue:(id)fragment into:(NSMutableString*)json; -- (BOOL)appendArray:(NSArray*)fragment into:(NSMutableString*)json; -- (BOOL)appendDictionary:(NSDictionary*)fragment into:(NSMutableString*)json; -- (BOOL)appendString:(NSString*)fragment into:(NSMutableString*)json; - -- (NSString*)indent; - -@end - -@implementation Franks_SBJsonWriter - -static NSMutableCharacterSet *kEscapeChars; - -+ (void)initialize { - kEscapeChars = [[NSMutableCharacterSet characterSetWithRange: NSMakeRange(0,32)] retain]; - [kEscapeChars addCharactersInString: @"\"\\"]; -} - - -@synthesize sortKeys; -@synthesize humanReadable; - -/** - @deprecated This exists in order to provide fragment support in older APIs in one more version. - It should be removed in the next major version. - */ -- (NSString*)stringWithFragment:(id)value { - [self clearErrorTrace]; - depth = 0; - NSMutableString *json = [NSMutableString stringWithCapacity:128]; - - if ([self appendValue:value into:json]) - return json; - - return nil; -} - - -- (NSString*)stringWithObject:(id)value { - - if ([value isKindOfClass:[NSDictionary class]] || [value isKindOfClass:[NSArray class]]) { - return [self stringWithFragment:value]; - } - - if ([value respondsToSelector:@selector(proxyForJson)]) { - NSString *tmp = [self stringWithObject:[value proxyForJson]]; - if (tmp) - return tmp; - } - - - [self clearErrorTrace]; - [self addErrorWithCode:EFRAGMENT description:@"Not valid type for JSON"]; - return nil; -} - - -- (NSString*)indent { - return [@"\n" stringByPaddingToLength:1 + 2 * depth withString:@" " startingAtIndex:0]; -} - -- (BOOL)appendValue:(id)fragment into:(NSMutableString*)json { - if ([fragment isKindOfClass:[NSDictionary class]]) { - if (![self appendDictionary:fragment into:json]) - return NO; - - } else if ([fragment isKindOfClass:[NSArray class]]) { - if (![self appendArray:fragment into:json]) - return NO; - - } else if ([fragment isKindOfClass:[NSString class]]) { - if (![self appendString:fragment into:json]) - return NO; - - } else if ([fragment isKindOfClass:[NSNumber class]]) { - if ('c' == *[fragment objCType]) - [json appendString:[fragment boolValue] ? @"true" : @"false"]; - else - [json appendString:[fragment stringValue]]; - - } else if ([fragment isKindOfClass:[NSNull class]]) { - [json appendString:@"null"]; - } else if ([fragment respondsToSelector:@selector(proxyForJson)]) { - [self appendValue:[fragment proxyForJson] into:json]; - - } else { - [self addErrorWithCode:EUNSUPPORTED description:[NSString stringWithFormat:@"JSON serialisation not supported for %@", [fragment class]]]; - return NO; - } - return YES; -} - -- (BOOL)appendArray:(NSArray*)fragment into:(NSMutableString*)json { - if (maxDepth && ++depth > maxDepth) { - [self addErrorWithCode:EDEPTH description: @"Nested too deep"]; - return NO; - } - [json appendString:@"["]; - - BOOL addComma = NO; - for (id value in fragment) { - if (addComma) - [json appendString:@","]; - else - addComma = YES; - - if ([self humanReadable]) - [json appendString:[self indent]]; - - if (![self appendValue:value into:json]) { - return NO; - } - } - - depth--; - if ([self humanReadable] && [fragment count]) - [json appendString:[self indent]]; - [json appendString:@"]"]; - return YES; -} - -- (BOOL)appendDictionary:(NSDictionary*)fragment into:(NSMutableString*)json { - if (maxDepth && ++depth > maxDepth) { - [self addErrorWithCode:EDEPTH description: @"Nested too deep"]; - return NO; - } - [json appendString:@"{"]; - - NSString *colon = [self humanReadable] ? @" : " : @":"; - BOOL addComma = NO; - NSArray *keys = [fragment allKeys]; - if (self.sortKeys) - keys = [keys sortedArrayUsingSelector:@selector(compare:)]; - - for (id value in keys) { - if (addComma) - [json appendString:@","]; - else - addComma = YES; - - if ([self humanReadable]) - [json appendString:[self indent]]; - - if (![value isKindOfClass:[NSString class]]) { - [self addErrorWithCode:EUNSUPPORTED description: @"JSON object key must be string"]; - return NO; - } - - if (![self appendString:value into:json]) - return NO; - - [json appendString:colon]; - if (![self appendValue:[fragment objectForKey:value] into:json]) { - [self addErrorWithCode:EUNSUPPORTED description:[NSString stringWithFormat:@"Unsupported value for key %@ in object", value]]; - return NO; - } - } - - depth--; - if ([self humanReadable] && [fragment count]) - [json appendString:[self indent]]; - [json appendString:@"}"]; - return YES; -} - -- (BOOL)appendString:(NSString*)fragment into:(NSMutableString*)json { - - [json appendString:@"\""]; - - NSRange esc = [fragment rangeOfCharacterFromSet:kEscapeChars]; - if ( !esc.length ) { - // No special chars -- can just add the raw string: - [json appendString:fragment]; - - } else { - NSUInteger length = [fragment length]; - for (NSUInteger i = 0; i < length; i++) { - unichar uc = [fragment characterAtIndex:i]; - switch (uc) { - case '"': [json appendString:@"\\\""]; break; - case '\\': [json appendString:@"\\\\"]; break; - case '\t': [json appendString:@"\\t"]; break; - case '\n': [json appendString:@"\\n"]; break; - case '\r': [json appendString:@"\\r"]; break; - case '\b': [json appendString:@"\\b"]; break; - case '\f': [json appendString:@"\\f"]; break; - default: - if (uc < 0x20) { - [json appendFormat:@"\\u%04x", uc]; - } else { - CFStringAppendCharacters((CFMutableStringRef)json, &uc, 1); - } - break; - - } - } - } - - [json appendString:@"\""]; - return YES; -} - - -@end diff --git a/lib/JSON/JSON.h b/lib/JSON/JSON.h deleted file mode 100644 index 52a31c7..0000000 --- a/lib/JSON/JSON.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - Copyright (C) 2009 Stig Brautaset. All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - * Neither the name of the author nor the names of its contributors may be used - to endorse or promote products derived from this software without specific - prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE - FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/** - @mainpage A strict JSON parser and generator for Objective-C - - JSON (JavaScript Object Notation) is a lightweight data-interchange - format. This framework provides two apis for parsing and generating - JSON. One standard object-based and a higher level api consisting of - categories added to existing Objective-C classes. - - Learn more on the http://code.google.com/p/json-framework project site. - - This framework does its best to be as strict as possible, both in what it - accepts and what it generates. For example, it does not support trailing commas - in arrays or objects. Nor does it support embedded comments, or - anything else not in the JSON specification. This is considered a feature. - -*/ - -#import "Franks_SBJSON.h" -#import "NSObject+Franks_SBJSON.h" -#import "NSString+Franks_SBJSON.h" - diff --git a/lib/JSON/NSObject+Franks_SBJSON.h b/lib/JSON/NSObject+Franks_SBJSON.h deleted file mode 100644 index f32c861..0000000 --- a/lib/JSON/NSObject+Franks_SBJSON.h +++ /dev/null @@ -1,68 +0,0 @@ -/* - Copyright (C) 2009 Stig Brautaset. All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - * Neither the name of the author nor the names of its contributors may be used - to endorse or promote products derived from this software without specific - prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE - FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#import - - -/** - @brief Adds JSON generation to Foundation classes - - This is a category on NSObject that adds methods for returning JSON representations - of standard objects to the objects themselves. This means you can call the - -JSONRepresentation method on an NSArray object and it'll do what you want. - */ -@interface NSObject (NSObject_Franks_SBJSON) - -/** - @brief Returns a string containing the receiver encoded as a JSON fragment. - - This method is added as a category on NSObject but is only actually - supported for the following objects: - @li NSDictionary - @li NSArray - @li NSString - @li NSNumber (also used for booleans) - @li NSNull - - @deprecated Given we bill ourselves as a "strict" JSON library, this method should be removed. - */ -- (NSString *)JSONFragment; - -/** - @brief Returns a string containing the receiver encoded in JSON. - - This method is added as a category on NSObject but is only actually - supported for the following objects: - @li NSDictionary - @li NSArray - */ -- (NSString *)JSONRepresentation; - -@end - diff --git a/lib/JSON/NSObject+Franks_SBJSON.m b/lib/JSON/NSObject+Franks_SBJSON.m deleted file mode 100644 index ee7d17f..0000000 --- a/lib/JSON/NSObject+Franks_SBJSON.m +++ /dev/null @@ -1,53 +0,0 @@ -/* - Copyright (C) 2009 Stig Brautaset. All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - * Neither the name of the author nor the names of its contributors may be used - to endorse or promote products derived from this software without specific - prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE - FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#import "NSObject+Franks_SBJSON.h" -#import "Franks_SBJsonWriter.h" - -@implementation NSObject (NSObject_Franks_SBJSON) - -- (NSString *)JSONFragment { - Franks_SBJsonWriter *jsonWriter = [Franks_SBJsonWriter new]; - NSString *json = [jsonWriter stringWithFragment:self]; - if (!json) - NSLog(@"-JSONFragment failed. Error trace is: %@", [jsonWriter errorTrace]); - [jsonWriter release]; - return json; -} - -- (NSString *)JSONRepresentation { - Franks_SBJsonWriter *jsonWriter = [Franks_SBJsonWriter new]; - NSString *json = [jsonWriter stringWithObject:self]; - if (!json) - NSLog(@"-JSONRepresentation failed. Error trace is: %@", [jsonWriter errorTrace]); - [jsonWriter release]; - return json; -} - -@end diff --git a/lib/JSON/NSString+Franks_SBJSON.h b/lib/JSON/NSString+Franks_SBJSON.h deleted file mode 100644 index 19625bc..0000000 --- a/lib/JSON/NSString+Franks_SBJSON.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - Copyright (C) 2009 Stig Brautaset. All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - * Neither the name of the author nor the names of its contributors may be used - to endorse or promote products derived from this software without specific - prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE - FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#import - -/** - @brief Adds JSON parsing methods to NSString - -This is a category on NSString that adds methods for parsing the target string. -*/ -@interface NSString (NSString_Franks_SBJSON) - - -/** - @brief Returns the object represented in the receiver, or nil on error. - - Returns a a scalar object represented by the string's JSON fragment representation. - - @deprecated Given we bill ourselves as a "strict" JSON library, this method should be removed. - */ -- (id)JSONFragmentValue; - -/** - @brief Returns the NSDictionary or NSArray represented by the current string's JSON representation. - - Returns the dictionary or array represented in the receiver, or nil on error. - - Returns the NSDictionary or NSArray represented by the current string's JSON representation. - */ -- (id)JSONValue; - -@end diff --git a/lib/JSON/NSString+Franks_SBJSON.m b/lib/JSON/NSString+Franks_SBJSON.m deleted file mode 100644 index 1d026d8..0000000 --- a/lib/JSON/NSString+Franks_SBJSON.m +++ /dev/null @@ -1,55 +0,0 @@ -/* - Copyright (C) 2007-2009 Stig Brautaset. All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - * Neither the name of the author nor the names of its contributors may be used - to endorse or promote products derived from this software without specific - prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE - FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#import "NSString+Franks_SBJSON.h" -#import "Franks_SBJsonParser.h" - -@implementation NSString (NSString_Franks_SBJSON) - -- (id)JSONFragmentValue -{ - Franks_SBJsonParser *jsonParser = [Franks_SBJsonParser new]; - id repr = [jsonParser fragmentWithString:self]; - if (!repr) - NSLog(@"-JSONFragmentValue failed. Error trace is: %@", [jsonParser errorTrace]); - [jsonParser release]; - return repr; -} - -- (id)JSONValue -{ - Franks_SBJsonParser *jsonParser = [Franks_SBJsonParser new]; - id repr = [jsonParser objectWithString:self]; - if (!repr) - NSLog(@"-JSONValue failed. Error trace is: %@", [jsonParser errorTrace]); - [jsonParser release]; - return repr; -} - -@end diff --git a/src/AccessibilityCheckCommand.m b/src/AccessibilityCheckCommand.m index 873c7e1..3dc28e6 100644 --- a/src/AccessibilityCheckCommand.m +++ b/src/AccessibilityCheckCommand.m @@ -9,7 +9,6 @@ #import "AccessibilityCheckCommand.h" #import "JSON.h" - @implementation AccessibilityCheckCommand - (BOOL) accessibilitySeemsToBeTurnedOn { @@ -28,7 +27,7 @@ - (NSString *)handleCommandWithRequestBody:(NSString *)requestBody { NSString *boolString = ([self accessibilitySeemsToBeTurnedOn] ? @"true" : @"false"); NSDictionary *response = [NSDictionary dictionaryWithObject:boolString forKey:@"accessibility_enabled"]; - return [response JSONRepresentation]; + return TO_JSON(response); } @end \ No newline at end of file diff --git a/src/AppCommand.m b/src/AppCommand.m index 4909592..8c75378 100644 --- a/src/AppCommand.m +++ b/src/AppCommand.m @@ -9,16 +9,16 @@ #import #import "AppCommand.h" -#import "JSON.h" #import "Operation.h" #import "ViewJSONSerializer.h" #import "FranklyProtocolHelper.h" +#import "JSON.h" @implementation AppCommand - (NSString *)handleCommandWithRequestBody:(NSString *)requestBody { - NSDictionary *requestCommand = [requestBody JSONValue]; + NSDictionary *requestCommand = FROM_JSON(requestBody); NSDictionary *operationDict = [requestCommand objectForKey:@"operation"]; Operation *operation = [[[Operation alloc] initFromJsonRepresentation:operationDict] autorelease]; diff --git a/src/DumpCommand.m b/src/DumpCommand.m index 08890de..5120014 100644 --- a/src/DumpCommand.m +++ b/src/DumpCommand.m @@ -9,11 +9,10 @@ #import "objc/runtime.h" #import "ViewJSONSerializer.h" +#import "JSON.h" #import "DumpCommand.h" -#import "JSON.h" - @interface DumpCommand() @property (nonatomic, readwrite, retain) NSMutableDictionary *classMapping; @@ -104,7 +103,7 @@ - (NSString *)handleCommandWithRequestBody:(NSString *)requestBody { // serialize starting from root window and return json representation of it UIWindow *window = [UIApplication sharedApplication].keyWindow; NSDictionary *dom = [self serializeView: window]; - return [dom JSONRepresentation]; + return TO_JSON(dom); } #pragma mark - view serialization @@ -185,7 +184,7 @@ - (id) valueForAttribute: (NSString *) attribute onObject: (NSObject *) object { ![value isKindOfClass: NSDictionary.class] && ![value isKindOfClass: NSNull.class] && value != nil) { - return [NSString stringWithFormat:@"<%@ @%i>", [value class], value]; + return [NSString stringWithFormat:@"<%@ @%i>", [value class], (int)value]; } return value; diff --git a/src/EnginesCommand.m b/src/EnginesCommand.m index 82db544..d48c6a7 100644 --- a/src/EnginesCommand.m +++ b/src/EnginesCommand.m @@ -1,12 +1,13 @@ #import "EnginesCommand.h" #import "SelectorEngineRegistry.h" + #import "JSON.h" @implementation EnginesCommand { } - (NSString *)handleCommandWithRequestBody:(NSString *)requestBody { - return [[SelectorEngineRegistry getEngineNames] JSONRepresentation]; + return TO_JSON([SelectorEngineRegistry getEngineNames]); } diff --git a/src/FranklyProtocolHelper.m b/src/FranklyProtocolHelper.m index 14800e4..619d3ac 100644 --- a/src/FranklyProtocolHelper.m +++ b/src/FranklyProtocolHelper.m @@ -6,6 +6,7 @@ #import "FranklyProtocolHelper.h" + #import "JSON.h" @@ -19,14 +20,14 @@ + (NSString *)generateErrorResponseWithReason:(NSString *)reason andDetails:(NSS reason, @"reason", details, @"details", nil]; - return [response JSONRepresentation]; + return TO_JSON(response); } + (NSString *)generateSuccessResponseWithoutResults{ NSDictionary *response = [NSDictionary dictionaryWithObjectsAndKeys: @"SUCCESS", @"outcome", nil]; - return [response JSONRepresentation]; + return TO_JSON(response); } + (NSString *)generateSuccessResponseWithResults:(NSArray *)results{ @@ -34,7 +35,7 @@ + (NSString *)generateSuccessResponseWithResults:(NSArray *)results{ @"SUCCESS", @"outcome", results, @"results", nil]; - return [response JSONRepresentation]; + return TO_JSON(response); } @end \ No newline at end of file diff --git a/src/JSON.h b/src/JSON.h new file mode 100644 index 0000000..5679f18 --- /dev/null +++ b/src/JSON.h @@ -0,0 +1,18 @@ +// +// JSON.h +// Frank +// +// Created by Pete Hodgson on 10/19/12. +// +// + +#ifndef Frank_JSON_h +#define Frank_JSON_h + +#import "AnyJSON.h" + +#define TO_JSON(obj) ([[[NSString alloc] initWithData:AnyJSONEncode((obj), nil) encoding:NSUTF8StringEncoding] autorelease]) + +#define FROM_JSON(str) (AnyJSONDecode([(str) dataUsingEncoding:NSUTF8StringEncoding], nil)) + +#endif diff --git a/src/KeyboardCommand.m b/src/KeyboardCommand.m index e225bde..f16f8d1 100644 --- a/src/KeyboardCommand.m +++ b/src/KeyboardCommand.m @@ -22,7 +22,7 @@ - (NSString *)generateKeyboardNotPresentErrorResponse { - (NSString *)handleCommandWithRequestBody:(NSString *)requestBody { - NSDictionary *requestCommand = [requestBody JSONValue]; + NSDictionary *requestCommand = FROM_JSON(requestBody); NSString *textToType = [requestCommand objectForKey:@"text_to_type"]; if( ![UIAutomationBridge checkForKeyboard] ){ diff --git a/src/MapOperationCommand.m b/src/MapOperationCommand.m index 462ab01..5e594d6 100644 --- a/src/MapOperationCommand.m +++ b/src/MapOperationCommand.m @@ -11,12 +11,12 @@ #import "FranklyProtocolHelper.h" #import "ViewJSONSerializer.h" +#import "JSON.h" #import "SelectorEngineRegistry.h" #import "Operation.h" #import "DumpCommand.h" -#import "JSON.h" @implementation MapOperationCommand @@ -29,8 +29,7 @@ - (id) performOperation:(Operation *)operation onView:(UIView *)view { } - (NSString *)handleCommandWithRequestBody:(NSString *)requestBody { - - NSDictionary *requestCommand = [requestBody JSONValue]; + NSDictionary *requestCommand = FROM_JSON(requestBody); NSString *selectorEngineString = [requestCommand objectForKey:@"selector_engine"]; if( !selectorEngineString ) diff --git a/src/OrientationCommand.m b/src/OrientationCommand.m index 89d9290..1c948db 100644 --- a/src/OrientationCommand.m +++ b/src/OrientationCommand.m @@ -7,10 +7,10 @@ // #import "OrientationCommand.h" -#import "NSObject+Franks_SBJSON.h" #import #import "FranklyProtocolHelper.h" +#import "JSON.h" @implementation OrientationCommand @@ -84,7 +84,7 @@ - (NSString *)handleGet{ if( !orientationDescription ) orientationDescription = [self getOrientationRepresentationViaDevice]; - return [orientationDescription JSONRepresentation]; + return TO_JSON(orientationDescription); } - (NSString *)handlePost:(NSString *)requestBody{