@@ -71,19 +71,7 @@ - (NSArray *)parseWithError:(NSError **)e
71
71
done = (event.type == YAML_STREAM_END_EVENT);
72
72
switch (event.type ) {
73
73
case YAML_SCALAR_EVENT:
74
- obj = [NSString stringWithUTF8String: (const char *)event.data.scalar.value];
75
-
76
- if (event.data .scalar .style == YAML_PLAIN_SCALAR_STYLE) {
77
- NSScanner *scanner = [NSScanner scannerWithString: obj];
78
-
79
- // Integers are automatically casted unless given a !!str tag. I think.
80
- if ([scanner scanInt: NULL ]) {
81
- obj = [NSNumber numberWithInt: [obj intValue ]];
82
- } else if ([obj isEqualToString: @" ~" ]) {
83
- obj = [NSNull null ];
84
- }
85
- }
86
-
74
+ obj = [self _interpretObjectFromEvent: event];
87
75
temp = [stack lastObject ];
88
76
89
77
if ([temp isKindOfClass: [NSArray class ]]) {
@@ -145,6 +133,33 @@ - (NSArray *)parseWithError:(NSError **)e
145
133
return stack;
146
134
}
147
135
136
+ // TODO: oof, add tag support.
137
+
138
+ - (id )_interpretObjectFromEvent : (yaml_event_t )event
139
+ {
140
+ id obj = [NSString stringWithUTF8String: (const char *)event.data.scalar.value];
141
+
142
+ if (event.data .scalar .style == YAML_PLAIN_SCALAR_STYLE) {
143
+ NSScanner *scanner = [NSScanner scannerWithString: obj];
144
+
145
+ // Integers are automatically casted unless given a !!str tag. I think.
146
+ if ([scanner scanInt: NULL ]) {
147
+ obj = [NSNumber numberWithInt: [obj intValue ]];
148
+ } else if ([scanner scanDouble: NULL ]) {
149
+ obj = [NSNumber numberWithDouble: [obj doubleValue ]];
150
+ // FIXME: Boolean parsing here is not in accordance with the YAML standards.
151
+ } else if ([obj caseInsensitiveCompare: @" true" ] == NSOrderedSame) {
152
+ obj = [NSNumber numberWithBool: YES ];
153
+ } else if ([obj caseInsensitiveCompare: @" false" ] == NSOrderedSame) {
154
+ obj = [NSNumber numberWithBool: NO ];
155
+ } else if ([obj isEqualToString: @" ~" ]) {
156
+ obj = [NSNull null ];
157
+ }
158
+ // TODO: add date parsing.
159
+ }
160
+ return obj;
161
+ }
162
+
148
163
- (NSError *)_constructErrorFromParser : (yaml_parser_t *)p
149
164
{
150
165
int code = 0 ;
0 commit comments