void number_formatter_platform_data_t::monitor_locale(const dictionary_t&) { auto_locale_t current_locale(::CFLocaleCopyCurrent()); std::string num_format_save(get_format()); formatter_m.reset(::CFNumberFormatterCreate(NULL, current_locale.get(), kCFNumberFormatterNoStyle)); set_format(num_format_save); }
bool completely_valid_number_string_given_current_locale(const std::string& value) { auto_locale_t current_locale(::CFLocaleCopyCurrent()); auto_formatter_t formatter(::CFNumberFormatterCreate(NULL, current_locale.get(), kCFNumberFormatterNoStyle)); ::CFRange range = { 0 }; double result(std::numeric_limits<double>::min()); range.length = value.size(); //::Boolean success = ::CFNumberFormatterGetValueFromString(formatter.get(), explicit_cast<auto_cfstring_t>(value).get(), &range, kCFNumberDoubleType, &result); return static_cast<double>(range.length) == static_cast<double>(value.size()); }
char * _real_gettext_u(const char *domain, const char *msgid1, const char *msgid2, unsigned long int ln, int category, int plural, locale_t loc) { char msgfile[MAXPATHLEN]; /* 1024 */ char mydomain[TEXTDOMAINMAX + 1]; /* 256 + 1 */ char *cur_binding; /* points to current binding in list */ const char *cur_locale; char *cur_domain, *result, *nlspath; char *msgloc, *cb, *cur_domain_binding; char *language; unsigned int n = (unsigned int)ln; /* we don't need long for n */ uint32_t cur_domain_len, cblen; uint32_t hash_domain; struct msg_pack *mp, omp; #ifdef GETTEXT_DEBUG gprintf(0, "*************** _real_gettext_u(\"%s\", \"%s\", " "\"%s\", %d, %d, %d)\n", domain ? domain : "NULL", msgid1 ? msgid1 : "NULL", msgid2 ? msgid2 : "NULL", n, category, plural); gprintf(0, "***************** global_gt: 0x%p\n", global_gt); printgt(global_gt, 1); #endif if (msgid1 == NULL) return (NULL); mp = memset(&omp, 0, sizeof (omp)); /* msg pack */ /* * category may be LC_MESSAGES or LC_TIME * locale contains the value of 'category' */ if (loc == NULL) loc = uselocale(NULL); cur_locale = current_locale(loc, category); language = getenv("LANGUAGE"); /* for GNU */ if (language) { if (!*language || strchr(language, '/') != NULL) { /* * LANGUAGE is an empty string or * LANGUAGE contains '/'. * Ignore it. */ language = NULL; } } /* * Query the current domain if domain argument is NULL pointer */ mydomain[0] = '\0'; if (domain == NULL) { /* * if NULL is specified for domainname, * use the currently bound domain. */ cur_domain = _textdomain_u(NULL, mydomain); } else if (!*domain) { /* * if an empty string is specified */ cur_domain = DEFAULT_DOMAIN; } else { cur_domain = (char *)domain; } hash_domain = get_hashid(cur_domain, &cur_domain_len); if (cur_domain_len > TEXTDOMAINMAX) { /* domain is invalid, return msg_id */ DFLTMSG(result, msgid1, msgid2, n, plural); return (result); } nlspath = getenv("NLSPATH"); /* get the content of NLSPATH */ if (nlspath == NULL || !*nlspath) { /* no NLSPATH is defined in the environ */ if ((*cur_locale == 'C') && (*(cur_locale + 1) == '\0')) { /* * If C locale, * return the original msgid immediately. */ DFLTMSG(result, msgid1, msgid2, n, plural); return (result); } nlspath = NULL; } else { /* NLSPATH is set */ int ret; msgloc = current_locale(loc, LC_MESSAGES); ret = process_nlspath(cur_domain, msgloc, (const char *)nlspath, &cur_binding); if (ret == -1) { /* error occurred */ DFLTMSG(result, msgid1, msgid2, n, plural); return (result); } else if (ret == 0) { nlspath = NULL; } } cur_domain_binding = _real_bindtextdomain_u(cur_domain, NULL, TP_BINDING); if (cur_domain_binding == NULL) { DFLTMSG(result, msgid1, msgid2, n, plural); return (result); } mp->msgid1 = msgid1; mp->msgid2 = msgid2; mp->msgfile = msgfile; mp->domain = cur_domain; mp->binding = cur_domain_binding; mp->locale = cur_locale; mp->language = language; mp->domain_len = cur_domain_len; mp->n = n; mp->category = category; mp->plural = plural; mp->hash_domain = hash_domain; /* * Spec1170 requires that we use NLSPATH if it's defined, to * override any system default variables. If NLSPATH is not * defined or if a message catalog is not found in any of the * components (bindings) specified by NLSPATH, dcgettext_u() will * search for the message catalog in either a) the binding path set * by any previous application calls to bindtextdomain() or * b) the default binding path (/usr/lib/locale). Save the original * binding path so that we can search it if the message catalog * is not found via NLSPATH. The original binding is restored before * returning from this routine because the gettext routines should * not change the binding set by the application. This allows * bindtextdomain() to be called once for all gettext() calls in the * application. */ /* * First, examine NLSPATH */ if (nlspath) { /* * NLSPATH binding has been successfully built */ #ifdef GETTEXT_DEBUG gprintf(0, "************************** examining NLSPATH\n"); gprintf(0, " cur_binding: \"%s\"\n", cur_binding ? cur_binding : "(null)"); #endif mp->nlsp = 1; /* * cur_binding always ends with ':' before a null * termination. */ while (*cur_binding) { cb = cur_binding; while (*cur_binding != ':') cur_binding++; cblen = cur_binding - cb; cur_binding++; if (cblen >= MAXPATHLEN) { /* cur_binding too long */ DFLTMSG(result, msgid1, msgid2, n, plural); return (result); } (void) memcpy(mp->msgfile, cb, cblen); *(mp->msgfile + cblen) = '\0'; #ifdef GETTEXT_DEBUG gprintf(0, "*******************" "********************* \n"); gprintf(0, " msgfile: \"%s\"\n", msgfile ? msgfile : "(null)"); gprintf(0, "*******************" "********************* \n"); #endif result = handle_mo(mp); if (result) { return (result); } } } mp->nlsp = 0; mp->binding = cur_domain_binding; /* * Next, examine LANGUAGE */ if (language) { char *ret_msg; ret_msg = handle_lang(mp); if (ret_msg != NULL) { /* valid msg found in GNU MO */ return (ret_msg); } /* * handle_lang() may have overridden locale */ mp->locale = cur_locale; mp->status = 0; } /* * Finally, handle a single binding */ #ifdef GETTEXT_DEBUG *mp->msgfile = '\0'; #endif if (mk_msgfile(mp) == NULL) { DFLTMSG(result, msgid1, msgid2, n, plural); return (result); } result = handle_mo(mp); if (result) { return (result); } DFLTMSG(result, msgid1, msgid2, n, plural); return (result); } /* _real_gettext_u */