Skip to content

changing QuickLookCSV's trying encoding #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
kkdd opened this issue Sep 13, 2014 · 2 comments
Open

changing QuickLookCSV's trying encoding #16

kkdd opened this issue Sep 13, 2014 · 2 comments

Comments

@kkdd
Copy link
Contributor

kkdd commented Sep 13, 2014

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);
+ }
@p2
Copy link
Owner

p2 commented Sep 13, 2014

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?

@kkdd
Copy link
Contributor Author

kkdd commented Sep 18, 2014

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.

@p2 p2 added the enhancement label Sep 21, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants