Skip to content

Instantly share code, notes, and snippets.

@0xced
Created May 20, 2011 13:22
Show Gist options
  • Select an option

  • Save 0xced/982878 to your computer and use it in GitHub Desktop.

Select an option

Save 0xced/982878 to your computer and use it in GitHub Desktop.
Swiss Franc currency symbol
#import <Foundation/Foundation.h>
// Swiss law on money (german): http://www.admin.ch/ch/d/sr/9/941.101.de.pdf
// Swiss law on money (french): http://www.admin.ch/ch/f/rs/9/941.101.fr.pdf
int main(int argc, const char *argv[])
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSArray *localeIdentifiers = [NSArray arrayWithObjects:@"de_CH", @"fr_CH", @"it_CH", @"rm_CH", nil];
NSArray *officialCurrencySymbols = [NSArray arrayWithObjects:@"Fr.", @"fr.", @"fr.", @"fr.", nil];
NSNumberFormatter *numberFormatter = [[[NSNumberFormatter alloc] init] autorelease];
for (NSUInteger i = 0; i < [localeIdentifiers count]; i++)
{
NSString *localeIdentifier = [localeIdentifiers objectAtIndex:i];
NSLocale *locale = [[[NSLocale alloc] initWithLocaleIdentifier:localeIdentifier] autorelease];
[numberFormatter setLocale:locale];
NSString *currencySymbol = [numberFormatter currencySymbol];
NSString *officialCurrencySymbol = [officialCurrencySymbols objectAtIndex:i];
BOOL isCorrect = [currencySymbol isEqualToString:officialCurrencySymbol];
NSString *comment = isCorrect ? @"OK" : [NSString stringWithFormat:@"should be \"%@\"", officialCurrencySymbol];
printf("%s: \"%s\" (%s)\n", [localeIdentifier UTF8String], [currencySymbol UTF8String], [comment UTF8String]);
}
[numberFormatter setLocale:nil];
NSString *internationalCurrencySymbol = [numberFormatter internationalCurrencySymbol];
BOOL isCorrect = [internationalCurrencySymbol isEqualToString:@"CHF"];
NSString *comment = isCorrect ? @"OK" : @"should be \"CHF\"";
printf("international: \"%s\" (%s)\n", [internationalCurrencySymbol UTF8String], [comment UTF8String]);
[pool drain];
return 0;
}
all: chf
chf: chf.m
gcc chf.m -o chf -framework Foundation -std=c99
clean:
rm -f chf
@digdog
Copy link
Copy Markdown

digdog commented Jul 22, 2011

Region: US

de_CH: "CHF" (should be "Fr.")
fr_CH: "CHF" (should be "fr.")
it_CH: "CHF" (should be "fr.")
rm_CH: "CHF" (should be "fr.") 
international: "USD" (should be "CHF")

Region: Switzerland (French)

de_CH: "CHF" (should be "Fr.")
fr_CH: "CHF" (should be "fr.")
it_CH: "CHF" (should be "fr.")
rm_CH: "CHF" (should be "fr.")
international: "CHF" (OK)

gcc version 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)
Mac OS X 10.7, Build 11A511, Xcode 4.2 Developer Preview 3 (Lion 4D75)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment