Skip to content

Commit

Permalink
misc
Browse files Browse the repository at this point in the history
  • Loading branch information
nst committed May 28, 2015
1 parent 90e0824 commit c7538fa
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
29 changes: 12 additions & 17 deletions model/RTBTypeDecoder2.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ - (instancetype)init {
self.simpeTypesDictionary = @{@"@":@"id",
@"#":@"Class",
@":":@"SEL",
@"c":@"char", // BOOL
@"c":@"BOOL", // char
@"C":@"unsigned char",
@"s":@"short",
@"S":@"unsigned short",
Expand Down Expand Up @@ -132,25 +132,17 @@ - (NSDictionary *)decodeStruct:(NSString *)encodedType {
}

NSString *s = [encodedType substringWithRange:NSMakeRange(1, closeIndex-1)]; // CGPoint="x"d"y"d

// if([s containsString:@"="]) {
//
// }

NSString *name = [[self class] nameBeforeEqualInString:s]; // CGPoint

NSString *longTail = [encodedType substringFromIndex:closeIndex+1];

NSString *structTail = @"";
if(name) {
NSUInteger equalLength = name ? 1 : 0;
NSUInteger rangeLocation = [name length] + equalLength; // {asd=
NSUInteger rangeLength = [s length] - rangeLocation;
structTail = [s substringWithRange:NSMakeRange(rangeLocation, rangeLength)]; // "origin"{CGPoint="x"d"y"d}"size"{CGSize="width"d"height"d}
} else {
name = s; // found '{NAME}' instead of '{NAME=TYPE}'
// structTail = s;
}
NSUInteger equalSignLength = name ? 1 : 0;
NSUInteger rangeLocation = [name length] + equalSignLength; // {asd=
NSUInteger rangeLength = [s length] - rangeLocation;
NSString *structTail = [s substringWithRange:NSMakeRange(rangeLocation, rangeLength)]; // "origin"{CGPoint="x"d"y"d}"size"{CGSize="width"d"height"d}

NSLog(@"- %@", structTail);

NSMutableArray *typesInStruct = [NSMutableArray array];

Expand Down Expand Up @@ -238,10 +230,12 @@ - (NSDictionary *)decodeType:(NSString *)encodedType {
return [self decodeStruct:encodedType];
} else if([firstCharacter isEqualToString:@"["]) {
return [self decodeArray:encodedType];
} else if (_simpeTypesDictionary[firstCharacter]) {
return [self decodeSimpleType:encodedType];
} else if ([firstCharacter isEqualToString:@"\""]) {
return [self decodeName:encodedType];
} else if (_simpeTypesDictionary[firstCharacter]) {
return [self decodeSimpleType:encodedType];
} else {
return [self decodeName:[NSString stringWithFormat:@"\"%@\"", encodedType]];
}

NSAssert(NO, @"cannot decode type %@", encodedType);
Expand All @@ -250,6 +244,7 @@ - (NSDictionary *)decodeType:(NSString *)encodedType {
}

+ (NSString *)descriptionForTypeDictionary:(NSDictionary *)d {

if([d[@"kind"] isEqualToString:@"POINTER"]) {
return [NSString stringWithFormat:@"%@*", [self descriptionForTypeDictionary:d[@"encodedType"]]];
} else if ([d[@"kind"] isEqualToString:@"SIMPLE_TYPE"]) {
Expand Down
11 changes: 10 additions & 1 deletion runtime_cli/UnitTests/RTBTypeDecoder2Tests.m
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ - (void)testComplicatedType1 {

NSLog(@"-- %@", d);



/*
struct TFCGImage {
struct TRef<CGImage *, TRetainReleasePolicy<CGImageRef> > {
Expand All @@ -138,7 +140,14 @@ - (void)testStructInStruct {

NSDictionary *d = [td decodeType:@"{CGRect=\"origin\"{CGPoint=\"x\"d\"y\"d}\"size\"{CGSize=\"width\"d\"height\"d}}"]; // OS X "NSLayerContentsFacet"

NSLog(@"-- %@", d);
//NSLog(@"-- %@", d);

NSArray *encodedTypes = d[@"encodedTypes"];

NSLog(@"-- %@", encodedTypes);

XCTAssertEquals([encodedTypes count], 4);


//XCTAssertEqual(d[@""], <#expression2, ...#>)

Expand Down

0 comments on commit c7538fa

Please sign in to comment.