better logic for rs_normalizedURLString
This commit is contained in:
parent
2d742b922e
commit
3dd74ce148
|
@ -129,20 +129,41 @@ NSString *RSStringReplaceAll(NSString *stringToSearch, NSString *searchFor, NSSt
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
given a URL that could be prefixed with 'feed:' or 'feeds:',
|
||||||
|
convert it to a URL that begins with 'http:' or 'https:'
|
||||||
|
|
||||||
|
Note: must handle edge case (like boingboing.net) where the feed URL is feed:http://boingboing.net/feed
|
||||||
|
|
||||||
|
Strategy:
|
||||||
|
1) note whether or not this is a feed: or feeds: or other prefix
|
||||||
|
2) strip the feed: or feeds: prefix
|
||||||
|
3) if the resulting string is not prefixed with http: or https:, then add http:// as a prefix
|
||||||
|
|
||||||
|
*/
|
||||||
- (NSString *)rs_normalizedURLString {
|
- (NSString *)rs_normalizedURLString {
|
||||||
|
|
||||||
NSString *s = [self rs_stringByTrimmingWhitespace];
|
NSString *s = [self rs_stringByTrimmingWhitespace];
|
||||||
|
|
||||||
static NSString *feedPrefix = @"feed:";
|
static NSString *feedPrefix = @"feed:";
|
||||||
static NSString *feedsPrefix = @"feeds:";
|
static NSString *feedsPrefix = @"feeds:";
|
||||||
static NSString *httpPrefix = @"http:";
|
static NSString *httpPrefix = @"http";
|
||||||
static NSString *httpsPrefix = @"https:";
|
static NSString *httpsPrefix = @"https";
|
||||||
|
Boolean wasFeeds = false;
|
||||||
|
|
||||||
|
NSString *lowercaseS = [s lowercaseString];
|
||||||
|
if ([lowercaseS hasPrefix:feedPrefix] || [lowercaseS hasPrefix:feedsPrefix]) {
|
||||||
|
if ([lowercaseS hasPrefix:feedsPrefix]) {
|
||||||
|
wasFeeds = true;
|
||||||
|
s = [s rs_stringByStrippingPrefix:feedsPrefix caseSensitive:NO];
|
||||||
|
} else {
|
||||||
|
s = [s rs_stringByStrippingPrefix:feedPrefix caseSensitive:NO];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
s = [s rs_stringByReplacingPrefix:feedPrefix withHTTPPrefix:httpPrefix];
|
lowercaseS = [s lowercaseString];
|
||||||
s = [s rs_stringByReplacingPrefix:feedsPrefix withHTTPPrefix:httpsPrefix];
|
if (![lowercaseS hasPrefix:httpPrefix]) {
|
||||||
|
s = [NSString stringWithFormat: @"%@://%@", wasFeeds ? httpsPrefix : httpPrefix, s];
|
||||||
if (![s hasPrefix:@"http"]) {
|
|
||||||
s = [NSString stringWithFormat:@"http://%@", s];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return s;
|
return s;
|
||||||
|
|
Loading…
Reference in New Issue