iCuke 0.5.5 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (201) hide show
  1. data/.gitignore +2 -0
  2. data/.gitmodules +3 -0
  3. data/README.rdoc +8 -7
  4. data/Rakefile +10 -30
  5. data/VERSION +1 -1
  6. data/app/.gitignore +3 -0
  7. data/app/LICENSE +20 -0
  8. data/app/Readme.markdown +3 -0
  9. data/app/Shared/AppDelegate_Shared.h +17 -0
  10. data/app/Shared/AppDelegate_Shared.m +25 -0
  11. data/app/{images/yellowslide.png → Shared/Icon.png} +0 -0
  12. data/app/Shared/ModalViewController.h +15 -0
  13. data/app/Shared/ModalViewController.m +96 -0
  14. data/app/Shared/TestViewController_Shared.h +15 -0
  15. data/app/Shared/TestViewController_Shared.m +43 -0
  16. data/app/{Info.plist → Shared/Universal-Info.plist} +17 -4
  17. data/app/Shared/Universal_Prefix.pch +8 -0
  18. data/app/Shared/main.m +14 -0
  19. data/app/Universal.xcodeproj/project.pbxproj +301 -0
  20. data/app/iPad/AppDelegate_Pad.h +15 -0
  21. data/app/iPad/AppDelegate_Pad.m +28 -0
  22. data/app/iPad/Default-Landscape.png +0 -0
  23. data/app/iPad/Default-Portrait.png +0 -0
  24. data/app/iPad/MainWindow_Pad.xib +343 -0
  25. data/app/iPad/TestViewController_Pad.h +15 -0
  26. data/app/iPad/TestViewController_Pad.m +52 -0
  27. data/app/iPhone/AppDelegate_Phone.h +15 -0
  28. data/app/iPhone/AppDelegate_Phone.m +28 -0
  29. data/app/{images/segment_search.png → iPhone/Default.png} +0 -0
  30. data/app/iPhone/MainWindow_Phone.xib +363 -0
  31. data/app/iPhone/TestViewController_Phone.h +15 -0
  32. data/app/iPhone/TestViewController_Phone.m +36 -0
  33. data/bin/.gitignore +1 -0
  34. data/bin/icuke +10 -0
  35. data/bin/icuke-module +17 -0
  36. data/ext/.gitignore +1 -0
  37. data/ext/Rakefile +6 -0
  38. data/ext/WaxSim/Simulator.h +31 -0
  39. data/ext/WaxSim/Simulator.m +131 -0
  40. data/ext/WaxSim/WaxSim.m +110 -0
  41. data/ext/WaxSim/WaxSim.xcodeproj/project.pbxproj +238 -0
  42. data/ext/WaxSim/WaxSim_Prefix.pch +7 -0
  43. data/ext/WaxSim/iPhoneSimulatorRemoteClient/iPhoneSimulatorRemoteClient.h +126 -0
  44. data/ext/iCuke/Rakefile +14 -17
  45. data/ext/iCuke/libicuke-sdk3.1.dylib +0 -0
  46. data/ext/iCuke/libicuke-sdk4.0.dylib +0 -0
  47. data/ext/iCuke/libicuke.dylib +0 -0
  48. data/ext/iCuke/{DefaultsResponse.h → sdk3.1/DefaultsResponse.h} +0 -0
  49. data/ext/iCuke/{DefaultsResponse.m → sdk3.1/DefaultsResponse.m} +0 -0
  50. data/ext/iCuke/{EventResponse.h → sdk3.1/EventResponse.h} +0 -0
  51. data/ext/iCuke/{EventResponse.m → sdk3.1/EventResponse.m} +0 -0
  52. data/ext/iCuke/sdk3.1/ModuleResponse.h +5 -0
  53. data/ext/iCuke/sdk3.1/ModuleResponse.m +76 -0
  54. data/ext/iCuke/sdk3.1/Rakefile +20 -0
  55. data/ext/iCuke/{Recorder.h → sdk3.1/Recorder.h} +0 -0
  56. data/ext/iCuke/{Recorder.m → sdk3.1/Recorder.m} +0 -0
  57. data/ext/iCuke/{RecorderResponse.h → sdk3.1/RecorderResponse.h} +0 -0
  58. data/ext/iCuke/{RecorderResponse.m → sdk3.1/RecorderResponse.m} +0 -0
  59. data/ext/iCuke/{SynthesizeSingleton.h → sdk3.1/SynthesizeSingleton.h} +0 -0
  60. data/ext/iCuke/{ViewResponse.h → sdk3.1/ViewResponse.h} +0 -0
  61. data/ext/iCuke/{ViewResponse.m → sdk3.1/ViewResponse.m} +0 -0
  62. data/ext/iCuke/{Viewer.h → sdk3.1/Viewer.h} +0 -0
  63. data/ext/iCuke/sdk3.1/Viewer.m +203 -0
  64. data/ext/iCuke/{iCukeHTTPResponseHandler.h → sdk3.1/iCukeHTTPResponseHandler.h} +0 -0
  65. data/ext/iCuke/{iCukeHTTPResponseHandler.m → sdk3.1/iCukeHTTPResponseHandler.m} +0 -0
  66. data/ext/iCuke/{iCukeHTTPServer.h → sdk3.1/iCukeHTTPServer.h} +0 -0
  67. data/ext/iCuke/{iCukeHTTPServer.m → sdk3.1/iCukeHTTPServer.m} +0 -0
  68. data/ext/iCuke/{iCukeServer.h → sdk3.1/iCukeServer.h} +0 -2
  69. data/ext/iCuke/{iCukeServer.m → sdk3.1/iCukeServer.m} +22 -20
  70. data/ext/iCuke/{json → sdk3.1/json}/JSON.h +0 -0
  71. data/ext/iCuke/{json → sdk3.1/json}/NSObject+SBJSON.h +0 -0
  72. data/ext/iCuke/{json → sdk3.1/json}/NSObject+SBJSON.m +0 -0
  73. data/ext/iCuke/{json → sdk3.1/json}/NSString+SBJSON.h +0 -0
  74. data/ext/iCuke/{json → sdk3.1/json}/NSString+SBJSON.m +0 -0
  75. data/ext/iCuke/{json → sdk3.1/json}/SBJSON.h +0 -0
  76. data/ext/iCuke/{json → sdk3.1/json}/SBJSON.m +0 -0
  77. data/ext/iCuke/{json → sdk3.1/json}/SBJsonBase.h +0 -0
  78. data/ext/iCuke/{json → sdk3.1/json}/SBJsonBase.m +0 -0
  79. data/ext/iCuke/{json → sdk3.1/json}/SBJsonParser.h +0 -0
  80. data/ext/iCuke/{json → sdk3.1/json}/SBJsonParser.m +0 -0
  81. data/ext/iCuke/{json → sdk3.1/json}/SBJsonWriter.h +0 -0
  82. data/ext/iCuke/{json → sdk3.1/json}/SBJsonWriter.m +0 -0
  83. data/ext/iCuke/sdk4.0/DefaultsResponse.h +5 -0
  84. data/ext/iCuke/sdk4.0/DefaultsResponse.m +66 -0
  85. data/ext/iCuke/sdk4.0/EventResponse.h +5 -0
  86. data/ext/iCuke/sdk4.0/EventResponse.m +130 -0
  87. data/ext/iCuke/sdk4.0/ModuleResponse.h +5 -0
  88. data/ext/iCuke/sdk4.0/ModuleResponse.m +76 -0
  89. data/ext/iCuke/sdk4.0/Rakefile +20 -0
  90. data/ext/iCuke/sdk4.0/Recorder.h +17 -0
  91. data/ext/iCuke/sdk4.0/Recorder.m +90 -0
  92. data/ext/iCuke/sdk4.0/RecorderResponse.h +6 -0
  93. data/ext/iCuke/sdk4.0/RecorderResponse.m +68 -0
  94. data/ext/iCuke/sdk4.0/SynthesizeSingleton.h +68 -0
  95. data/ext/iCuke/sdk4.0/ViewResponse.h +5 -0
  96. data/ext/iCuke/sdk4.0/ViewResponse.m +84 -0
  97. data/ext/iCuke/sdk4.0/Viewer.h +8 -0
  98. data/ext/iCuke/{Viewer.m → sdk4.0/Viewer.m} +14 -0
  99. data/ext/iCuke/sdk4.0/iCukeHTTPResponseHandler.h +50 -0
  100. data/ext/iCuke/sdk4.0/iCukeHTTPResponseHandler.m +381 -0
  101. data/ext/iCuke/sdk4.0/iCukeHTTPServer.h +53 -0
  102. data/ext/iCuke/sdk4.0/iCukeHTTPServer.m +365 -0
  103. data/ext/iCuke/sdk4.0/iCukeServer.h +14 -0
  104. data/ext/iCuke/sdk4.0/iCukeServer.m +65 -0
  105. data/ext/iCuke/sdk4.0/json/JSON.h +50 -0
  106. data/ext/iCuke/sdk4.0/json/NSObject+SBJSON.h +68 -0
  107. data/ext/iCuke/sdk4.0/json/NSObject+SBJSON.m +53 -0
  108. data/ext/iCuke/sdk4.0/json/NSString+SBJSON.h +58 -0
  109. data/ext/iCuke/sdk4.0/json/NSString+SBJSON.m +55 -0
  110. data/ext/iCuke/sdk4.0/json/SBJSON.h +75 -0
  111. data/ext/iCuke/sdk4.0/json/SBJSON.m +212 -0
  112. data/ext/iCuke/sdk4.0/json/SBJsonBase.h +86 -0
  113. data/ext/iCuke/sdk4.0/json/SBJsonBase.m +78 -0
  114. data/ext/iCuke/sdk4.0/json/SBJsonParser.h +87 -0
  115. data/ext/iCuke/sdk4.0/json/SBJsonParser.m +475 -0
  116. data/ext/iCuke/sdk4.0/json/SBJsonWriter.h +129 -0
  117. data/ext/iCuke/sdk4.0/json/SBJsonWriter.m +228 -0
  118. data/features/iphone.feature +15 -0
  119. data/features/support/env.rb +1 -1
  120. data/iCuke.gemspec +118 -114
  121. data/lib/icuke/cucumber.rb +93 -64
  122. data/lib/icuke/screen.rb +110 -0
  123. data/lib/icuke/sdk.rb +134 -0
  124. data/lib/icuke/simulate.rb +9 -5
  125. data/lib/icuke/simulator.rb +10 -11
  126. data/lib/icuke/waxsim.rb +36 -0
  127. data/lib/icuke.rb +2 -1
  128. metadata +124 -129
  129. data/app/AlertsViewController.h +0 -59
  130. data/app/AlertsViewController.m +0 -341
  131. data/app/AppDelegate.h +0 -60
  132. data/app/AppDelegate.m +0 -101
  133. data/app/ButtonsViewController.h +0 -80
  134. data/app/ButtonsViewController.m +0 -448
  135. data/app/Constants.h +0 -58
  136. data/app/ControlsViewController.h +0 -72
  137. data/app/ControlsViewController.m +0 -379
  138. data/app/ImagesViewController.h +0 -62
  139. data/app/ImagesViewController.m +0 -137
  140. data/app/MainViewController.h +0 -57
  141. data/app/MainViewController.m +0 -262
  142. data/app/Picker/CustomPickerDataSource.h +0 -55
  143. data/app/Picker/CustomPickerDataSource.m +0 -135
  144. data/app/Picker/CustomView.h +0 -62
  145. data/app/Picker/CustomView.m +0 -119
  146. data/app/PickerViewController.h +0 -88
  147. data/app/PickerViewController.m +0 -402
  148. data/app/Prefix.pch +0 -5
  149. data/app/ReadMe.txt +0 -82
  150. data/app/SearchBarController.h +0 -58
  151. data/app/SearchBarController.m +0 -105
  152. data/app/SegmentViewController.h +0 -54
  153. data/app/SegmentViewController.m +0 -195
  154. data/app/TextFieldController.h +0 -67
  155. data/app/TextFieldController.m +0 -342
  156. data/app/TextViewController.h +0 -57
  157. data/app/TextViewController.m +0 -164
  158. data/app/ToolbarViewController.h +0 -74
  159. data/app/ToolbarViewController.m +0 -303
  160. data/app/TransitionViewController.h +0 -64
  161. data/app/TransitionViewController.m +0 -178
  162. data/app/UICatalog.xcodeproj/project.pbxproj +0 -615
  163. data/app/WebViewController.h +0 -57
  164. data/app/WebViewController.m +0 -173
  165. data/app/en.lproj/AlertsViewController.xib +0 -144
  166. data/app/en.lproj/ButtonsViewController.xib +0 -147
  167. data/app/en.lproj/ControlsViewController.xib +0 -147
  168. data/app/en.lproj/ImagesViewController.xib +0 -264
  169. data/app/en.lproj/Localizable.strings +0 -41
  170. data/app/en.lproj/MainWindow.xib +0 -306
  171. data/app/en.lproj/PickerViewController.xib +0 -415
  172. data/app/en.lproj/SearchBarController.xib +0 -142
  173. data/app/en.lproj/SegmentViewController.xib +0 -143
  174. data/app/en.lproj/TextFieldController.xib +0 -167
  175. data/app/en.lproj/TextViewController.xib +0 -149
  176. data/app/en.lproj/ToolbarViewController.xib +0 -491
  177. data/app/en.lproj/TransitionViewController.xib +0 -255
  178. data/app/en.lproj/WebViewController.xib +0 -141
  179. data/app/images/12-6AM.png +0 -0
  180. data/app/images/12-6PM.png +0 -0
  181. data/app/images/6-12AM.png +0 -0
  182. data/app/images/6-12PM.png +0 -0
  183. data/app/images/Default.png +0 -0
  184. data/app/images/Icon.png +0 -0
  185. data/app/images/UIButton_custom.png +0 -0
  186. data/app/images/blueButton.png +0 -0
  187. data/app/images/orangeslide.png +0 -0
  188. data/app/images/scene1.jpg +0 -0
  189. data/app/images/scene2.jpg +0 -0
  190. data/app/images/scene3.jpg +0 -0
  191. data/app/images/scene4.jpg +0 -0
  192. data/app/images/scene5.jpg +0 -0
  193. data/app/images/segment_check.png +0 -0
  194. data/app/images/segment_tools.png +0 -0
  195. data/app/images/slider_ball.png +0 -0
  196. data/app/images/whiteButton.png +0 -0
  197. data/app/main.m +0 -58
  198. data/features/uicatalog.feature +0 -20
  199. data/lib/icuke/com.apple.Accessibility.plist +0 -0
  200. data/lib/icuke/headless.rb +0 -54
  201. data/lib/icuke/xcode.rb +0 -164
