X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/b75a7d8f3b4adbae880cab104ce2c6a50eee4db2..4388f060552cc537e71e957d32f35e9d75a61233:/icuSources/i18n/format.cpp diff --git a/icuSources/i18n/format.cpp b/icuSources/i18n/format.cpp index 3141c85f..d80a44da 100644 --- a/icuSources/i18n/format.cpp +++ b/icuSources/i18n/format.cpp @@ -1,6 +1,6 @@ /* ******************************************************************************* -* Copyright (C) 1997-2003, International Business Machines Corporation and * +* Copyright (C) 1997-2011, International Business Machines Corporation and * * others. All Rights Reserved. * ******************************************************************************* * @@ -18,9 +18,15 @@ // ***************************************************************************** // This file was generated from the java source file Format.java // ***************************************************************************** - + +#include // for 'typeid' to work + #include "unicode/utypes.h" +#ifndef U_I18N_IMPLEMENTATION +#error U_I18N_IMPLEMENTATION not set - must be set for all ICU source files in i18n/ - see http://userguide.icu-project.org/howtouseicu +#endif + /* * Dummy code: * If all modules in the I18N library are switched off, then there are no @@ -39,6 +45,9 @@ uprv_icuin_lib_dummy(int32_t i) { #if !UCONFIG_NO_FORMATTING #include "unicode/format.h" +#include "unicode/ures.h" +#include "cstring.h" +#include "locbased.h" // ***************************************************************************** // class Format @@ -46,7 +55,14 @@ uprv_icuin_lib_dummy(int32_t i) { U_NAMESPACE_BEGIN -const char FieldPosition::fgClassID=0; +UOBJECT_DEFINE_RTTI_IMPLEMENTATION(FieldPosition) + +FieldPosition::~FieldPosition() {} + +FieldPosition * +FieldPosition::clone() const { + return new FieldPosition(*this); +} // ------------------------------------- // default constructor @@ -54,6 +70,7 @@ const char FieldPosition::fgClassID=0; Format::Format() : UObject() { + *validLocale = *actualLocale = 0; } // ------------------------------------- @@ -68,42 +85,61 @@ Format::~Format() Format::Format(const Format &that) : UObject(that) { + *this = that; } // ------------------------------------- // assignment operator Format& -Format::operator=(const Format& /*that*/) +Format::operator=(const Format& that) { + if (this != &that) { + uprv_strcpy(validLocale, that.validLocale); + uprv_strcpy(actualLocale, that.actualLocale); + } return *this; } // ------------------------------------- // Formats the obj and append the result in the buffer, toAppendTo. // This calls the actual implementation in the concrete subclasses. - + UnicodeString& -Format::format(const Formattable& obj, - UnicodeString& toAppendTo, +Format::format(const Formattable& obj, + UnicodeString& toAppendTo, UErrorCode& status) const { if (U_FAILURE(status)) return toAppendTo; - // {sfb} should really be FieldPosition::DONT_CARE, not 0 - // leave at 0 for now, to keep in sync with Java - FieldPosition pos(0); + FieldPosition pos(FieldPosition::DONT_CARE); return format(obj, toAppendTo, pos, status); } - + // ------------------------------------- -// Parses the source string and create the corresponding +// Default implementation sets unsupported error; subclasses should +// override. + +UnicodeString& +Format::format(const Formattable& /* unused obj */, + UnicodeString& toAppendTo, + FieldPositionIterator* /* unused posIter */, + UErrorCode& status) const +{ + if (!U_FAILURE(status)) { + status = U_UNSUPPORTED_ERROR; + } + return toAppendTo; +} + +// ------------------------------------- +// Parses the source string and create the corresponding // result object. Checks the parse position for errors. - + void -Format::parseObject(const UnicodeString& source, - Formattable& result, +Format::parseObject(const UnicodeString& source, + Formattable& result, UErrorCode& status) const { if (U_FAILURE(status)) return; @@ -114,14 +150,14 @@ Format::parseObject(const UnicodeString& source, status = U_INVALID_FORMAT_ERROR; } } - + // ------------------------------------- UBool -Format::operator==(const Format& /*that*/) const +Format::operator==(const Format& that) const { - // Add this implementation to make linker happy. - return TRUE; + // Subclasses: Call this method and then add more specific checks. + return typeid(*this) == typeid(that); } //--------------------------------------- @@ -138,24 +174,42 @@ void Format::syntaxError(const UnicodeString& pattern, UParseError& parseError) { parseError.offset = pos; parseError.line=0; // we are not using line number - + // for pre-context - int32_t start = (pos <=U_PARSE_CONTEXT_LEN)? 0 : (pos - (U_PARSE_CONTEXT_LEN-1 + int32_t start = (pos < U_PARSE_CONTEXT_LEN)? 0 : (pos - (U_PARSE_CONTEXT_LEN-1 /* subtract 1 so that we have room for null*/)); int32_t stop = pos; pattern.extract(start,stop-start,parseError.preContext,0); //null terminate the buffer parseError.preContext[stop-start] = 0; - + //for post-context start = pos+1; - stop = ((pos+U_PARSE_CONTEXT_LEN)<=pattern.length()) ? (pos+(U_PARSE_CONTEXT_LEN-1)) : + stop = ((pos+U_PARSE_CONTEXT_LEN)<=pattern.length()) ? (pos+(U_PARSE_CONTEXT_LEN-1)) : pattern.length(); pattern.extract(start,stop-start,parseError.postContext,0); //null terminate the buffer parseError.postContext[stop-start]= 0; } +Locale +Format::getLocale(ULocDataLocaleType type, UErrorCode& status) const { + U_LOCALE_BASED(locBased, *this); + return locBased.getLocale(type, status); +} + +const char * +Format::getLocaleID(ULocDataLocaleType type, UErrorCode& status) const { + U_LOCALE_BASED(locBased, *this); + return locBased.getLocaleID(type, status); +} + +void +Format::setLocaleIDs(const char* valid, const char* actual) { + U_LOCALE_BASED(locBased, *this); + locBased.setLocaleIDs(valid, actual); +} + U_NAMESPACE_END #endif /* #if !UCONFIG_NO_FORMATTING */