예제 #1
0
파일: Country.cpp 프로젝트: mmanley/Antares
bool
BCountry::Name(BString& name) const
{
	UnicodeString uString;
	fICULocale->getDisplayName(uString);
	BStringByteSink stringConverter(&name);
	uString.toUTF8(stringConverter);
	return true;
}
예제 #2
0
파일: Country.cpp 프로젝트: mmanley/Antares
void
BCountry::FormatDate(BString *string, time_t time, bool longFormat)
{
	// TODO: ICU allows for 4 different levels of expansion :
	// short, medium, long, and full. Our bool parameter is not enough...
	icu_4_2::DateFormat* dateFormatter
		= longFormat ? fICULongDateFormatter : fICUShortDateFormatter;
	UnicodeString ICUString;
	ICUString = dateFormatter->format((UDate)time * 1000, ICUString);

	string->Truncate(0);
	BStringByteSink stringConverter(string);

	ICUString.toUTF8(stringConverter);
}
예제 #3
0
status_t
BFormattingConventions::GetTimeFormat(BTimeFormatStyle style,
                                      BString& outFormat) const
{
    if (style < 0 || style >= B_TIME_FORMAT_STYLE_COUNT)
        return B_BAD_VALUE;

    outFormat = fExplicitTimeFormats[style].Length()
                ? fExplicitTimeFormats[style]
                : fCachedTimeFormats[style];

    if (outFormat.Length() > 0)
        return B_OK;

    ObjectDeleter<DateFormat> timeFormatter(
        DateFormat::createTimeInstance((DateFormat::EStyle)style, *fICULocale));
    if (timeFormatter.Get() == NULL)
        return B_NO_MEMORY;

    SimpleDateFormat* timeFormatterImpl
        = static_cast<SimpleDateFormat*>(timeFormatter.Get());

    UnicodeString icuString;
    timeFormatterImpl->toPattern(icuString);
    BStringByteSink stringConverter(&outFormat);
    icuString.toUTF8(stringConverter);

    int8 use24HourClock = fExplicitUse24HourClock != CLOCK_HOURS_UNSET
                          ?  fExplicitUse24HourClock : fCachedUse24HourClock;
    if (use24HourClock != CLOCK_HOURS_UNSET) {
        // adjust to 12/24-hour clock as requested
        bool localeUses24HourClock = !FormatUsesAmPm(outFormat);
        if (localeUses24HourClock) {
            if (use24HourClock == CLOCK_HOURS_12)
                CoerceFormatTo12HourClock(outFormat);
        } else {
            if (use24HourClock == CLOCK_HOURS_24)
                CoerceFormatTo24HourClock(outFormat);
        }
    }

    // use abbreviated timezone in short timezone format
    CoerceFormatToAbbreviatedTimezone(outFormat);

    fCachedTimeFormats[style] = outFormat;

    return B_OK;
}
예제 #4
0
파일: Country.cpp 프로젝트: mmanley/Antares
void
BCountry::FormatNumber(BString* string, int32 value)
{
	UErrorCode err;
	NumberFormat* numberFormatter
		= NumberFormat::createInstance(*fICULocale, err);

	assert(err == U_ZERO_ERROR);

	UnicodeString ICUString;
	ICUString = numberFormatter->format((int32_t)value, ICUString);

	string->Truncate(0);
	BStringByteSink stringConverter(string);

	ICUString.toUTF8(stringConverter);
}
예제 #5
0
파일: Country.cpp 프로젝트: mmanley/Antares
bool
BCountry::DateFormat(BString& format, bool longFormat) const
{
	icu_4_2::DateFormat* dateFormatter
		= longFormat ? fICULongDateFormatter : fICUShortDateFormatter;
	SimpleDateFormat* dateFormatterImpl
		= static_cast<SimpleDateFormat*>(dateFormatter);

	UnicodeString ICUString;
	ICUString = dateFormatterImpl->toPattern(ICUString);

	BStringByteSink stringConverter(&format);

	ICUString.toUTF8(stringConverter);

	return true;
}
예제 #6
0
파일: Country.cpp 프로젝트: mmanley/Antares
void
BCountry::FormatTime(BString* string, time_t time, bool longFormat)
{
	// TODO: ICU allows for 4 different levels of expansion :
	// short, medium, long, and full. Our bool parameter is not enough...
	icu_4_2::DateFormat* timeFormatter;
 	timeFormatter = DateFormat::createTimeInstance(
		longFormat ? DateFormat::FULL : DateFormat::SHORT,
		*fICULocale);
	UnicodeString ICUString;
	ICUString = timeFormatter->format((UDate)time * 1000, ICUString);

	string->Truncate(0);
	BStringByteSink stringConverter(string);

	ICUString.toUTF8(stringConverter);
}
예제 #7
0
파일: Country.cpp 프로젝트: mmanley/Antares
bool
BCountry::TimeFormat(BString& format, bool longFormat) const
{
	icu_4_2::DateFormat* dateFormatter;
 	dateFormatter = DateFormat::createTimeInstance(
		longFormat ? DateFormat::FULL : DateFormat::SHORT,
		*fICULocale);
	SimpleDateFormat* dateFormatterImpl
		= static_cast<SimpleDateFormat*>(dateFormatter);

	UnicodeString ICUString;
	ICUString = dateFormatterImpl->toPattern(ICUString);

	BStringByteSink stringConverter(&format);

	ICUString.toUTF8(stringConverter);

	return true;
}
예제 #8
0
status_t
BFormattingConventions::GetDateTimeFormat(BDateFormatStyle dateStyle,
	BTimeFormatStyle timeStyle, BString& outFormat) const
{
	if (dateStyle < 0 || dateStyle >= B_DATE_FORMAT_STYLE_COUNT)
		return B_BAD_VALUE;

	if (timeStyle < 0 || timeStyle >= B_TIME_FORMAT_STYLE_COUNT)
		return B_BAD_VALUE;

	outFormat = fExplicitDateTimeFormats[dateStyle][timeStyle].Length()
		? fExplicitDateTimeFormats[dateStyle][timeStyle]
		: fCachedDateTimeFormats[dateStyle][timeStyle];

	if (outFormat.Length() > 0)
		return B_OK;

	ObjectDeleter<DateFormat> dateFormatter(
		DateFormat::createDateTimeInstance((DateFormat::EStyle)dateStyle,
			(DateFormat::EStyle)timeStyle, *fICULocale));
	if (dateFormatter.Get() == NULL)
		return B_NO_MEMORY;

	SimpleDateFormat* dateFormatterImpl
		= static_cast<SimpleDateFormat*>(dateFormatter.Get());

	UnicodeString icuString;
	dateFormatterImpl->toPattern(icuString);
	BStringByteSink stringConverter(&outFormat);
	icuString.toUTF8(stringConverter);

	CoerceFormatForClock(outFormat);

	if (dateStyle != B_FULL_DATE_FORMAT) {
		// use abbreviated timezone in short timezone format
		CoerceFormatToAbbreviatedTimezone(outFormat);
	}

	fCachedDateTimeFormats[dateStyle][timeStyle] = outFormat;

	return B_OK;
}
예제 #9
0
파일: Country.cpp 프로젝트: mmanley/Antares
status_t
BCountry::FormatNumber(BString* string, double value)
{
	UErrorCode err = U_ZERO_ERROR;
	NumberFormat* numberFormatter
		= NumberFormat::createInstance(*fICULocale, NumberFormat::kNumberStyle,
			err);

	// Warning: we're returning an ICU error here but the type is status_t.
	if (U_FAILURE(err)) return err;

	UnicodeString ICUString;
	ICUString = numberFormatter->format(value, ICUString);

	string->Truncate(0);
	BStringByteSink stringConverter(string);

	ICUString.toUTF8(stringConverter);

	return U_ZERO_ERROR;
}
예제 #10
0
status_t
BFormattingConventions::GetName(BString& name,
                                const BLanguage* displayLanguage) const
{
    BString displayLanguageID;
    if (displayLanguage == NULL) {
        BLanguage defaultLanguage;
        BLocale::Default()->GetLanguage(&defaultLanguage);
        displayLanguageID = defaultLanguage.Code();
    } else {
        displayLanguageID = displayLanguage->Code();
    }

    UnicodeString uString;
    fICULocale->getDisplayName(Locale(displayLanguageID.String()), uString);
    name.Truncate(0);
    BStringByteSink stringConverter(&name);
    uString.toUTF8(stringConverter);

    return B_OK;
}
예제 #11
0
파일: Country.cpp 프로젝트: mmanley/Antares
ssize_t
BCountry::FormatMonetary(BString* string, double value)
{
	if (string == NULL)
		return B_BAD_VALUE;

	UErrorCode err;
	NumberFormat* numberFormatter
		= NumberFormat::createCurrencyInstance(*fICULocale, err);

	assert(err == U_ZERO_ERROR);

	UnicodeString ICUString;
	ICUString = numberFormatter->format(value, ICUString);

	string->Truncate(0);
	BStringByteSink stringConverter(string);

	ICUString.toUTF8(stringConverter);

	return string->Length();
}
예제 #12
0
파일: Country.cpp 프로젝트: mmanley/Antares
bool
BCountry::MonThousandsSeparator(BString& separator) const
{
	UErrorCode err;
	NumberFormat* numberFormatter
		= NumberFormat::createCurrencyInstance(*fICULocale, err);
	assert(err == U_ZERO_ERROR);
	DecimalFormat* decimalFormatter
		= dynamic_cast<DecimalFormat*>(numberFormatter);

	assert(decimalFormatter != NULL);

	const DecimalFormatSymbols* syms
		= decimalFormatter->getDecimalFormatSymbols();

	UnicodeString ICUString;
	ICUString = syms->getSymbol(DecimalFormatSymbols::kPatternSeparatorSymbol);

	BStringByteSink stringConverter(&separator);

	ICUString.toUTF8(stringConverter);

	return true;
}
예제 #13
0
파일: Country.cpp 프로젝트: mmanley/Antares
bool
BCountry::NegativeSign(BString& sign) const
{
	UErrorCode err;
	NumberFormat* numberFormatter
		= NumberFormat::createInstance(*fICULocale, err);
	assert(err == U_ZERO_ERROR);
	DecimalFormat* decimalFormatter
		= dynamic_cast<DecimalFormat*>(numberFormatter);

	assert(decimalFormatter != NULL);

	const DecimalFormatSymbols* syms
		= decimalFormatter->getDecimalFormatSymbols();

	UnicodeString ICUString;
	ICUString = syms->getSymbol(DecimalFormatSymbols::kMinusSignSymbol);

	BStringByteSink stringConverter(&sign);

	ICUString.toUTF8(stringConverter);

	return true;
}