Skip to content

Commit

Permalink
ocapigen:
Browse files Browse the repository at this point in the history
- OCYAMLParser: remove encapsulating "" and '' for values and keys
- OCCodeGenerator: add support for "@" property names
  • Loading branch information
felix-schwarz committed Dec 20, 2024
1 parent 565a5b5 commit 4711847
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
13 changes: 13 additions & 0 deletions tools/ocapigen/Code Generation/Generator/OCCodeGenerator.m
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,19 @@ - (OCCodeNativePropertyName)nativeNameForProperty:(OCSchemaProperty *)property i
}
}

if ([property.name hasPrefix:@"@"])
{
NSRange dotRange;

NSString *name = [property.name substringFromIndex:1];

while ((dotRange = [name rangeOfString:@"."]).location != NSNotFound) {
name = [[name substringToIndex:dotRange.location] stringByAppendingString:[name substringFromIndex:dotRange.location+1].withCapitalizedFirstChar];
};

return (name);
}

return (property.name);
}

Expand Down
17 changes: 17 additions & 0 deletions tools/ocapigen/YAML Parser/OCYAMLParser.m
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,18 @@ - (void)parse
NSString *name = [lineContent substringToIndex:splitPoint.location];
NSString *value = [[lineContent substringFromIndex:splitPoint.location+1] stringByTrimmingCharactersInSet:whitespaceCharSet];

// Sanitize name
if ([name hasPrefix:@"'"] && [name hasSuffix:@"'"] && (name.length > 1))
{
// Remove ''
name = [name substringWithRange:NSMakeRange(1, name.length-2)];
}
if ([name hasPrefix:@"\""] && [name hasSuffix:@"\""] && (name.length > 1))
{
// Remove ''
name = [name substringWithRange:NSMakeRange(1, name.length-2)];
}

// Sanitize value
if ([value isEqual:@""]) { value = nil; }

Expand All @@ -139,6 +151,11 @@ - (void)parse
// Remove ''
value = [value substringWithRange:NSMakeRange(1, value.length-2)];
}
if ([value hasPrefix:@"\""] && [value hasSuffix:@"\""] && (value.length > 1))
{
// Remove ''
value = [value substringWithRange:NSMakeRange(1, value.length-2)];
}

// Create node for line
OCYAMLNode *node = [[OCYAMLNode alloc] initWithName:name value:value];
Expand Down

0 comments on commit 4711847

Please sign in to comment.