iCuke 0.6.3 → 0.6.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (129) hide show
  1. data/.gitmodules +1 -1
  2. data/Gemfile +12 -0
  3. data/Gemfile.lock +41 -0
  4. data/README.markdown +126 -0
  5. data/Rakefile +34 -12
  6. data/VERSION +1 -1
  7. data/bin/icuke +12 -10
  8. data/ext/Rakefile +6 -0
  9. data/ext/iCuke/{sdk3.1/DefaultsResponse.h → DefaultsResponse.h} +0 -0
  10. data/ext/iCuke/{sdk3.1/DefaultsResponse.m → DefaultsResponse.m} +0 -0
  11. data/ext/iCuke/{sdk3.1/EventResponse.h → EventResponse.h} +0 -0
  12. data/ext/iCuke/{sdk3.1/EventResponse.m → EventResponse.m} +0 -0
  13. data/ext/iCuke/{sdk3.1/ModuleResponse.h → ModuleResponse.h} +0 -0
  14. data/ext/iCuke/{sdk3.1/ModuleResponse.m → ModuleResponse.m} +0 -0
  15. data/ext/iCuke/{sdk3.1/QuitResponse.h → QuitResponse.h} +0 -0
  16. data/ext/iCuke/{sdk3.1/QuitResponse.m → QuitResponse.m} +0 -0
  17. data/ext/iCuke/Rakefile +14 -13
  18. data/ext/iCuke/{sdk3.1/Recorder.h → Recorder.h} +0 -0
  19. data/ext/iCuke/{sdk3.1/Recorder.m → Recorder.m} +0 -0
  20. data/ext/iCuke/{sdk3.1/RecorderResponse.h → RecorderResponse.h} +0 -0
  21. data/ext/iCuke/{sdk3.1/RecorderResponse.m → RecorderResponse.m} +0 -0
  22. data/ext/iCuke/{sdk3.1/SynthesizeSingleton.h → SynthesizeSingleton.h} +0 -0
  23. data/ext/iCuke/{sdk3.1/ViewResponse.h → ViewResponse.h} +0 -0
  24. data/ext/iCuke/{sdk3.1/ViewResponse.m → ViewResponse.m} +0 -0
  25. data/ext/iCuke/{sdk3.1/Viewer.h → Viewer.h} +0 -0
  26. data/ext/iCuke/{sdk4.0/Viewer.m → Viewer.m} +0 -0
  27. data/ext/iCuke/{sdk3.1/iCukeHTTPResponseHandler.h → iCukeHTTPResponseHandler.h} +0 -0
  28. data/ext/iCuke/{sdk3.1/iCukeHTTPResponseHandler.m → iCukeHTTPResponseHandler.m} +0 -0
  29. data/ext/iCuke/{sdk3.1/iCukeHTTPServer.h → iCukeHTTPServer.h} +0 -0
  30. data/ext/iCuke/{sdk4.0/iCukeHTTPServer.m → iCukeHTTPServer.m} +4 -2
  31. data/ext/iCuke/{sdk3.1/iCukeServer.h → iCukeServer.h} +0 -0
  32. data/ext/iCuke/{sdk3.1/iCukeServer.m → iCukeServer.m} +0 -0
  33. data/ext/iCuke/{sdk3.1/json → json}/JSON.h +0 -0
  34. data/ext/iCuke/{sdk3.1/json → json}/NSObject+SBJSON.h +0 -0
  35. data/ext/iCuke/{sdk3.1/json → json}/NSObject+SBJSON.m +0 -0
  36. data/ext/iCuke/{sdk3.1/json → json}/NSString+SBJSON.h +0 -0
  37. data/ext/iCuke/{sdk3.1/json → json}/NSString+SBJSON.m +0 -0
  38. data/ext/iCuke/{sdk3.1/json → json}/SBJSON.h +0 -0
  39. data/ext/iCuke/{sdk3.1/json → json}/SBJSON.m +0 -0
  40. data/ext/iCuke/{sdk3.1/json → json}/SBJsonBase.h +0 -0
  41. data/ext/iCuke/{sdk3.1/json → json}/SBJsonBase.m +0 -0
  42. data/ext/iCuke/{sdk3.1/json → json}/SBJsonParser.h +0 -0
  43. data/ext/iCuke/{sdk3.1/json → json}/SBJsonParser.m +0 -0
  44. data/ext/iCuke/{sdk3.1/json → json}/SBJsonWriter.h +0 -0
  45. data/ext/iCuke/{sdk3.1/json → json}/SBJsonWriter.m +0 -0
  46. data/features/starting_project.feature +18 -0
  47. data/features/step_definitions/shell.rb +41 -0
  48. data/features/support/env.rb +2 -0
  49. data/features/support/environment.rb +40 -0
  50. data/features/supported_sdks.feature +12 -0
  51. data/iCuke.gemspec +149 -161
  52. data/lib/icuke/configuration.rb +19 -0
  53. data/lib/icuke/core_ext.rb +27 -0
  54. data/lib/icuke/cucumber.rb +29 -265
  55. data/lib/icuke/cucumber_compat.rb +4 -0
  56. data/lib/icuke/icuke_world.rb +149 -0
  57. data/lib/icuke/sdk.rb +5 -13
  58. data/lib/icuke/simulator_driver.rb +201 -0
  59. data/lib/icuke/waxsim.rb +47 -9
  60. data/spec/cucumber_spec.rb +130 -0
  61. data/spec/fixtures/controls_page.xml +252 -0
  62. data/spec/process_spec.rb +76 -0
  63. data/spec/screen_spec.rb +173 -0
  64. data/spec/simulate_spec.rb +75 -0
  65. data/spec/simulator_spec.rb +28 -0
  66. data/spec/spec.opts +2 -0
  67. data/spec/spec_helper.rb +67 -0
  68. metadata +222 -121
  69. data/.gitignore +0 -15
  70. data/README.rdoc +0 -68
  71. data/ext/WaxSim/Simulator.h +0 -31
  72. data/ext/WaxSim/Simulator.m +0 -131
  73. data/ext/WaxSim/WaxSim.m +0 -110
  74. data/ext/WaxSim/WaxSim.xcodeproj/project.pbxproj +0 -238
  75. data/ext/WaxSim/WaxSim_Prefix.pch +0 -7
  76. data/ext/WaxSim/build/Release/waxsim +0 -0
  77. data/ext/WaxSim/build/Release/waxsim.dSYM/Contents/Info.plist +0 -20
  78. data/ext/WaxSim/build/Release/waxsim.dSYM/Contents/Resources/DWARF/waxsim +0 -0
  79. data/ext/WaxSim/build/WaxSim.build/Release/WaxSim.build/Objects-normal/x86_64/Simulator.o +0 -0
  80. data/ext/WaxSim/build/WaxSim.build/Release/WaxSim.build/Objects-normal/x86_64/WaxSim.o +0 -0
  81. data/ext/WaxSim/build/WaxSim.build/Release/WaxSim.build/Objects-normal/x86_64/waxsim.LinkFileList +0 -2
  82. data/ext/WaxSim/build/WaxSim.build/Release/WaxSim.build/WaxSim.dep +0 -6
  83. data/ext/WaxSim/build/WaxSim.build/Release/WaxSim.build/WaxSim~.dep +0 -6
  84. data/ext/WaxSim/build/WaxSim.build/Release/WaxSim.build/build-state.dat +0 -227
  85. data/ext/WaxSim/build/WaxSim.build/Release/WaxSim.build/build-state~.dat +0 -227
  86. data/ext/WaxSim/build/WaxSim.build/Release/WaxSim.build/waxsim-all-target-headers.hmap +0 -0
  87. data/ext/WaxSim/build/WaxSim.build/Release/WaxSim.build/waxsim-generated-files.hmap +0 -0
  88. data/ext/WaxSim/build/WaxSim.build/Release/WaxSim.build/waxsim-own-target-headers.hmap +0 -0
  89. data/ext/WaxSim/build/WaxSim.build/Release/WaxSim.build/waxsim-project-headers.hmap +0 -0
  90. data/ext/WaxSim/build/WaxSim.build/Release/WaxSim.build/waxsim.hmap +0 -0
  91. data/ext/WaxSim/iPhoneSimulatorRemoteClient/iPhoneSimulatorRemoteClient.h +0 -126
  92. data/ext/iCuke/sdk3.1/Rakefile +0 -20
  93. data/ext/iCuke/sdk3.1/Viewer.m +0 -203
  94. data/ext/iCuke/sdk3.1/iCukeHTTPServer.m +0 -365
  95. data/ext/iCuke/sdk4.0/DefaultsResponse.h +0 -5
  96. data/ext/iCuke/sdk4.0/DefaultsResponse.m +0 -66
  97. data/ext/iCuke/sdk4.0/EventResponse.h +0 -5
  98. data/ext/iCuke/sdk4.0/EventResponse.m +0 -130
  99. data/ext/iCuke/sdk4.0/ModuleResponse.h +0 -5
  100. data/ext/iCuke/sdk4.0/ModuleResponse.m +0 -76
  101. data/ext/iCuke/sdk4.0/QuitResponse.h +0 -5
  102. data/ext/iCuke/sdk4.0/QuitResponse.m +0 -23
  103. data/ext/iCuke/sdk4.0/Rakefile +0 -20
  104. data/ext/iCuke/sdk4.0/Recorder.h +0 -17
  105. data/ext/iCuke/sdk4.0/Recorder.m +0 -90
  106. data/ext/iCuke/sdk4.0/RecorderResponse.h +0 -6
  107. data/ext/iCuke/sdk4.0/RecorderResponse.m +0 -68
  108. data/ext/iCuke/sdk4.0/SynthesizeSingleton.h +0 -68
  109. data/ext/iCuke/sdk4.0/ViewResponse.h +0 -5
  110. data/ext/iCuke/sdk4.0/ViewResponse.m +0 -84
  111. data/ext/iCuke/sdk4.0/Viewer.h +0 -8
  112. data/ext/iCuke/sdk4.0/iCukeHTTPResponseHandler.h +0 -50
  113. data/ext/iCuke/sdk4.0/iCukeHTTPResponseHandler.m +0 -381
  114. data/ext/iCuke/sdk4.0/iCukeHTTPServer.h +0 -53
  115. data/ext/iCuke/sdk4.0/iCukeServer.h +0 -14
  116. data/ext/iCuke/sdk4.0/iCukeServer.m +0 -65
  117. data/ext/iCuke/sdk4.0/json/JSON.h +0 -50
  118. data/ext/iCuke/sdk4.0/json/NSObject+SBJSON.h +0 -68
  119. data/ext/iCuke/sdk4.0/json/NSObject+SBJSON.m +0 -53
  120. data/ext/iCuke/sdk4.0/json/NSString+SBJSON.h +0 -58
  121. data/ext/iCuke/sdk4.0/json/NSString+SBJSON.m +0 -55
  122. data/ext/iCuke/sdk4.0/json/SBJSON.h +0 -75
  123. data/ext/iCuke/sdk4.0/json/SBJSON.m +0 -212
  124. data/ext/iCuke/sdk4.0/json/SBJsonBase.h +0 -86
  125. data/ext/iCuke/sdk4.0/json/SBJsonBase.m +0 -78
  126. data/ext/iCuke/sdk4.0/json/SBJsonParser.h +0 -87
  127. data/ext/iCuke/sdk4.0/json/SBJsonParser.m +0 -475
  128. data/ext/iCuke/sdk4.0/json/SBJsonWriter.h +0 -129
  129. data/ext/iCuke/sdk4.0/json/SBJsonWriter.m +0 -228
