void XMLAbstractDoubleFloat::normalizeDecimalPoint(char* const toNormal) { // find the locale-specific decimal point delimiter lconv* lc = localeconv(); char delimiter = *lc->decimal_point; // replace '.' with the locale-specific decimal point delimiter if ( delimiter != '.' ) { char* period = strchr( toNormal, '.' ); if ( period ) { *period = delimiter; } } }
static char* CPLReplacePointByLocalePoint(const char* pszNumber, char point) { #if defined(__ANDROID__) static char byPoint = 0; if (byPoint == 0) { char szBuf[16]; snprintf(szBuf, sizeof(szBuf), "%.1f", 1.0); byPoint = szBuf[1]; } if (point != byPoint) { const char* pszPoint = strchr(pszNumber, point); if (pszPoint) { char* pszNew = CPLStrdup(pszNumber); pszNew[pszPoint - pszNumber] = byPoint; return pszNew; } } #else // ndef __ANDROID__ struct lconv *poLconv = localeconv(); if ( poLconv && poLconv->decimal_point && poLconv->decimal_point[0] != '\0' ) { char byPoint = poLconv->decimal_point[0]; if (point != byPoint) { const char* pszLocalePoint = strchr(pszNumber, byPoint); const char* pszPoint = strchr(pszNumber, point); if (pszPoint || pszLocalePoint) { char* pszNew = CPLStrdup(pszNumber); if( pszLocalePoint ) pszNew[pszLocalePoint - pszNumber] = ' '; if( pszPoint ) pszNew[pszPoint - pszNumber] = byPoint; return pszNew; } } } #endif // __ANDROID__ return const_cast<char*>( pszNumber ); }
/* * Set current locale symbols. */ static void set_locale(void) { struct lconv *lc; const char *locale; setlocale(LC_ALL, ""); lc = localeconv(); if (lc) { /* obtain LC_NUMERIC info */ /* Convert to wide char form */ conv_mbtowc(&symbol_decimal_point, lc->decimal_point, symbol_decimal_point); conv_mbtowc(&symbol_thousands_sep, lc->thousands_sep, symbol_thousands_sep); conv_mbtowc(&symbol_positive_sign, lc->positive_sign, symbol_positive_sign); conv_mbtowc(&symbol_negative_sign, lc->negative_sign, symbol_negative_sign); } if (getenv("GNUSORT_NUMERIC_COMPATIBILITY")) gnusort_numeric_compatibility = true; locale = setlocale(LC_COLLATE, NULL); if (locale) { char *tmpl; const char *cclocale; tmpl = sort_strdup(locale); cclocale = setlocale(LC_COLLATE, "C"); if (cclocale && !strcmp(cclocale, tmpl)) byte_sort = true; else { const char *pclocale; pclocale = setlocale(LC_COLLATE, "POSIX"); if (pclocale && !strcmp(pclocale, tmpl)) byte_sort = true; } setlocale(LC_COLLATE, tmpl); sort_free(tmpl); } }
wxChar NumberFormatter::GetDecimalSeparator() { #if wxUSE_INTL struct lconv *info = localeconv(); wxString s = info ? wxString::FromUTF8(info->decimal_point) : wxT("."); if (s.empty()) { // We really must have something for decimal separator, so fall // back to the C locale default. s = wxT("."); } return s[0]; #else // !wxUSE_INTL return wxT('.'); #endif // wxUSE_INTL/!wxUSE_INTL }
/* static */ wxString wxLocale::GetInfo(wxLocaleInfo index, wxLocaleCategory cat) { lconv * const lc = localeconv(); if ( !lc ) return wxString(); switch ( index ) { case wxLOCALE_THOUSANDS_SEP: if ( cat == wxLOCALE_CAT_NUMBER ) return lc->thousands_sep; else if ( cat == wxLOCALE_CAT_MONEY ) return lc->mon_thousands_sep; wxFAIL_MSG( "invalid wxLocaleCategory" ); break; case wxLOCALE_DECIMAL_POINT: if ( cat == wxLOCALE_CAT_NUMBER ) return lc->decimal_point; else if ( cat == wxLOCALE_CAT_MONEY ) return lc->mon_decimal_point; wxFAIL_MSG( "invalid wxLocaleCategory" ); break; case wxLOCALE_SHORT_DATE_FMT: case wxLOCALE_LONG_DATE_FMT: case wxLOCALE_DATE_TIME_FMT: case wxLOCALE_TIME_FMT: if ( cat != wxLOCALE_CAT_DATE && cat != wxLOCALE_CAT_DEFAULT ) { wxFAIL_MSG( "invalid wxLocaleCategory" ); break; } return GetDateFormatFromLangInfo(index); default: wxFAIL_MSG( "unknown wxLocaleInfo value" ); } return wxString(); }
Array f_localeconv() { struct lconv currlocdata; { Lock lock(s_mutex); struct lconv *res = localeconv(); currlocdata = *res; } Array ret; #define SET_LOCALE_STRING(x) ret.set(#x, String(currlocdata.x, CopyString)) SET_LOCALE_STRING(decimal_point); SET_LOCALE_STRING(thousands_sep); SET_LOCALE_STRING(int_curr_symbol); SET_LOCALE_STRING(currency_symbol); SET_LOCALE_STRING(mon_decimal_point); SET_LOCALE_STRING(mon_thousands_sep); SET_LOCALE_STRING(positive_sign); SET_LOCALE_STRING(negative_sign); #define SET_LOCALE_INTEGER(x) ret.set(#x, currlocdata.x) SET_LOCALE_INTEGER(int_frac_digits); SET_LOCALE_INTEGER(frac_digits); SET_LOCALE_INTEGER(p_cs_precedes); SET_LOCALE_INTEGER(p_sep_by_space); SET_LOCALE_INTEGER(n_cs_precedes); SET_LOCALE_INTEGER(n_sep_by_space); SET_LOCALE_INTEGER(p_sign_posn); SET_LOCALE_INTEGER(n_sign_posn); Array grouping, mon_grouping; /* Grab the grouping data out of the array */ int len = strlen(currlocdata.grouping); for (int i = 0; i < len; i++) { grouping.set(i, currlocdata.grouping[i]); } ret.set("grouping", grouping); /* Grab the monetary grouping data out of the array */ len = strlen(currlocdata.mon_grouping); for (int i = 0; i < len; i++) { mon_grouping.set(i, currlocdata.mon_grouping[i]); } ret.set("mon_grouping", mon_grouping); return ret; }
// Returns a string that contains valid characters for a 'numeric' string. Used for user input. std::string LegalNrTokens(bool real, const std::string &curstr, TSTLStrSize pos) { lconv *lc = localeconv(); std::string legal = "1234567890"; assert(lc != NULL); std::string decpoint = std::string(lc->decimal_point); std::string plusminsign = std::string(lc->positive_sign) + std::string(lc->negative_sign); if (real && (curstr.find_first_of(decpoint) == std::string::npos)) legal += decpoint; if ((pos == 0) && (curstr.find_first_of(plusminsign) == std::string::npos)) legal += plusminsign; return legal; }
void InitSimpleStuff(void) { initlibrarysearchpath(); initlibltdl(); initrand(); initadobeenc(); setlocale(LC_ALL,""); localeinfo = *localeconv(); coord_sep = ","; if ( *localeinfo.decimal_point=='.' ) coord_sep=","; else if ( *localeinfo.decimal_point!='.' ) coord_sep=" "; if ( getenv("FF_SCRIPT_IN_LATIN1") ) use_utf8_in_script=false; inituninameannot(); /* Note: unicodenames done after locales set */ SetDefaults(); }
bool NumberFormatter::GetThousandsSeparatorIfUsed(wxChar *sep) { #if wxUSE_INTL struct lconv *info = localeconv(); wxString s = info ? wxString::FromUTF8(info->thousands_sep) : wxT(""); if (s.IsEmpty()) { return false; } *sep = s[0]; return true; #else // !wxUSE_INTL wxUnusedVar(sep); return false; #endif // wxUSE_INTL/!wxUSE_INTL }
char *make_apostrophe(char *ret_s) { char *help_s; struct lconv *lc; size_t i; lc = localeconv(); if (!(*(lc->thousands_sep))) return (ret_s); help_s = lc->thousands_sep; i = ft_strlen(ret_s) - 3; while (ret_s[i] && i > 0 && ft_isdigit(ret_s[i - 1])) { ret_s = ft_insert_string(ret_s, help_s, i); i -= 3; } return (ret_s); }
char *commaprint(u64 n) { static int comma = '\0'; static char retbuf[32]; char *p = &retbuf[sizeof(retbuf) - 1]; int i = 0; if(comma == '\0') { #ifndef ANDROID struct lconv *lcp = localeconv(); if(lcp != NULL) { if(lcp->thousands_sep != NULL && *lcp->thousands_sep != '\0') { comma = *lcp->thousands_sep; } else { comma = ','; } } #else comma = ','; #endif } *p = '\0'; do { if(i % 3 == 0 && i != 0) { *--p = comma; } *--p = '0' + n % 10; n /= 10; i++; } while(n != 0); return p; }
static void to_locale(strbuffer_t *strbuffer) { const char *point; char *pos; #ifdef ANDROID_NDK point = "."; // Note: Changed in order to compile on Android #else point = localeconv()->decimal_point; #endif if(*point == '.') { /* No conversion needed */ return; } pos = strchr(strbuffer->value, '.'); if(pos) *pos = *point; }
void CMyEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) { char nDecimalPoint = localeconv()->decimal_point[0]; if (m_nType == EditReal) { if ((nChar < '0' || nChar > '9') && nChar != nDecimalPoint && nChar != VK_BACK && (!m_bPercent || nChar != '%')) return; } else if (m_nType == EditInteger) { if ((nChar < '0' || nChar > '9') && nChar != VK_BACK && (!m_bPercent || nChar != '%')) return; } CEdit::OnChar(nChar, nRepCnt, nFlags); }
tmain() { #if _lib_locale char buf[128], cmp[128]; float d; int n, decimal, thousand; struct lconv* lv; setlocale(LC_ALL, ""); if(!(lv = localeconv())) texit(0); decimal = '.'; if(lv->decimal_point && lv->decimal_point[0]) decimal = lv->decimal_point[0]; thousand = 0; if(lv->thousands_sep && lv->thousands_sep[0]) thousand = lv->thousands_sep[0]; if(thousand) sfsprintf(cmp, sizeof(cmp), "1%c000", thousand); else sfsprintf(cmp, sizeof(cmp), "1000"); sfsprintf(buf, sizeof(buf), "%'d", 1000); if(strcmp(buf, cmp) != 0) terror("Bad printing"); if(thousand) sfsprintf(cmp, sizeof(cmp), "1%c000%c10", thousand, decimal); else sfsprintf(cmp, sizeof(cmp), "1000%c10", decimal); d = 0.; if((n = sfsscanf(cmp, "%'f", &d)) != 1) terror("Scan error %d", n); if(d < 1000.099 || d > 1000.101) terror("Bad scanning"); sfsprintf(buf, sizeof(buf), "%.2f", d); if(strcmp(buf, "1000.10") != 0) terror("Deep formatting error"); #endif texit(0); }
static void from_locale(char *buffer) { const char *point; char *pos; #ifdef ANDROID_NDK point = "."; // Note: Changed in order to compile on Android #else point = localeconv()->decimal_point; #endif if(*point == '.') { /* No conversion needed */ return; } pos = strchr(buffer, *point); if(pos) *pos = '.'; }
/*! @decl mapping localeconv() *! *! The localeconv() function returns a mapping with settings for *! the current locale. This mapping contains all values *! associated with the locale categories @[LC_NUMERIC] and *! @[LC_MONETARY]. *! *! @mapping *! @member string "decimal_point" *! The decimal-point character used to format *! non-monetary quantities. *! *! @member string "thousands_sep" *! The character used to separate groups of digits to *! the left of the decimal-point character in *! formatted non-monetary quantities. *! *! @member string "int_curr_symbol" *! The international currency symbol applicable to *! the current locale, left-justified within a *! four-character space-padded field. The character *! sequences should match with those specified in ISO *! 4217 Codes for the Representation of Currency and *! Funds. *! *! @member string "currency_symbol" *! The local currency symbol applicable to the *! current locale. *! *! @member string "mon_decimal_point" *! The decimal point used to format monetary quantities. *! *! @member string "mon_thousands_sep" *! The separator for groups of digits to the left of *! the decimal point in formatted monetary quantities. *! *! @member string "positive_sign" *! The string used to indicate a non-negative-valued *! formatted monetary quantity. *! *! @member string "negative_sign" *! The string used to indicate a negative-valued *! formatted monetary quantity. *! *! @member int "int_frac_digits" *! The number of fractional digits (those to the *! right of the decimal point) to be displayed in an *! internationally formatted monetary quantity. *! *! @member int "frac_digits" *! The number of fractional digits (those to the *! right of the decimal point) to be displayed in a *! formatted monetary quantity. *! *! @member int(0..1) "p_cs_precedes" *! Set to 1 or 0 if the currency_symbol respectively *! precedes or succeeds the value for a non-negative *! formatted monetary quantity. *! *! @member int(0..1) "p_sep_by_space" *! Set to 1 or 0 if the currency_symbol respectively *! is or is not separated by a space from the value *! for a non-negative formatted monetary quantity. *! *! @member int(0..1) "n_cs_precedes" *! Set to 1 or 0 if the currency_symbol respectively *! precedes or succeeds the value for a negative *! formatted monetary quantity. *! *! @member int(0..1) "n_sep_by_space" *! Set to 1 or 0 if the currency_symbol respectively *! is or is not separated by a space from the value *! for a negative formatted monetary quantity. *! *! @member int(0..4) "p_sign_posn" *! Set to a value indicating the positioning of the *! positive_sign for a non-negative formatted *! monetary quantity. The value of p_sign_posn is *! interpreted according to the following: *! *! @int *! @value 0 *! Parentheses surround the quantity and currency_symbol. *! @value 1 *! The sign string precedes the quantity and currency_symbol. *! @value 2 *! The sign string succeeds the quantity and currency_symbol. *! @value 3 *! The sign string immediately precedes the currency_symbol. *! @value 4 *! The sign string immediately succeeds the currency_symbol. *! @endint *! *! @member int "n_sign_posn" *! Set to a value indicating the positioning of the *! negative_sign for a negative formatted monetary *! quantity. The value of n_sign_posn is interpreted *! according to the rules described under p_sign_posn. *! @endmapping *! *! @seealso *! @[bindtextdomain], @[textdomain], @[gettext], @[dgettext], @[dcgettext], @[setlocale] */ void f_localeconv(INT32 args) { struct lconv *locale; /* Information about the current locale */ struct svalue *save_sp = Pike_sp; locale = localeconv(); #define MAPSTR(key) do { \ push_text(TOSTR(key)); \ push_text(locale->key); \ } while(0) #define MAPINT(key) do { \ push_text(TOSTR(key)); \ push_int(locale->key); \ } while(0) MAPSTR(decimal_point); MAPSTR(thousands_sep); MAPSTR(int_curr_symbol); MAPSTR(currency_symbol); MAPSTR(mon_decimal_point); MAPSTR(mon_thousands_sep); MAPSTR(positive_sign); MAPSTR(negative_sign); /* * MAPCHAR(grouping); * MAPCHAR(mon_grouping); */ MAPINT(int_frac_digits); MAPINT(frac_digits); MAPINT(p_cs_precedes); MAPINT(p_sep_by_space); MAPINT(n_cs_precedes); MAPINT(n_sep_by_space); MAPINT(p_sign_posn); MAPINT(n_sign_posn); f_aggregate_mapping(Pike_sp - save_sp); stack_pop_n_elems_keep_top(args); }
static bool MR_StringToDouble(const char* string_value, double* dvalue) { static char MR_Radix = 0; const unsigned slen = strlen(string_value); char cpi[slen + 1]; char* endptr = NULL; if(!MR_Radix) { char buf[64]; // Use extra-large buffer since we're using sprintf() instead of snprintf() for portability reasons. //4]; // Use libc snprintf() and not trio_snprintf() here for out little abomination. //snprintf(buf, 4, "%.1f", (double)1); sprintf(buf, "%.1f", (double)1); if(buf[0] == '1' && buf[2] == '0' && buf[3] == 0) { MR_Radix = buf[1]; } else { lconv* l = localeconv(); assert(l != NULL); MR_Radix = *(l->decimal_point); } } for(unsigned i = 0; i < slen; i++) { char c = string_value[i]; if(c == '.' || c == ',') c = MR_Radix; cpi[i] = c; } cpi[slen] = 0; *dvalue = strtod(cpi, &endptr); if(endptr == NULL || *endptr != 0) return(false); return(true); }
/*--------------------------------------------------------------------------- | Facility : libnform | Function : static void *Make_This_Type(va_list * ap) | | Description : Allocate structure for numeric type argument. | | Return Values : Pointer to argument structure or NULL on error +--------------------------------------------------------------------------*/ static void * Make_This_Type(va_list *ap) { thisARG *argn = (thisARG *) malloc(sizeof(thisARG)); if (argn) { argn->precision = va_arg(*ap, int); argn->low = va_arg(*ap, double); argn->high = va_arg(*ap, double); #if HAVE_LOCALE_H argn->L = localeconv(); #else argn->L = NULL; #endif } return (void *)argn; }
static char* CPLReplacePointByLocalePoint(const char* pszNumber, char point) { #if defined(WIN32CE) || defined(__ANDROID__) static char byPoint = 0; if (byPoint == 0) { char szBuf[16]; sprintf(szBuf, "%.1f", 1.0); byPoint = szBuf[1]; } if (point != byPoint) { const char* pszPoint = strchr(pszNumber, point); if (pszPoint) { char* pszNew = CPLStrdup(pszNumber); pszNew[pszPoint - pszNumber] = byPoint; return pszNew; } } #else struct lconv *poLconv = localeconv(); if ( poLconv && poLconv->decimal_point && strlen(poLconv->decimal_point) > 0 ) { char byPoint = poLconv->decimal_point[0]; if (point != byPoint) { const char* pszPoint = strchr(pszNumber, point); if (pszPoint) { char* pszNew = CPLStrdup(pszNumber); pszNew[pszPoint - pszNumber] = byPoint; return pszNew; } } } #endif return (char*) pszNumber; }
/* Remove trailing 0 from a string containing a converted float number. * the trailing 0 are removed if the mantissa has more * than aTrailingZeroAllowed digits and some trailing 0 */ void StripTrailingZeros( wxString& aStringValue, unsigned aTrailingZeroAllowed ) { struct lconv * lc = localeconv(); char sep = lc->decimal_point[0]; unsigned sep_pos = aStringValue.Find( sep ); if( sep_pos > 0 ) { // We want to keep at least aTrailingZeroAllowed digits after the separator unsigned min_len = sep_pos + aTrailingZeroAllowed + 1; while( aStringValue.Len() > min_len ) { if( aStringValue.Last() == '0' ) aStringValue.RemoveLast(); else break; } } }
void bkspf(void) { lift_enabled = 0; if (! flagINV) { if (entered!=1) { clearf(); return; } if (clrdisp) return; if ((int) strlen(dispstr) > 0) { #ifndef X_LOCALE const char *dp = localeconv()->decimal_point; size_t dp_len = strlen(dp); size_t ds_len = strlen(dispstr); if (ds_len >= dp_len && strcmp(dispstr + ds_len - dp_len, dp) == 0) Dpoint=0; #else if (dispstr[strlen(dispstr)-1] == '.') Dpoint=0; #endif dispstr[strlen(dispstr)-1] = 0; } if (strlen(dispstr) == 0) { strcat(dispstr, "0"); clrdisp++; } } else { strlcpy(dispstr, "0", sizeof(dispstr)); dnum = 0.0; clrdisp++; flagINV = 0; } DrawDisplay(); }
/* * Initialize the thousands' grouping state in preparation to print a * number with ndigits digits. This routine returns the total number * of wide characters that will be printed. */ static int grouping_init(struct grouping_state *gs, int ndigits) { gs->grouping = localeconv()->grouping; gs->thousands_sep = get_thousep(); gs->nseps = gs->nrepeats = 0; gs->lead = ndigits; while (*gs->grouping != CHAR_MAX) { if (gs->lead <= *gs->grouping) break; gs->lead -= *gs->grouping; if (*(gs->grouping+1)) { gs->nseps++; gs->grouping++; } else gs->nrepeats++; } return (gs->nseps + gs->nrepeats); }
int main(void) { struct lconv l; int i; setlocale(LC_ALL, ""); l = *localeconv(); printf("decimal_point = [%s]\n", l.decimal_point); printf("thousands_sep = [%s]\n", l.thousands_sep); for (i = 0; l.grouping[i] != 0 && l.grouping[i] != CHAR_MAX; i++) printf("grouping[%d] = [%d]\n", i, l.grouping[i]); printf("int_curr_symbol = [%s]\n", l.int_curr_symbol); printf("currency_symbol = [%s]\n", l.currency_symbol); printf("mon_decimal_point = [%s]\n", l.mon_decimal_point); printf("mon_thousands_sep = [%s]\n", l.mon_thousands_sep); printf("positive_sign = [%s]\n", l.positive_sign); printf("negative_sign = [%s]\n", l.negative_sign); }
void decf(void) { flagINV=0; if (clrdisp) { if (rpn && lift_enabled) PushNum(dnum); strlcpy(dispstr, "0", sizeof(dispstr)); } if (!Dpoint) { #ifndef X_LOCALE strcat(dispstr, localeconv()->decimal_point); #else strcat(dispstr, "."); #endif DrawDisplay(); Dpoint++; } clrdisp=0; entered=1; }
void CNumberEdit::Prepare() { if( m_nType == ntDouble ) { struct lconv *pConv = localeconv(); CString charSet( _T("1234567890") ); if( m_dMin < 0.0 || m_dMax < 0.0 ) charSet+= _T('-'); SetCharSet( charSet + pConv->decimal_point ); } else { CString charSet( _T("1234567890") ); if( m_lMin < 0 || m_lMax < 0 ) charSet+= _T('-'); SetCharSet( charSet ); } }
// Format capacity with SI prefixes const char * format_capacity(char * str, int strsize, uint64_t val, const char * decimal_point /* = 0 */) { if (!decimal_point) { decimal_point = "."; #ifdef HAVE_LOCALE_H setlocale(LC_ALL, ""); const struct lconv * currentlocale = localeconv(); if (*(currentlocale->decimal_point)) decimal_point = currentlocale->decimal_point; #endif } const unsigned factor = 1000; // 1024 for KiB,MiB,... static const char prefixes[] = " KMGTP"; // Find d with val in [d, d*factor) unsigned i = 0; uint64_t d = 1; for (uint64_t d2 = d * factor; val >= d2; d2 *= factor) { d = d2; if (++i >= sizeof(prefixes)-2) break; } // Print 3 digits uint64_t n = val / d; if (i == 0) snprintf(str, strsize, "%u B", (unsigned)n); else if (n >= 100) // "123 xB" snprintf(str, strsize, "%"PRIu64" %cB", n, prefixes[i]); else if (n >= 10) // "12.3 xB" snprintf(str, strsize, "%"PRIu64"%s%u %cB", n, decimal_point, (unsigned)(((val % d) * 10) / d), prefixes[i]); else // "1.23 xB" snprintf(str, strsize, "%"PRIu64"%s%02u %cB", n, decimal_point, (unsigned)(((val % d) * 100) / d), prefixes[i]); return str; }
inline std::string value::to_str() const { switch (type_) { case null_type: return "null"; case boolean_type: return u_.boolean_ ? "true" : "false"; #ifdef PICOJSON_USE_INT64 case int64_type: { char buf[sizeof("-9223372036854775808")]; SNPRINTF(buf, sizeof(buf), "%" PRId64, u_.int64_); return buf; } #endif case number_type: { char buf[256]; double tmp; SNPRINTF(buf, sizeof(buf), fabs(u_.number_) < (1ULL << 53) && modf(u_.number_, &tmp) == 0 ? "%.f" : "%.17g", u_.number_); #if PICOJSON_USE_LOCALE char *decimal_point = localeconv()->decimal_point; if (strcmp(decimal_point, ".") != 0) { size_t decimal_point_len = strlen(decimal_point); for (char *p = buf; *p != '\0'; ++p) { if (strncmp(p, decimal_point, decimal_point_len) == 0) { return std::string(buf, p) + "." + (p + decimal_point_len); } } } #endif return buf; } case string_type: return *u_.string_; case array_type: return "array"; case object_type: return "object"; default: PICOJSON_ASSERT(0); #ifdef _MSC_VER __assume(0); #endif } return std::string(); }
static void wcsutil_locale_to_dot(char *buf) { struct lconv *locale_data = localeconv(); const char *decimal_point = locale_data->decimal_point; if (decimal_point[0] != '.' || decimal_point[1] != 0) { size_t decimal_point_len = strlen(decimal_point); char *inbuf = buf; char *outbuf = buf; for ( ; *inbuf; inbuf++) { if (strncmp(inbuf, decimal_point, decimal_point_len) == 0) { *outbuf++ = '.'; inbuf += decimal_point_len - 1; } else { *outbuf++ = *inbuf; } } *outbuf = '\0'; } }
/** * init the decimal point and the thousands separator. * * */ void initialise_number_separators ( void ) { struct lconv *conv; gchar *dec_point = NULL, *thousand_sep = NULL; gsb_locale_set_mon_decimal_point ( NULL ); gsb_locale_set_mon_thousands_sep ( NULL ); conv = localeconv(); if ( conv->mon_decimal_point && strlen ( conv->mon_decimal_point ) ) { dec_point = g_locale_to_utf8 ( conv->mon_decimal_point, -1, NULL, NULL, NULL ); gsb_locale_set_mon_decimal_point ( dec_point ); g_free ( dec_point ); } else gsb_locale_set_mon_decimal_point ( "." ); thousand_sep = g_locale_to_utf8 ( conv->mon_thousands_sep, -1, NULL, NULL, NULL ); gsb_locale_set_mon_thousands_sep ( thousand_sep ); g_free ( thousand_sep ); }
char *ft_anytoa(uint64_t n, int pre, int flag) { char *result; size_t i; size_t j; i = ft_getsize(n); if (flag) i += ((i - 1) / 3); i = ((int)i < pre) ? pre : i; if ((result = malloc(i + 1)) == NULL) return (NULL); result[i] = '\0'; j = 0; while (i--) { result[i] = n % 10 + '0'; if ((++j % 3) == 0 && flag && (n / 10)) result[--i] = *localeconv()->thousands_sep; n /= 10; } return (result); }