-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathCWHessianTranslator+Private.m
59 lines (52 loc) · 2.16 KB
/
CWHessianTranslator+Private.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//
// CWHessianTranslator+Private.m
// HessianKit
//
// Created by Fredrik Olsson on 2009-09-12.
// Copyright 2009 __MyCompanyName__. All rights reserved.
//
#import "CWHessianTranslator+Private.h"
@implementation CWHessianTranslator (Private)
-(void)setLocalTypeName:(NSString*)localTypeName forDistantTypeName:(NSString*)distantTypeName;
{
[typeNameTranslations setObject:distantTypeName forKey:localTypeName];
}
-(NSString*)distantTypeNameForLocalTypeName:(NSString*)localTypeName;
{
NSString* distantTypeName = [typeNameTranslations objectForKey:localTypeName];
if (distantTypeName == nil) {
NSString* distantTypeName = localTypeName;
if (_localTypeNamePrefix != nil && [localTypeName hasPrefix:_localTypeNamePrefix]) {
distantTypeName = [localTypeName substringFromIndex:[_localTypeNamePrefix length]];
}
if (_distantTypeNamePrefix != nil) {
distantTypeName = [_distantTypeNamePrefix stringByAppendingString:distantTypeName];
}
[self setLocalTypeName:localTypeName forDistantTypeName:distantTypeName];
}
return distantTypeName;
}
-(NSString*)localTypeNameForDistantTypeName:(NSString*)distantTypeName;
{
NSArray* knownLocalTypeNames = [typeNameTranslations allKeysForObject:distantTypeName];
if ([knownLocalTypeNames count] > 0) {
return [knownLocalTypeNames objectAtIndex:0];
}
NSString* localTypeName = distantTypeName;
if (_distantTypeNamePrefix != nil && [distantTypeName hasPrefix:_distantTypeNamePrefix]) {
localTypeName = [localTypeName substringFromIndex:[_distantTypeNamePrefix length]];
}
NSInteger lastDotPosition = [localTypeName rangeOfString:@"." options:NSBackwardsSearch].location;
if (lastDotPosition != NSNotFound) {
localTypeName = [localTypeName substringFromIndex:lastDotPosition + 1];
}
if (_localTypeNamePrefix != nil) {
NSString* potentialLocalTypeName = [_localTypeNamePrefix stringByAppendingString:localTypeName];
if (NSProtocolFromString(potentialLocalTypeName) != nil || NSClassFromString(potentialLocalTypeName)) {
localTypeName = potentialLocalTypeName;
}
}
[self setLocalTypeName:localTypeName forDistantTypeName:distantTypeName];
return localTypeName;
}
@end