/** * @file llresmgr.cpp * @brief Localized resource manager * * Copyright (c) 2001-$CurrentYear$, Linden Research, Inc. * $License$ */ // NOTE: this is a MINIMAL implementation. The interface will remain, but the implementation will // (when the time is right) become dynamic and probably use external files. #include "linden_common.h" #include "llresmgr.h" #include "llfontgl.h" #include "llerror.h" #include "llstring.h" // Global singleton LLResMgr* gResMgr = NULL; LLResMgr::LLResMgr() { U32 i; // Init values for each locale. // Note: This is only the most bare-bones version. In the future, load these dynamically, on demand. ////////////////////////////////////////////////////////////////////////////// // USA // USA Fonts for( i=0; idecimal_point[0]; #if LL_DARWIN // On the Mac, locale support is broken before 10.4, which causes things to go all pear-shaped. if(decimal == 0) { decimal = '.'; } #endif return decimal; } char LLResMgr::getThousandsSeparator() const { char separator = localeconv()->thousands_sep[0]; #if LL_DARWIN // On the Mac, locale support is broken before 10.4, which causes things to go all pear-shaped. if(separator == 0) { separator = ','; } #endif return separator; } char LLResMgr::getMonetaryDecimalPoint() const { char decimal = localeconv()->mon_decimal_point[0]; #if LL_DARWIN // On the Mac, locale support is broken before 10.4, which causes things to go all pear-shaped. if(decimal == 0) { decimal = '.'; } #endif return decimal; } char LLResMgr::getMonetaryThousandsSeparator() const { char separator = localeconv()->mon_thousands_sep[0]; #if LL_DARWIN // On the Mac, locale support is broken before 10.4, which causes things to go all pear-shaped. if(separator == 0) { separator = ','; } #endif return separator; } // Sets output to a string of integers with monetary separators inserted according to the locale. void LLResMgr::getMonetaryString( LLString& output, S32 input ) const { LLLocale locale(LLLocale::USER_LOCALE); struct lconv *conv = localeconv(); #if LL_DARWIN // On the Mac, locale support is broken before 10.4, which causes things to go all pear-shaped. // Fake up a conv structure with some reasonable values for the fields this function uses. struct lconv fakeconv; if(conv->negative_sign[0] == 0) // Real locales all seem to have something here... { fakeconv = *conv; // start with what's there. switch(mLocale) { default: // Unknown -- use the US defaults. case LLLOCALE_USA: case LLLOCALE_UK: // UK ends up being the same as US for the items used here. fakeconv.negative_sign = "-"; fakeconv.mon_grouping = "\x03\x03\x00"; // commas every 3 digits fakeconv.n_sign_posn = 1; // negative sign before the string break; } conv = &fakeconv; } #endif char* negative_sign = conv->negative_sign; char separator = getMonetaryThousandsSeparator(); char* grouping = conv->mon_grouping; // Note on mon_grouping: // Specifies a string that defines the size of each group of digits in formatted monetary quantities. // The operand for the mon_grouping keyword consists of a sequence of semicolon-separated integers. // Each integer specifies the number of digits in a group. The initial integer defines the size of // the group immediately to the left of the decimal delimiter. The following integers define succeeding // groups to the left of the previous group. If the last integer is not -1, the size of the previous // group (if any) is repeatedly used for the remainder of the digits. If the last integer is -1, no // further grouping is performed. // Note: we assume here that the currency symbol goes on the left. (Hey, it's Lindens! We can just decide.) BOOL negative = (input < 0 ); BOOL negative_before = negative && (conv->n_sign_posn != 2); BOOL negative_after = negative && (conv->n_sign_posn == 2); LLString digits = llformat("%u", abs(input)); if( !grouping || !grouping[0] ) { output.assign("L$"); if( negative_before ) { output.append( negative_sign ); } output.append( digits ); if( negative_after ) { output.append( negative_sign ); } return; } S32 groupings[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; S32 cur_group; for( cur_group = 0; grouping[ cur_group ]; cur_group++ ) { if( grouping[ cur_group ] != ';' ) { groupings[cur_group] = grouping[ cur_group ]; } cur_group++; if( groupings[cur_group] < 0 ) { break; } } S32 group_count = cur_group; char reversed_output[20] = ""; char forward_output[20] = ""; S32 output_pos = 0; cur_group = 0; S32 pos = digits.size()-1; S32 count_within_group = 0; while( (pos >= 0) && (groupings[cur_group] >= 0) ) { count_within_group++; if( count_within_group > groupings[cur_group] ) { count_within_group = 1; reversed_output[ output_pos++ ] = separator; if( (cur_group + 1) >= group_count ) { break; } else if( groupings[cur_group + 1] > 0 ) { cur_group++; } } reversed_output[ output_pos++ ] = digits[pos--]; } while( pos >= 0 ) { reversed_output[ output_pos++ ] = digits[pos--]; } reversed_output[ output_pos ] = '\0'; forward_output[ output_pos ] = '\0'; for( S32 i = 0; i < output_pos; i++ ) { forward_output[ output_pos - 1 - i ] = reversed_output[ i ]; } output.assign("L$"); if( negative_before ) { output.append( negative_sign ); } output.append( forward_output ); if( negative_after ) { output.append( negative_sign ); } } void LLResMgr::getIntegerString( LLString& output, S32 input ) const { S32 fraction = 0; LLString fraction_string; S32 remaining_count = input; while(remaining_count > 0) { fraction = (remaining_count) % 1000; if (!output.empty()) { if (fraction == remaining_count) { fraction_string = llformat("%d%c", fraction, getThousandsSeparator()); } else { fraction_string = llformat("%3.3d%c", fraction, getThousandsSeparator()); } output = fraction_string + output; } else { if (fraction == remaining_count) { fraction_string = llformat("%d", fraction); } else { fraction_string = llformat("%3.3d", fraction); } output = fraction_string; } remaining_count /= 1000; } } const LLString LLFONT_ID_NAMES[] = { LLString("OCRA"), LLString("SANSSERIF"), LLString("SANSSERIF_SMALL"), LLString("SANSSERIF_BIG"), LLString("SMALL"), }; const LLFontGL* LLResMgr::getRes( LLString font_id ) const { for (S32 i=0; i