-(NSURL*)smartURLForString:(NSString*)str
{
NSURL * result;
NSString *trimmedStr;
NSRange schemeMarkerRange;
NSString *scheme;
result = nil;
// 去除空白
trimmedStr = [strstringByT rimmingCharactersInSet:[NSCharacterSetwhitespaceCharacterSet]];
if ( (trimmedStr != nil) && (trimmedStr.length != 0) ) {
schemeMarkerRange = [trimmedStr rangeOfString:@"://"];
if(schemeMarkerRange.location ==NSNotFound) {
result =[NSURL URLWithString:[NSString stringWithFormat:@"http://%@", trimmedStr]];
} else {
scheme =[trimmedStr substringWithRange:NSMakeRange(0, schemeMarkerRange.location)];
assert(scheme != nil);
if( ([scheme compare:@"http" options:NSCaseInsensitiveSearch] == NSOrderedSame)
|| ([schemecompare:@"https" options:NSCaseInsensitiveSearch] == NSOrderedSame) ) {
result = [NSURL URLWithString:trimmedStr];
}else {
//It looks like this is some unsupported URL scheme.
}
}
}
return result;
}