Differences From Artifact [669a08ac5c]:
- File
src/OFApplication.m
— part of check-in
[6dff0f5922]
at
2017-01-07 02:34:39
on branch trunk
— Always use "." for the decimal point
This is achieved by replacing the locale's decimal point with "." after
formatting and replacing "." with the locale's decimal point before
parsing.To still use the decimal point from the locale for formatting, the new
flag "," is introduced to formats. This is useful for just printing a
string to the user that is not saved to a file or sent via a network.While this is an ugly hack, there is no better way to do this other than
implementing the functionality of printf and strtod myself, as POSIX
does not specify versions of these that take a locale as an argument.
While this is a lot of work and error-prone, I will most likely end up
doing this eventually.This commit also enables the locale in OFApplication to notice when
things break. As a nice side effect, ofhttp now uses the locale's
decimal point in its user interface. (user: js, size: 10856) [annotate] [blame] [check-ins using]
To Artifact [bbaed6eb9f]:
- File src/OFApplication.m — part of check-in [f12cecf014] at 2017-01-08 02:38:36 on branch trunk — Get native8BitEncoding from locale (user: js, size: 12412) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | #include "config.h" #include <stdio.h> #include <stdlib.h> #include <string.h> #include <locale.h> #include <signal.h> #import "OFApplication.h" #import "OFString.h" #import "OFArray.h" #import "OFDictionary.h" #import "OFSystemInfo.h" #import "OFRunLoop.h" #import "OFRunLoop+Private.h" #import "OFThread.h" #import "OFThread+Private.h" #if defined(OF_MAC_OS_X) # include <crt_externs.h> #elif defined(OF_WINDOWS) # include <windows.h> extern int _CRT_glob; | > > > > > > | 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | #include "config.h" #include <stdio.h> #include <stdlib.h> #include <string.h> #ifdef HAVE_LANGINFO_H # include <langinfo.h> #endif #include <locale.h> #include <signal.h> #import "OFApplication.h" #import "OFString.h" #import "OFArray.h" #import "OFDictionary.h" #import "OFSystemInfo.h" #import "OFRunLoop.h" #import "OFRunLoop+Private.h" #import "OFThread.h" #import "OFThread+Private.h" #import "OFOutOfMemoryException.h" #import "OFOutOfRangeException.h" #if defined(OF_MAC_OS_X) # include <crt_externs.h> #elif defined(OF_WINDOWS) # include <windows.h> extern int _CRT_glob; |
︙ | ︙ | |||
62 63 64 65 66 67 68 69 70 71 72 73 74 75 | - (void)OF_setArgumentCount: (int)argc andWideArgumentValues: (wchar_t*[])argv; #endif - (void)OF_run; @end static OFApplication *app = nil; static void atexitHandler(void) { id <OFApplicationDelegate> delegate = [app delegate]; if ([delegate respondsToSelector: @selector(applicationWillTerminate)]) | > > | 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | - (void)OF_setArgumentCount: (int)argc andWideArgumentValues: (wchar_t*[])argv; #endif - (void)OF_run; @end static OFApplication *app = nil; extern of_string_encoding_t of_system_info_native_8bit_encoding; extern OFString *of_system_info_decimal_point; static void atexitHandler(void) { id <OFApplicationDelegate> delegate = [app delegate]; if ([delegate respondsToSelector: @selector(applicationWillTerminate)]) |
︙ | ︙ | |||
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | of_application_main(int *argc, char **argv[], Class cls) { id <OFApplicationDelegate> delegate; #ifdef OF_WINDOWS wchar_t **wargv, **wenvp; int wargc, si = 0; #endif setlocale(LC_ALL, ""); if ([cls isSubclassOfClass: [OFApplication class]]) { fprintf(stderr, "FATAL ERROR:\n Class %s is a subclass of " "class OFApplication, but class\n %s was specified as " "application delegate!\n Most likely, you wanted to " "subclass OFObject instead or specified\n the wrong class " "with OF_APPLICATION_DELEGATE().\n", class_getName(cls), class_getName(cls)); | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 | of_application_main(int *argc, char **argv[], Class cls) { id <OFApplicationDelegate> delegate; #ifdef OF_WINDOWS wchar_t **wargv, **wenvp; int wargc, si = 0; #endif #ifdef HAVE_LANGINFO_H char *codeset, *lowerCodeset; size_t codesetLen; #endif setlocale(LC_ALL, ""); #ifdef HAVE_LANGINFO_H codeset = nl_langinfo(CODESET); codesetLen = strlen(codeset); if (SIZE_MAX - codesetLen < 1) @throw [OFOutOfRangeException exception]; if ((lowerCodeset = malloc(codesetLen + 1)) == NULL) @throw [OFOutOfMemoryException exceptionWithRequestedSize: codesetLen + 1]; for (size_t i = 0; i < codesetLen; i++) lowerCodeset[i] = of_ascii_tolower(codeset[i]); if (strcmp(lowerCodeset, "utf8") == 0 || strcmp(lowerCodeset, "utf-8") == 0) of_system_info_native_8bit_encoding = OF_STRING_ENCODING_UTF_8; else if (strcmp(lowerCodeset, "ascii") == 0 || strcmp(lowerCodeset, "us-ascii") == 0) of_system_info_native_8bit_encoding = OF_STRING_ENCODING_ASCII; else if (strcmp(lowerCodeset, "iso8859-1") == 0 || strcmp(lowerCodeset, "iso-8859-1") == 0) of_system_info_native_8bit_encoding = OF_STRING_ENCODING_ISO_8859_1; else if (strcmp(lowerCodeset, "iso8859-15") == 0 || strcmp(lowerCodeset, "iso-8859-15") == 0) of_system_info_native_8bit_encoding = OF_STRING_ENCODING_ISO_8859_15; free(lowerCodeset); #endif of_system_info_decimal_point = [[OFString alloc] initWithCString: localeconv()->decimal_point encoding: of_system_info_native_8bit_encoding]; if ([cls isSubclassOfClass: [OFApplication class]]) { fprintf(stderr, "FATAL ERROR:\n Class %s is a subclass of " "class OFApplication, but class\n %s was specified as " "application delegate!\n Most likely, you wanted to " "subclass OFObject instead or specified\n the wrong class " "with OF_APPLICATION_DELEGATE().\n", class_getName(cls), class_getName(cls)); |
︙ | ︙ |