tomaz / appledoc

Objective-c code Apple style documentation set generator.
http://gentlebytes.com
4.19k stars 645 forks source link

Added support for ISO-8859-1 encoded files #629

Closed 0bmxa closed 6 years ago

0bmxa commented 6 years ago

Hello! I added (very simple) support for reading ISO-8859-1 (in addition to UTF-8) encoded source files.

Changes If reading a file with NSUTF8StringEncoding fails, it essentially tries to read the file again with NSISOLatin1StringEncoding.

Possible issues I know this approach is not very flexible, so In case more encodings should be supported, this should be done differently. But I guess not too many encodings are needed anyways.

Background I needed this for a side project, where I try to render all Apple SDK headers to HTML, cause apparently quite a few of those headers are in ISO-8859-1 encoding.

tomaz commented 6 years ago

Nice, thanks!

I'm fine with code as is, but those ifs can potentially start "piling-up" with additional encodings in the future. Can you add a comment in there, something along the lines "Convert this to more managable handling when new encoding support needs adding".

Of course, if you feel for it, the ultimate solution would be to setup example for adding additional encoding in this PR. For example:

NSError *error;
NSString *string;
NSArray *encodings = @[ @(NSUTF8StringEncoding), @(NSISOLatin1StringEncoding) ];
for (NSNumber *encoding in encodings) {
    string = ....
    if (!error) break;
}
if (error) {
    ...
}

Well, if you feel for it, otherwise I'll merge as is too - with comment as suggested above :)

0bmxa commented 6 years ago

Thanks for your feedback! You are totally right, the previous solution was not really future proof or anything. I updated the PR now according to your suggestion!

tomaz commented 6 years ago

Cool, thanks! Merged now!