FTP目录乱码用GBK
2014-04-29 13:26
239 查看
NSStringEncoding gbkEncoding =CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingGB_18030_2000);
NSDictionary * entryToAdd;
entryToAdd = [self entryByReencodingNameInEntry:( NSDictionary *) thisEntry encoding:gbkEncoding];
- (NSDictionary *)entryByReencodingNameInEntry:(NSDictionary *)entry encoding:(NSStringEncoding)newEncoding//转码,解决乱码问题
// CFFTPCreateParsedResourceListing always interprets the file name as MacRoman,
// which is clearly bogus <rdar://problem/7420589>. This code attempts to fix
// that by converting the Unicode name back to MacRoman (to get the original bytes;
// this works because there's a lossless round trip between MacRoman and Unicode)
// and then reconverting those bytes to Unicode using the encoding provided.
{
NSDictionary * result;
NSString * name;
NSData * nameData;
NSString * newName;
newName = nil;
// Try to get the name, convert it back to MacRoman, and then reconvert it
// with the preferred encoding.
name = [entry objectForKey:(id) kCFFTPResourceName];
if (name != nil) {
assert([name isKindOfClass:[NSString class]]);
nameData = [name dataUsingEncoding:NSMacOSRomanStringEncoding];
if (nameData != nil) {
newName = [[NSString alloc] initWithData:nameData encoding:newEncoding];
}
}
// If the above failed, just return the entry unmodified. If it succeeded,
// make a copy of the entry and replace the name with the new name that we
// calculated.
if (newName == nil) {
//assert(NO); // in the debug builds, if this fails, we should investigate why
result = (NSDictionary *) entry;
} else {
NSMutableDictionary * newEntry;
newEntry = [entry mutableCopy];
assert(newEntry != nil);
[newEntry setObject:newName forKey:(id) kCFFTPResourceName];
result = newEntry;
}
return result;
}
NSDictionary * entryToAdd;
entryToAdd = [self entryByReencodingNameInEntry:( NSDictionary *) thisEntry encoding:gbkEncoding];
- (NSDictionary *)entryByReencodingNameInEntry:(NSDictionary *)entry encoding:(NSStringEncoding)newEncoding//转码,解决乱码问题
// CFFTPCreateParsedResourceListing always interprets the file name as MacRoman,
// which is clearly bogus <rdar://problem/7420589>. This code attempts to fix
// that by converting the Unicode name back to MacRoman (to get the original bytes;
// this works because there's a lossless round trip between MacRoman and Unicode)
// and then reconverting those bytes to Unicode using the encoding provided.
{
NSDictionary * result;
NSString * name;
NSData * nameData;
NSString * newName;
newName = nil;
// Try to get the name, convert it back to MacRoman, and then reconvert it
// with the preferred encoding.
name = [entry objectForKey:(id) kCFFTPResourceName];
if (name != nil) {
assert([name isKindOfClass:[NSString class]]);
nameData = [name dataUsingEncoding:NSMacOSRomanStringEncoding];
if (nameData != nil) {
newName = [[NSString alloc] initWithData:nameData encoding:newEncoding];
}
}
// If the above failed, just return the entry unmodified. If it succeeded,
// make a copy of the entry and replace the name with the new name that we
// calculated.
if (newName == nil) {
//assert(NO); // in the debug builds, if this fails, we should investigate why
result = (NSDictionary *) entry;
} else {
NSMutableDictionary * newEntry;
newEntry = [entry mutableCopy];
assert(newEntry != nil);
[newEntry setObject:newName forKey:(id) kCFFTPResourceName];
result = newEntry;
}
return result;
}
相关文章推荐
- Appach FTPClient 遍历服务器目录文件,文件名奇数中文乱码 UTF-8 GBK ISO-8859-1
- FtpClient在创建中文目录文件名中的中文显示乱码解决方法
- 20100722 使用FTP客户端(filezilla)中文目录显示乱码无法正常使用解决
- FTPClient上传 中文目录、中文文件名乱码问题
- Indy10 FTP列目录乱码问题
- sun.net.ftp.FtpClient 中文目录乱码问题解决
- Java中FTPClient上传中文目录、中文文件名乱码问题解决方法
- IOS开发FTP中文目录和文件名乱码解决办法
- Debian : 解决filezilla由于ftp目录乱码引起的改名失败
- 【Java】解决FTPClient上传中文目录出现中文名乱码问题
- firefox访问ftp中文目录乱码(未解决)
- 解决Firefox访问FTP中文目录乱码的方法
- MFC 遍历FTP服务器目录中文乱码问题
- linux下将中文文件名文件cp到windows目录下后文件名乱码问题的解决
- python实现ftp中的乱码问题
- sublime text 2支持gbk编码-解决浏览器中文乱码的问题
- Linux下的ftp工具及中文乱码的解决
- gbk转utf-8出现乱码
- vsftp设置不同用户登录ftp的根目录不同
- javadoc时候乱码-编码 GBK 的不可映射字符