@@ -0,0 +1,55 @@
1
+ /*
2
+ Copyright (C) 2007-2009 Stig Brautaset. All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without
5
+ modification, are permitted provided that the following conditions are met:
6
+
7
+ * Redistributions of source code must retain the above copyright notice, this
8
+ list of conditions and the following disclaimer.
9
+
10
+ * Redistributions in binary form must reproduce the above copyright notice,
11
+ this list of conditions and the following disclaimer in the documentation
12
+ and/or other materials provided with the distribution.
13
+
14
+ * Neither the name of the author nor the names of its contributors may be used
15
+ to endorse or promote products derived from this software without specific
16
+ prior written permission.
17
+
18
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
22
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
+ */
29
+
30
+ #import "NSString+SBJSON.h"
31
+ #import "SBJsonParser.h"
32
+
33
+ @implementation NSString (NSString_SBJSON)
34
+
35
+ - (id)JSONFragmentValue
36
+ {
37
+ SBJsonParser *jsonParser = [SBJsonParser new];
38
+ id repr = [jsonParser fragmentWithString:self];
39
+ if (!repr)
40
+ NSLog(@"-JSONFragmentValue failed. Error trace is: %@", [jsonParser errorTrace]);
41
+ [jsonParser release];
42
+ return repr;
43
+ }
44
+
45
+ - (id)JSONValue
46
+ {
47
+ SBJsonParser *jsonParser = [SBJsonParser new];
48
+ id repr = [jsonParser objectWithString:self];
49
+ if (!repr)
50
+ NSLog(@"-JSONValue failed. Error trace is: %@", [jsonParser errorTrace]);
51
+ [jsonParser release];
52
+ return repr;
53
+ }
54
+
55
+ @end
@@ -0,0 +1,75 @@
1
+ /*
2
+ Copyright (C) 2007-2009 Stig Brautaset. All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without
5
+ modification, are permitted provided that the following conditions are met:
6
+
7
+ * Redistributions of source code must retain the above copyright notice, this
8
+ list of conditions and the following disclaimer.
9
+
10
+ * Redistributions in binary form must reproduce the above copyright notice,
11
+ this list of conditions and the following disclaimer in the documentation
12
+ and/or other materials provided with the distribution.
13
+
14
+ * Neither the name of the author nor the names of its contributors may be used
15
+ to endorse or promote products derived from this software without specific
16
+ prior written permission.
17
+
18
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
22
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
+ */
29
+
30
+ #import <Foundation/Foundation.h>
31
+ #import "SBJsonParser.h"
32
+ #import "SBJsonWriter.h"
33
+
34
+ /**
35
+ @brief Facade for SBJsonWriter/SBJsonParser.
36
+
37
+ Requests are forwarded to instances of SBJsonWriter and SBJsonParser.
38
+ */
39
+ @interface SBJSON : SBJsonBase <SBJsonParser, SBJsonWriter> {
40
+
41
+ @private
42
+ SBJsonParser *jsonParser;
43
+ SBJsonWriter *jsonWriter;
44
+ }
45
+
46
+
47
+ /// Return the fragment represented by the given string
48
+ - (id)fragmentWithString:(NSString*)jsonrep
49
+ error:(NSError**)error;
50
+
51
+ /// Return the object represented by the given string
52
+ - (id)objectWithString:(NSString*)jsonrep
53
+ error:(NSError**)error;
54
+
55
+ /// Parse the string and return the represented object (or scalar)
56
+ - (id)objectWithString:(id)value
57
+ allowScalar:(BOOL)x
58
+ error:(NSError**)error;
59
+
60
+
61
+ /// Return JSON representation of an array or dictionary
62
+ - (NSString*)stringWithObject:(id)value
63
+ error:(NSError**)error;
64
+
65
+ /// Return JSON representation of any legal JSON value
66
+ - (NSString*)stringWithFragment:(id)value
67
+ error:(NSError**)error;
68
+
69
+ /// Return JSON representation (or fragment) for the given object
70
+ - (NSString*)stringWithObject:(id)value
71
+ allowScalar:(BOOL)x
72
+ error:(NSError**)error;
73
+
74
+
75
+ @end
@@ -0,0 +1,212 @@
1
+ /*
2
+ Copyright (C) 2007-2009 Stig Brautaset. All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without
5
+ modification, are permitted provided that the following conditions are met:
6
+
7
+ * Redistributions of source code must retain the above copyright notice, this
8
+ list of conditions and the following disclaimer.
9
+
10
+ * Redistributions in binary form must reproduce the above copyright notice,
11
+ this list of conditions and the following disclaimer in the documentation
12
+ and/or other materials provided with the distribution.
13
+
14
+ * Neither the name of the author nor the names of its contributors may be used
15
+ to endorse or promote products derived from this software without specific
16
+ prior written permission.
17
+
18
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
22
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
+ */
29
+
30
+ #import "SBJSON.h"
31
+
32
+ @implementation SBJSON
33
+
34
+ - (id)init {
35
+ self = [super init];
36
+ if (self) {
37
+ jsonWriter = [SBJsonWriter new];
38
+ jsonParser = [SBJsonParser new];
39
+ [self setMaxDepth:512];
40
+
41
+ }
42
+ return self;
43
+ }
44
+
45
+ - (void)dealloc {
46
+ [jsonWriter release];
47
+ [jsonParser release];
48
+ [super dealloc];
49
+ }
50
+
51
+ #pragma mark Writer
52
+
53
+
54
+ - (NSString *)stringWithObject:(id)obj {
55
+ NSString *repr = [jsonWriter stringWithObject:obj];
56
+ if (repr)
57
+ return repr;
58
+
59
+ [errorTrace release];
60
+ errorTrace = [[jsonWriter errorTrace] mutableCopy];
61
+ return nil;
62
+ }
63
+
64
+ /**
65
+ Returns a string containing JSON representation of the passed in value, or nil on error.
66
+ If nil is returned and @p error is not NULL, @p *error can be interrogated to find the cause of the error.
67
+
68
+ @param value any instance that can be represented as a JSON fragment
69
+ @param allowScalar wether to return json fragments for scalar objects
70
+ @param error used to return an error by reference (pass NULL if this is not desired)
71
+
72
+ @deprecated Given we bill ourselves as a "strict" JSON library, this method should be removed.
73
+ */
74
+ - (NSString*)stringWithObject:(id)value allowScalar:(BOOL)allowScalar error:(NSError**)error {
75
+
76
+ NSString *json = allowScalar ? [jsonWriter stringWithFragment:value] : [jsonWriter stringWithObject:value];
77
+ if (json)
78
+ return json;
79
+
80
+ [errorTrace release];
81
+ errorTrace = [[jsonWriter errorTrace] mutableCopy];
82
+
83
+ if (error)
84
+ *error = [errorTrace lastObject];
85
+ return nil;
86
+ }
87
+
88
+ /**
89
+ Returns a string containing JSON representation of the passed in value, or nil on error.
90
+ If nil is returned and @p error is not NULL, @p error can be interrogated to find the cause of the error.
91
+
92
+ @param value any instance that can be represented as a JSON fragment
93
+ @param error used to return an error by reference (pass NULL if this is not desired)
94
+
95
+ @deprecated Given we bill ourselves as a "strict" JSON library, this method should be removed.
96
+ */
97
+ - (NSString*)stringWithFragment:(id)value error:(NSError**)error {
98
+ return [self stringWithObject:value
99
+ allowScalar:YES
100
+ error:error];
101
+ }
102
+
103
+ /**
104
+ Returns a string containing JSON representation of the passed in value, or nil on error.
105
+ If nil is returned and @p error is not NULL, @p error can be interrogated to find the cause of the error.
106
+
107
+ @param value a NSDictionary or NSArray instance
108
+ @param error used to return an error by reference (pass NULL if this is not desired)
109
+ */
110
+ - (NSString*)stringWithObject:(id)value error:(NSError**)error {
111
+ return [self stringWithObject:value
112
+ allowScalar:NO
113
+ error:error];
114
+ }
115
+
116
+ #pragma mark Parsing
117
+
118
+ - (id)objectWithString:(NSString *)repr {
119
+ id obj = [jsonParser objectWithString:repr];
120
+ if (obj)
121
+ return obj;
122
+
123
+ [errorTrace release];
124
+ errorTrace = [[jsonParser errorTrace] mutableCopy];
125
+
126
+ return nil;
127
+ }
128
+
129
+ /**
130
+ Returns the object represented by the passed-in string or nil on error. The returned object can be
131
+ a string, number, boolean, null, array or dictionary.
132
+
133
+ @param value the json string to parse
134
+ @param allowScalar whether to return objects for JSON fragments
135
+ @param error used to return an error by reference (pass NULL if this is not desired)
136
+
137
+ @deprecated Given we bill ourselves as a "strict" JSON library, this method should be removed.
138
+ */
139
+ - (id)objectWithString:(id)value allowScalar:(BOOL)allowScalar error:(NSError**)error {
140
+
141
+ id obj = allowScalar ? [jsonParser fragmentWithString:value] : [jsonParser objectWithString:value];
142
+ if (obj)
143
+ return obj;
144
+
145
+ [errorTrace release];
146
+ errorTrace = [[jsonParser errorTrace] mutableCopy];
147
+
148
+ if (error)
149
+ *error = [errorTrace lastObject];
150
+ return nil;
151
+ }
152
+
153
+ /**
154
+ Returns the object represented by the passed-in string or nil on error. The returned object can be
155
+ a string, number, boolean, null, array or dictionary.
156
+
157
+ @param repr the json string to parse
158
+ @param error used to return an error by reference (pass NULL if this is not desired)
159
+
160
+ @deprecated Given we bill ourselves as a "strict" JSON library, this method should be removed.
161
+ */
162
+ - (id)fragmentWithString:(NSString*)repr error:(NSError**)error {
163
+ return [self objectWithString:repr
164
+ allowScalar:YES
165
+ error:error];
166
+ }
167
+
168
+ /**
169
+ Returns the object represented by the passed-in string or nil on error. The returned object
170
+ will be either a dictionary or an array.
171
+
172
+ @param repr the json string to parse
173
+ @param error used to return an error by reference (pass NULL if this is not desired)
174
+ */
175
+ - (id)objectWithString:(NSString*)repr error:(NSError**)error {
176
+ return [self objectWithString:repr
177
+ allowScalar:NO
178
+ error:error];
179
+ }
180
+
181
+
182
+
183
+ #pragma mark Properties - parsing
184
+
185
+ - (NSUInteger)maxDepth {
186
+ return jsonParser.maxDepth;
187
+ }
188
+
189
+ - (void)setMaxDepth:(NSUInteger)d {
190
+ jsonWriter.maxDepth = jsonParser.maxDepth = d;
191
+ }
192
+
193
+
194
+ #pragma mark Properties - writing
195
+
196
+ - (BOOL)humanReadable {
197
+ return jsonWriter.humanReadable;
198
+ }
199
+
200
+ - (void)setHumanReadable:(BOOL)x {
201
+ jsonWriter.humanReadable = x;
202
+ }
203
+
204
+ - (BOOL)sortKeys {
205
+ return jsonWriter.sortKeys;
206
+ }
207
+
208
+ - (void)setSortKeys:(BOOL)x {
209
+ jsonWriter.sortKeys = x;
210
+ }
211
+
212
+ @end
@@ -0,0 +1,86 @@
1
+ /*
2
+ Copyright (C) 2009 Stig Brautaset. All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without
5
+ modification, are permitted provided that the following conditions are met:
6
+
7
+ * Redistributions of source code must retain the above copyright notice, this
8
+ list of conditions and the following disclaimer.
9
+
10
+ * Redistributions in binary form must reproduce the above copyright notice,
11
+ this list of conditions and the following disclaimer in the documentation
12
+ and/or other materials provided with the distribution.
13
+
14
+ * Neither the name of the author nor the names of its contributors may be used
15
+ to endorse or promote products derived from this software without specific
16
+ prior written permission.
17
+
18
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
22
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
+ */
29
+
30
+ #import <Foundation/Foundation.h>
31
+
32
+ extern NSString * SBJSONErrorDomain;
33
+
34
+
35
+ enum {
36
+ EUNSUPPORTED = 1,
37
+ EPARSENUM,
38
+ EPARSE,
39
+ EFRAGMENT,
40
+ ECTRL,
41
+ EUNICODE,
42
+ EDEPTH,
43
+ EESCAPE,
44
+ ETRAILCOMMA,
45
+ ETRAILGARBAGE,
46
+ EEOF,
47
+ EINPUT
48
+ };
49
+
50
+ /**
51
+ @brief Common base class for parsing & writing.
52
+
53
+ This class contains the common error-handling code and option between the parser/writer.
54
+ */
55
+ @interface SBJsonBase : NSObject {
56
+ NSMutableArray *errorTrace;
57
+
58
+ @protected
59
+ NSUInteger depth, maxDepth;
60
+ }
61
+
62
+ /**
63
+ @brief The maximum recursing depth.
64
+
65
+ Defaults to 512. If the input is nested deeper than this the input will be deemed to be
66
+ malicious and the parser returns nil, signalling an error. ("Nested too deep".) You can
67
+ turn off this security feature by setting the maxDepth value to 0.
68
+ */
69
+ @property NSUInteger maxDepth;
70
+
71
+ /**
72
+ @brief Return an error trace, or nil if there was no errors.
73
+
74
+ Note that this method returns the trace of the last method that failed.
75
+ You need to check the return value of the call you're making to figure out
76
+ if the call actually failed, before you know call this method.
77
+ */
78
+ @property(copy,readonly) NSArray* errorTrace;
79
+
80
+ /// @internal for use in subclasses to add errors to the stack trace
81
+ - (void)addErrorWithCode:(NSUInteger)code description:(NSString*)str;
82
+
83
+ /// @internal for use in subclasess to clear the error before a new parsing attempt
84
+ - (void)clearErrorTrace;
85
+
86
+ @end
@@ -0,0 +1,78 @@
1
+ /*
2
+ Copyright (C) 2009 Stig Brautaset. All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without
5
+ modification, are permitted provided that the following conditions are met:
6
+
7
+ * Redistributions of source code must retain the above copyright notice, this
8
+ list of conditions and the following disclaimer.
9
+
10
+ * Redistributions in binary form must reproduce the above copyright notice,
11
+ this list of conditions and the following disclaimer in the documentation
12
+ and/or other materials provided with the distribution.
13
+
14
+ * Neither the name of the author nor the names of its contributors may be used
15
+ to endorse or promote products derived from this software without specific
16
+ prior written permission.
17
+
18
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
22
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
+ */
29
+
30
+ #import "SBJsonBase.h"
31
+ NSString * SBJSONErrorDomain = @"org.brautaset.JSON.ErrorDomain";
32
+
33
+
34
+ @implementation SBJsonBase
35
+
36
+ @synthesize errorTrace;
37
+ @synthesize maxDepth;
38
+
39
+ - (id)init {
40
+ self = [super init];
41
+ if (self)
42
+ self.maxDepth = 512;
43
+ return self;
44
+ }
45
+
46
+ - (void)dealloc {
47
+ [errorTrace release];
48
+ [super dealloc];
49
+ }
50
+
51
+ - (void)addErrorWithCode:(NSUInteger)code description:(NSString*)str {
52
+ NSDictionary *userInfo;
53
+ if (!errorTrace) {
54
+ errorTrace = [NSMutableArray new];
55
+ userInfo = [NSDictionary dictionaryWithObject:str forKey:NSLocalizedDescriptionKey];
56
+
57
+ } else {
58
+ userInfo = [NSDictionary dictionaryWithObjectsAndKeys:
59
+ str, NSLocalizedDescriptionKey,
60
+ [errorTrace lastObject], NSUnderlyingErrorKey,
61
+ nil];
62
+ }
63
+
64
+ NSError *error = [NSError errorWithDomain:SBJSONErrorDomain code:code userInfo:userInfo];
65
+
66
+ [self willChangeValueForKey:@"errorTrace"];
67
+ [errorTrace addObject:error];
68
+ [self didChangeValueForKey:@"errorTrace"];
69
+ }
70
+
71
+ - (void)clearErrorTrace {
72
+ [self willChangeValueForKey:@"errorTrace"];
73
+ [errorTrace release];
74
+ errorTrace = nil;
75
+ [self didChangeValueForKey:@"errorTrace"];
76
+ }
77
+
78
+ @end
@@ -0,0 +1,87 @@
1
+ /*
2
+ Copyright (C) 2009 Stig Brautaset. All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without
5
+ modification, are permitted provided that the following conditions are met:
6
+
7
+ * Redistributions of source code must retain the above copyright notice, this
8
+ list of conditions and the following disclaimer.
9
+
10
+ * Redistributions in binary form must reproduce the above copyright notice,
11
+ this list of conditions and the following disclaimer in the documentation
12
+ and/or other materials provided with the distribution.
13
+
14
+ * Neither the name of the author nor the names of its contributors may be used
15
+ to endorse or promote products derived from this software without specific
16
+ prior written permission.
17
+
18
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
22
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
+ */
29
+
30
+ #import <Foundation/Foundation.h>
31
+ #import "SBJsonBase.h"
32
+
33
+ /**
34
+ @brief Options for the parser class.
35
+
36
+ This exists so the SBJSON facade can implement the options in the parser without having to re-declare them.
37
+ */
38
+ @protocol SBJsonParser
39
+
40
+ /**
41
+ @brief Return the object represented by the given string.
42
+
43
+ Returns the object represented by the passed-in string or nil on error. The returned object can be
44
+ a string, number, boolean, null, array or dictionary.
45
+
46
+ @param repr the json string to parse
47
+ */
48
+ - (id)objectWithString:(NSString *)repr;
49
+
50
+ @end
51
+
52
+
53
+ /**
54
+ @brief The JSON parser class.
55
+
56
+ JSON is mapped to Objective-C types in the following way:
57
+
58
+ @li Null -> NSNull
59
+ @li String -> NSMutableString
60
+ @li Array -> NSMutableArray
61
+ @li Object -> NSMutableDictionary
62
+ @li Boolean -> NSNumber (initialised with -initWithBool:)
63
+ @li Number -> NSDecimalNumber
64
+
65
+ Since Objective-C doesn't have a dedicated class for boolean values, these turns into NSNumber
66
+ instances. These are initialised with the -initWithBool: method, and
67
+ round-trip back to JSON properly. (They won't silently suddenly become 0 or 1; they'll be
68
+ represented as 'true' and 'false' again.)
69
+
70
+ JSON numbers turn into NSDecimalNumber instances,
71
+ as we can thus avoid any loss of precision. (JSON allows ridiculously large numbers.)
72
+
73
+ */
74
+ @interface SBJsonParser : SBJsonBase <SBJsonParser> {
75
+
76
+ @private
77
+ const char *c;
78
+ }
79
+
80
+ @end
81
+
82
+ // don't use - exists for backwards compatibility with 2.1.x only. Will be removed in 2.3.
83
+ @interface SBJsonParser (Private)
84
+ - (id)fragmentWithString:(id)repr;
85
+ @end
86
+
87
+