quicklook-csv
quicklook-csv copied to clipboard
changing QuickLookCSV's trying encoding
Hello,
I would like to set the QuickLookCSV's trying encoding by
$ defaults write com.google.code.quicklookcsv textEncoding Shift_JIS ,
for example.
The source then would be modified as like this:
OSStatus GeneratePreviewForURL(void *thisInterface, QLPreviewRequestRef preview, CFURLRef url, CFStringRef contentTypeUTI, CFDictionaryRef options)
{
:
:
// We could not open the file, probably unknown encoding; try ISO-8859-1
if (!fileString) {
- stringEncoding = NSISOLatin1StringEncoding;
+ stringEncoding = getDefaultEncoding();
fileString = [NSString stringWithContentsOfURL:myURL encoding:stringEncoding error:&theErr];
:
:
}
+ NSStringEncoding getDefaultEncoding()
+ {
+ NSString *enc_name = [NSUserDefaults.standardUserDefaults stringForKey:@"textEncoding"];
+ CFStringEncoding cf_enc = CFStringConvertIANACharSetNameToEncoding((CFStringRef)enc_name);
+ if (cf_enc == kCFStringEncodingInvalidId) {
+ return NSISOLatin1StringEncoding; // ISO-8859-1
+ }
+ return CFStringConvertEncodingToNSStringEncoding(cf_enc);
+ }
Hmm, I don't think it's a good idea to make this a user setting. The encoding depends on the file, not the user's preferences. Can you upload a Shift_JIS-encoded CSV file so one can take a look?
Hello, I will send you a sample Shift_JIS(CP932)-encoded CSV file.
I'm now struggling to extend a StringWithContentsOfURL method as follows: https://github.com/kkdd/quicklook-csv/blob/master/NSString%2BStringWithContentsOfURLExt.m https://github.com/kkdd/quicklook-csv/blob/master/GeneratePreviewForURL.m And I think Japanese Shift_JIS encodings are somewhat in a mess.