Permalink
Browse files

Merge pull request #2 from GunioRobot/clean

Automatically Removed Whitespace
  • Loading branch information...
2 parents 989f65e + 61758a3 commit ff5dafb33e885999597e61ca1891aea0e3fe7cc1 @patrickt committed Aug 22, 2014
Showing with 22 additions and 22 deletions.
  1. +4 −4 src/YAMLKit.m
  2. +3 −3 src/YKEmitter.m
  3. +15 −15 src/YKParser.m
View
@@ -24,17 +24,17 @@ + (id)loadFromString:(NSString *)str
+ (id)loadFromFile:(NSString *)path
{
- NSString *contents = [NSString stringWithContentsOfFile:path
- encoding:NSUTF8StringEncoding
+ NSString *contents = [NSString stringWithContentsOfFile:path
+ encoding:NSUTF8StringEncoding
error:NULL];
if(contents == nil) return nil; // if there was an error reading from the file
return [self loadFromString:contents];
}
+ (id)loadFromURL:(NSURL *)url
{
- NSString *contents = [NSString stringWithContentsOfURL:url
- encoding:NSUTF8StringEncoding
+ NSString *contents = [NSString stringWithContentsOfURL:url
+ encoding:NSUTF8StringEncoding
error:NULL];
if(contents == nil) return nil; // if there was an error reading from the URL
return [self loadFromString:contents];
View
@@ -22,10 +22,10 @@ - (id)init
if((self = [super init])) {
memset(&emitter, 0, sizeof(emitter));
yaml_emitter_initialize(&emitter);
-
+
buffer = [NSMutableData data];
// Coincidentally, the order of arguments to CFDataAppendBytes are just right
- // such that if I pass the buffer as the data parameter, I can just use
+ // such that if I pass the buffer as the data parameter, I can just use
// a pointer to CFDataAppendBytes to tell the emitter to write to the NSMutableData.
yaml_emitter_set_output(&emitter, (yaml_write_handler_t*)CFDataAppendBytes, buffer);
[self setUsesExplicitDelimiters:NO];
@@ -50,7 +50,7 @@ - (void)emitItem:(id)item
- (int)_writeItem:(id)item toDocument:(yaml_document_t *)doc
{
int nodeID = 0;
- // #keyEnumerator covers NSMapTable/NSHashTable/NSDictionary
+ // #keyEnumerator covers NSMapTable/NSHashTable/NSDictionary
if([item respondsToSelector:@selector(keyEnumerator)]) {
// Add a mapping node.
nodeID = yaml_document_add_mapping(doc, (yaml_char_t *)YAML_DEFAULT_MAPPING_TAG, YAML_ANY_MAPPING_STYLE);
View
@@ -37,7 +37,7 @@ - (BOOL)readFile:(NSString *)path
[self reset];
fileInput = fopen([path fileSystemRepresentation], "r");
readyToParse = ((fileInput != NULL) && (yaml_parser_initialize(&parser)));
- if(readyToParse)
+ if(readyToParse)
yaml_parser_set_input_file(&parser, fileInput);
return readyToParse;
}
@@ -47,7 +47,7 @@ - (BOOL)readString:(NSString *)str
[self reset];
stringInput = [str UTF8String];
readyToParse = yaml_parser_initialize(&parser);
- if(readyToParse)
+ if(readyToParse)
yaml_parser_set_input_string(&parser, (const unsigned char *)stringInput, [str length]);
return readyToParse;
}
@@ -69,9 +69,9 @@ - (NSArray *)parseWithError:(NSError **)e
*e = [self _constructErrorFromParser:NULL];
return nil;
}
- }
+ }
}
-
+
while(!done) {
if(!yaml_parser_parse(&parser, &event)) {
if(e != NULL) {
@@ -84,7 +84,7 @@ - (NSArray *)parseWithError:(NSError **)e
case YAML_SCALAR_EVENT:
obj = [self _interpretObjectFromEvent:event];
temp = [stack lastObject];
-
+
if([temp isKindOfClass:[NSArray class]]) {
[temp addObject:obj];
} else if([temp isKindOfClass:[NSDictionary class]]) {
@@ -100,7 +100,7 @@ - (NSArray *)parseWithError:(NSError **)e
}
[[stack lastObject] setObject:obj forKey:temp];
}
-
+
break;
case YAML_SEQUENCE_START_EVENT:
[stack addObject:[NSMutableArray array]];
@@ -113,7 +113,7 @@ - (NSArray *)parseWithError:(NSError **)e
// TODO: Check for retain count errors.
temp = [stack lastObject];
[stack removeLastObject];
-
+
id last = [stack lastObject];
if(last == nil) {
[stack addObject:temp];
@@ -130,7 +130,7 @@ - (NSArray *)parseWithError:(NSError **)e
*e = [self _constructErrorFromParser:NULL];
return nil;
}
- }
+ }
[[stack lastObject] setObject:temp forKey:obj];
}
break;
@@ -150,10 +150,10 @@ - (id)_interpretObjectFromEvent:(yaml_event_t)event
{
NSString *stringValue = [NSString stringWithUTF8String:(const char *)event.data.scalar.value];
id obj = stringValue;
-
+
if(event.data.scalar.style == YAML_PLAIN_SCALAR_STYLE) {
NSScanner *scanner = [NSScanner scannerWithString:obj];
-
+
// Integers are automatically casted unless given a !!str tag. I think.
if([scanner scanDouble:NULL] && [scanner scanLocation] == [stringValue length]) {
obj = [NSNumber numberWithDouble:[obj doubleValue]];
@@ -176,7 +176,7 @@ - (NSError *)_constructErrorFromParser:(yaml_parser_t *)p
{
int code = 0;
NSMutableDictionary *data = [NSMutableDictionary dictionary];
-
+
if(p != NULL) {
// actual parser error
code = p->error;
@@ -195,26 +195,26 @@ - (NSError *)_constructErrorFromParser:(yaml_parser_t *)p
default: break;
}
[data setObject:[NSNumber numberWithInt:enc] forKey:NSStringEncodingErrorKey];
-
+
[data setObject:[NSString stringWithUTF8String:p->problem] forKey:YKProblemDescriptionKey];
[data setObject:[NSNumber numberWithInt:p->problem_offset] forKey:YKProblemOffsetKey];
[data setObject:[NSNumber numberWithInt:p->problem_value] forKey:YKProblemValueKey];
[data setObject:[NSNumber numberWithInt:p->problem_mark.line] forKey:YKProblemLineKey];
[data setObject:[NSNumber numberWithInt:p->problem_mark.index] forKey:YKProblemIndexKey];
[data setObject:[NSNumber numberWithInt:p->problem_mark.column] forKey:YKProblemColumnKey];
-
+
[data setObject:[NSString stringWithUTF8String:p->context] forKey:YKErrorContextDescriptionKey];
[data setObject:[NSNumber numberWithInt:p->context_mark.line] forKey:YKErrorContextLineKey];
[data setObject:[NSNumber numberWithInt:p->context_mark.column] forKey:YKErrorContextColumnKey];
[data setObject:[NSNumber numberWithInt:p->context_mark.index] forKey:YKErrorContextIndexKey];
-
+
} else if(readyToParse) {
[data setObject:NSLocalizedString(@"Internal assertion failed, possibly due to specially malformed input.", @"") forKey:NSLocalizedDescriptionKey];
} else {
[data setObject:NSLocalizedString(@"YAML parser was not ready to parse.", @"") forKey:NSLocalizedFailureReasonErrorKey];
[data setObject:NSLocalizedString(@"Did you remember to call readFile: or readString:?", @"") forKey:NSLocalizedDescriptionKey];
}
-
+
return [[NSError alloc] initWithDomain:YKErrorDomain code:code userInfo:data];
}

0 comments on commit ff5dafb

Please sign in to comment.