开发者

Does Cocoa's CFHost support IDNs?

开发者 https://www.devze.com 2023-03-27 02:09 出处:网络
WINAPI ha开发者_C百科s methods to convert Unicode host names to Punycode. Does Cocoa/Cocoa Touch have a similar mechanism?There\'s a little hack that works without any external libraries. Assuming you

WINAPI ha开发者_C百科s methods to convert Unicode host names to Punycode. Does Cocoa/Cocoa Touch have a similar mechanism?


There's a little hack that works without any external libraries. Assuming you have a Unicode URL in theUrl, you can do:

NSURL *urlToLoad = nil;
NSPasteboard * pasteboard = [NSPasteboard pasteboardWithName:@"RandomPB"];
[pasteboard declareTypes:[NSArray arrayWithObject:NSStringPboardType] owner:nil];
@try
{
    if ([pasteboard setString:theUrl forType:NSStringPboardType])
        urlToLoad = [WebView URLFromPasteboard:pasteboard];
}
@catch (NSException * exception)
{
    urlToLoad = nil;
    NSLog(@"Can't create URL from string '%@'.", theUrl);
}
return urlToLoad;


Check out SBPunyCode (updated link)

0

精彩评论

暂无评论...
验证码 换一张
取 消