Discussion Forums  >  Plugins, Customizing, Source Code

Replies: 3    Views: 52

us_david
Code is Art
Profile
Posts: 41
Reg: Dec 27, 2010
San Francisco
410
09/15/13 08:49 PM (12 years ago)

Encoding other than uft-8

I digged deeper into the support of encoding other than utf-8, for example, gb2312, which is used a lot in China. I found that the core of BT inherently does not support encoding other than utf-8. The basic function/methods in BT_fileManager (for example its: readTextFileFromCacheWithEncoding and saveTextFileFromCacheWithEncoding) or BT_downloader (-connectionDidFinishLoading method) assuming uft-8 encoding. How to detect the encoding in BT_downloader's -connectionDidFinishLoading method and convert the encoding to utf-8 if it's not? Any one has suggestion on how to support gb2312 or encoding other than utf-8? All of above is in regard to IOS platform. feng
 
Cakebit
Code is Art
Profile
Posts: 502
Reg: Dec 15, 2010
In your local b...
16,520
like
09/16/13 12:09 PM (12 years ago)
Try searching Google (https://www.google.com/search?q=utf-8+to+gb2312) There are many sites that can convert utf-8 to gb2312 encoding.
 
us_david
Code is Art
Profile
Posts: 41
Reg: Dec 27, 2010
San Francisco
410
like
09/16/13 08:06 PM (12 years ago)
Hello, I have made changes to BT core to support GB2312 and the same idea can be used to support other none utf-8 encoding. The following is a hi-light of the changes for IOS: in BT_downloader.m's connectionDidFinishLoading:(NSURLConnection *)connection method, when saving the downloaded result is not utf-8, the current solution is to save it in "NSISOLatin1StringEncoding", I modified code to do a little detection of the encoding and then use: CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingGB_18030_2000) to convert the current encoding and change it to utf-8, then save the file (saveTextFileToCacheWithEncoding). Replace "kCFStringEncodingGB_18030_2000" with your encoding. Then use: [NSString initWithData:[newdata dataUsingEncoding:NSUTF8StringEncoding] ] to do teh actual conversion. Hope this will help anyone who needs it. If you need details, write to me. There is a test gb2312 URL that you can use it to test your code: http://news.qq.com/newsgn/rss_newsgn.xml Here comes another question: How do you make patch to BT Core? Next time when I download the code, my change is gone and I would need to patch it manually... any better solutions or how would you do it if you have made changes to BT Core? Regards, Feng
 
Cakebit
Code is Art
Profile
Posts: 502
Reg: Dec 15, 2010
In your local b...
16,520
like
09/16/13 08:09 PM (12 years ago)
Hi us_david, That is the one problem with "Open Source" software is once it updates your changes normally don't transfer. Buzztouch probably will improve (over time) in areas like these so It works like Wordpress when autoupdating :D
 

Login + Screen Name Required to Post

pointerLogin to participate so you can start earning points. Once you're logged in (and have a screen name entered in your profile), you can subscribe to topics, follow users, and start learning how to make apps like the pros.