@@ -1,129 +0,0 @@
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 writer class.
35
-
36
- This exists so the SBJSON facade can implement the options in the writer without having to re-declare them.
37
- */
38
- @protocol SBJsonWriter
39
-
40
- /**
41
- @brief Whether we are generating human-readable (multiline) JSON.
42
-
43
- Set whether or not to generate human-readable JSON. The default is NO, which produces
44
- JSON without any whitespace. (Except inside strings.) If set to YES, generates human-readable
45
- JSON with linebreaks after each array value and dictionary key/value pair, indented two
46
- spaces per nesting level.
47
- */
48
- @property BOOL humanReadable;
49
-
50
- /**
51
- @brief Whether or not to sort the dictionary keys in the output.
52
-
53
- If this is set to YES, the dictionary keys in the JSON output will be in sorted order.
54
- (This is useful if you need to compare two structures, for example.) The default is NO.
55
- */
56
- @property BOOL sortKeys;
57
-
58
- /**
59
- @brief Return JSON representation (or fragment) for the given object.
60
-
61
- Returns a string containing JSON representation of the passed in value, or nil on error.
62
- If nil is returned and @p error is not NULL, @p *error can be interrogated to find the cause of the error.
63
-
64
- @param value any instance that can be represented as a JSON fragment
65
-
66
- */
67
- - (NSString*)stringWithObject:(id)value;
68
-
69
- @end
70
-
71
-
72
- /**
73
- @brief The JSON writer class.
74
-
75
- Objective-C types are mapped to JSON types in the following way:
76
-
77
- @li NSNull -> Null
78
- @li NSString -> String
79
- @li NSArray -> Array
80
- @li NSDictionary -> Object
81
- @li NSNumber (-initWithBool:) -> Boolean
82
- @li NSNumber -> Number
83
-
84
- In JSON the keys of an object must be strings. NSDictionary keys need
85
- not be, but attempting to convert an NSDictionary with non-string keys
86
- into JSON will throw an exception.
87
-
88
- NSNumber instances created with the +initWithBool: method are
89
- converted into the JSON boolean "true" and "false" values, and vice
90
- versa. Any other NSNumber instances are converted to a JSON number the
91
- way you would expect.
92
-
93
- */
94
- @interface SBJsonWriter : SBJsonBase <SBJsonWriter> {
95
-
96
- @private
97
- BOOL sortKeys, humanReadable;
98
- }
99
-
100
- @end
101
-
102
- // don't use - exists for backwards compatibility. Will be removed in 2.3.
103
- @interface SBJsonWriter (Private)
104
- - (NSString*)stringWithFragment:(id)value;
105
- @end
106
-
107
- /**
108
- @brief Allows generation of JSON for otherwise unsupported classes.
109
-
110
- If you have a custom class that you want to create a JSON representation for you can implement
111
- this method in your class. It should return a representation of your object defined
112
- in terms of objects that can be translated into JSON. For example, a Person
113
- object might implement it like this:
114
-
115
- @code
116
- - (id)jsonProxyObject {
117
- return [NSDictionary dictionaryWithObjectsAndKeys:
118
- name, @"name",
119
- phone, @"phone",
120
- email, @"email",
121
- nil];
122
- }
123
- @endcode
124
-
125
- */
126
- @interface NSObject (SBProxyForJson)
127
- - (id)proxyForJson;
128
- @end
129
-
@@ -1,228 +0,0 @@
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 "SBJsonWriter.h"
31
-
32
- @interface SBJsonWriter ()
33
-
34
- - (BOOL)appendValue:(id)fragment into:(NSMutableString*)json;
35
- - (BOOL)appendArray:(NSArray*)fragment into:(NSMutableString*)json;
36
- - (BOOL)appendDictionary:(NSDictionary*)fragment into:(NSMutableString*)json;
37
- - (BOOL)appendString:(NSString*)fragment into:(NSMutableString*)json;
38
-
39
- - (NSString*)indent;
40
-
41
- @end
42
-
43
- @implementation SBJsonWriter
44
-
45
- @synthesize sortKeys;
46
- @synthesize humanReadable;
47
-
48
- /**
49
- @deprecated This exists in order to provide fragment support in older APIs in one more version.
50
- It should be removed in the next major version.
51
- */
52
- - (NSString*)stringWithFragment:(id)value {
53
- [self clearErrorTrace];
54
- depth = 0;
55
- NSMutableString *json = [NSMutableString stringWithCapacity:128];
56
-
57
- if ([self appendValue:value into:json])
58
- return json;
59
-
60
- return nil;
61
- }
62
-
63
-
64
- - (NSString*)stringWithObject:(id)value {
65
-
66
- if ([value isKindOfClass:[NSDictionary class]] || [value isKindOfClass:[NSArray class]]) {
67
- return [self stringWithFragment:value];
68
- }
69
-
70
- [self clearErrorTrace];
71
- [self addErrorWithCode:EFRAGMENT description:@"Not valid type for JSON"];
72
- return nil;
73
- }
74
-
75
-
76
- - (NSString*)indent {
77
- return [@"\n" stringByPaddingToLength:1 + 2 * depth withString:@" " startingAtIndex:0];
78
- }
79
-
80
- - (BOOL)appendValue:(id)fragment into:(NSMutableString*)json {
81
- if ([fragment isKindOfClass:[NSDictionary class]]) {
82
- if (![self appendDictionary:fragment into:json])
83
- return NO;
84
-
85
- } else if ([fragment isKindOfClass:[NSArray class]]) {
86
- if (![self appendArray:fragment into:json])
87
- return NO;
88
-
89
- } else if ([fragment isKindOfClass:[NSString class]]) {
90
- if (![self appendString:fragment into:json])
91
- return NO;
92
-
93
- } else if ([fragment isKindOfClass:[NSNumber class]]) {
94
- if ('c' == *[fragment objCType])
95
- [json appendString:[fragment boolValue] ? @"true" : @"false"];
96
- else
97
- [json appendString:[fragment stringValue]];
98
-
99
- } else if ([fragment isKindOfClass:[NSNull class]]) {
100
- [json appendString:@"null"];
101
- } else if ([fragment respondsToSelector:@selector(proxyForJson)]) {
102
- [self appendValue:[fragment proxyForJson] into:json];
103
-
104
- } else {
105
- [self addErrorWithCode:EUNSUPPORTED description:[NSString stringWithFormat:@"JSON serialisation not supported for %@", [fragment class]]];
106
- return NO;
107
- }
108
- return YES;
109
- }
110
-
111
- - (BOOL)appendArray:(NSArray*)fragment into:(NSMutableString*)json {
112
- if (maxDepth && ++depth > maxDepth) {
113
- [self addErrorWithCode:EDEPTH description: @"Nested too deep"];
114
- return NO;
115
- }
116
- [json appendString:@"["];
117
-
118
- BOOL addComma = NO;
119
- for (id value in fragment) {
120
- if (addComma)
121
- [json appendString:@","];
122
- else
123
- addComma = YES;
124
-
125
- if ([self humanReadable])
126
- [json appendString:[self indent]];
127
-
128
- if (![self appendValue:value into:json]) {
129
- return NO;
130
- }
131
- }
132
-
133
- depth--;
134
- if ([self humanReadable] && [fragment count])
135
- [json appendString:[self indent]];
136
- [json appendString:@"]"];
137
- return YES;
138
- }
139
-
140
- - (BOOL)appendDictionary:(NSDictionary*)fragment into:(NSMutableString*)json {
141
- if (maxDepth && ++depth > maxDepth) {
142
- [self addErrorWithCode:EDEPTH description: @"Nested too deep"];
143
- return NO;
144
- }
145
- [json appendString:@"{"];
146
-
147
- NSString *colon = [self humanReadable] ? @" : " : @":";
148
- BOOL addComma = NO;
149
- NSArray *keys = [fragment allKeys];
150
- if (self.sortKeys)
151
- keys = [keys sortedArrayUsingSelector:@selector(compare:)];
152
-
153
- for (id value in keys) {
154
- if (addComma)
155
- [json appendString:@","];
156
- else
157
- addComma = YES;
158
-
159
- if ([self humanReadable])
160
- [json appendString:[self indent]];
161
-
162
- if (![value isKindOfClass:[NSString class]]) {
163
- [self addErrorWithCode:EUNSUPPORTED description: @"JSON object key must be string"];
164
- return NO;
165
- }
166
-
167
- if (![self appendString:value into:json])
168
- return NO;
169
-
170
- [json appendString:colon];
171
- if (![self appendValue:[fragment objectForKey:value] into:json]) {
172
- [self addErrorWithCode:EUNSUPPORTED description:[NSString stringWithFormat:@"Unsupported value for key %@ in object", value]];
173
- return NO;
174
- }
175
- }
176
-
177
- depth--;
178
- if ([self humanReadable] && [fragment count])
179
- [json appendString:[self indent]];
180
- [json appendString:@"}"];
181
- return YES;
182
- }
183
-
184
- - (BOOL)appendString:(NSString*)fragment into:(NSMutableString*)json {
185
-
186
- static NSMutableCharacterSet *kEscapeChars;
187
- if( ! kEscapeChars ) {
188
- kEscapeChars = [[NSMutableCharacterSet characterSetWithRange: NSMakeRange(0,32)] retain];
189
- [kEscapeChars addCharactersInString: @"\"\\"];
190
- }
191
-
192
- [json appendString:@"\""];
193
-
194
- NSRange esc = [fragment rangeOfCharacterFromSet:kEscapeChars];
195
- if ( !esc.length ) {
196
- // No special chars -- can just add the raw string:
197
- [json appendString:fragment];
198
-
199
- } else {
200
- NSUInteger length = [fragment length];
201
- for (NSUInteger i = 0; i < length; i++) {
202
- unichar uc = [fragment characterAtIndex:i];
203
- switch (uc) {
204
- case '"': [json appendString:@"\\\""]; break;
205
- case '\\': [json appendString:@"\\\\"]; break;
206
- case '\t': [json appendString:@"\\t"]; break;
207
- case '\n': [json appendString:@"\\n"]; break;
208
- case '\r': [json appendString:@"\\r"]; break;
209
- case '\b': [json appendString:@"\\b"]; break;
210
- case '\f': [json appendString:@"\\f"]; break;
211
- default:
212
- if (uc < 0x20) {
213
- [json appendFormat:@"\\u%04x", uc];
214
- } else {
215
- CFStringAppendCharacters((CFMutableStringRef)json, &uc, 1);
216
- }
217
- break;
218
-
219
- }
220
- }
221
- }
222
-
223
- [json appendString:@"\""];
224
- return YES;
225
- }
226
-
227
-
228
- @end