1c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org/* 2c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org******************************************************************************* 3c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org* Copyright (C) 1997-2012, International Business Machines Corporation and * 4c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org* others. All Rights Reserved. * 5c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org******************************************************************************* 6c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org* 7c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org* File FORMAT.CPP 8c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org* 9c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org* Modification History: 10c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org* 11c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org* Date Name Description 12c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org* 02/19/97 aliu Converted from java. 138b0e8ac5f582de80356019406e2975079bf0829dcommit-bot@chromium.org* 03/17/97 clhuang Implemented with new APIs. 148b0e8ac5f582de80356019406e2975079bf0829dcommit-bot@chromium.org* 03/27/97 helena Updated to pass the simple test after code review. 15c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org* 07/20/98 stephen Added explicit init values for Field/ParsePosition 16c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org******************************************************************************** 17c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org*/ 18c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org// ***************************************************************************** 19c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org// This file was generated from the java source file Format.java 20c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org// ***************************************************************************** 218b0e8ac5f582de80356019406e2975079bf0829dcommit-bot@chromium.org 22c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org#include "utypeinfo.h" // for 'typeid' to work 23c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org 24c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org#include "unicode/utypes.h" 25c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org 260951fe12984944406e0f1bb105b9fa4c54fcdcddsugoi#ifndef U_I18N_IMPLEMENTATION 27c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org#error U_I18N_IMPLEMENTATION not set - must be set for all ICU source files in i18n/ - see http://userguide.icu-project.org/howtouseicu 28c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org#endif 29c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org 30c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org/* 31c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org * Dummy code: 32c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org * If all modules in the I18N library are switched off, then there are no 33c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org * library exports and MSVC 6 writes a .dll but not a .lib file. 34c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org * Unless we export _something_ in that case... 35c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org */ 36c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org#if UCONFIG_NO_COLLATION && UCONFIG_NO_FORMATTING && UCONFIG_NO_TRANSLITERATION 37c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.orgU_CAPI int32_t U_EXPORT2 38c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.orguprv_icuin_lib_dummy(int32_t i) { 39c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org return -i; 40c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org} 41c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org#endif 42c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org 4383f23d87f1d67e6e73873e1ef7cda621c43703a0commit-bot@chromium.org/* Format class implementation ---------------------------------------------- */ 44c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org 45c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org#if !UCONFIG_NO_FORMATTING 46c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org 47c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org#include "unicode/format.h" 48c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org#include "unicode/ures.h" 49c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org#include "cstring.h" 50c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org#include "locbased.h" 51c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org 52025128811219dc45fd99b6c4d1d14f833cf7a26ecommit-bot@chromium.org// ***************************************************************************** 53025128811219dc45fd99b6c4d1d14f833cf7a26ecommit-bot@chromium.org// class Format 54025128811219dc45fd99b6c4d1d14f833cf7a26ecommit-bot@chromium.org// ***************************************************************************** 55025128811219dc45fd99b6c4d1d14f833cf7a26ecommit-bot@chromium.org 56025128811219dc45fd99b6c4d1d14f833cf7a26ecommit-bot@chromium.orgU_NAMESPACE_BEGIN 57c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org 58c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.orgUOBJECT_DEFINE_RTTI_IMPLEMENTATION(FieldPosition) 59c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org 60c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.orgFieldPosition::~FieldPosition() {} 61c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org 62025128811219dc45fd99b6c4d1d14f833cf7a26ecommit-bot@chromium.orgFieldPosition * 63c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.orgFieldPosition::clone() const { 648f457e3230f1a4ce737f512ffbb5c919b8d02407commit-bot@chromium.org return new FieldPosition(*this); 65c2e9db30d393862bd3485cfe57b4ac06433f2f32commit-bot@chromium.org} 66c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org 67ef74fa189b738e13295d6a96f86a6e10223505a8commit-bot@chromium.org// ------------------------------------- 68ef74fa189b738e13295d6a96f86a6e10223505a8commit-bot@chromium.org// default constructor 69c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org 70025128811219dc45fd99b6c4d1d14f833cf7a26ecommit-bot@chromium.orgFormat::Format() 71025128811219dc45fd99b6c4d1d14f833cf7a26ecommit-bot@chromium.org : UObject() 72c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org{ 73c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org *validLocale = *actualLocale = 0; 74c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org} 75c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org 76c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org// ------------------------------------- 77c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org 78c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.orgFormat::~Format() 79c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org{ 808b0e8ac5f582de80356019406e2975079bf0829dcommit-bot@chromium.org} 81c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org 82c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org// ------------------------------------- 83c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org// copy constructor 84 85Format::Format(const Format &that) 86 : UObject(that) 87{ 88 *this = that; 89} 90 91// ------------------------------------- 92// assignment operator 93 94Format& 95Format::operator=(const Format& that) 96{ 97 if (this != &that) { 98 uprv_strcpy(validLocale, that.validLocale); 99 uprv_strcpy(actualLocale, that.actualLocale); 100 } 101 return *this; 102} 103 104// ------------------------------------- 105// Formats the obj and append the result in the buffer, toAppendTo. 106// This calls the actual implementation in the concrete subclasses. 107 108UnicodeString& 109Format::format(const Formattable& obj, 110 UnicodeString& toAppendTo, 111 UErrorCode& status) const 112{ 113 if (U_FAILURE(status)) return toAppendTo; 114 115 FieldPosition pos(FieldPosition::DONT_CARE); 116 117 return format(obj, toAppendTo, pos, status); 118} 119 120// ------------------------------------- 121// Default implementation sets unsupported error; subclasses should 122// override. 123 124UnicodeString& 125Format::format(const Formattable& /* unused obj */, 126 UnicodeString& toAppendTo, 127 FieldPositionIterator* /* unused posIter */, 128 UErrorCode& status) const 129{ 130 if (!U_FAILURE(status)) { 131 status = U_UNSUPPORTED_ERROR; 132 } 133 return toAppendTo; 134} 135 136// ------------------------------------- 137// Parses the source string and create the corresponding 138// result object. Checks the parse position for errors. 139 140void 141Format::parseObject(const UnicodeString& source, 142 Formattable& result, 143 UErrorCode& status) const 144{ 145 if (U_FAILURE(status)) return; 146 147 ParsePosition parsePosition(0); 148 parseObject(source, result, parsePosition); 149 if (parsePosition.getIndex() == 0) { 150 status = U_INVALID_FORMAT_ERROR; 151 } 152} 153 154// ------------------------------------- 155 156UBool 157Format::operator==(const Format& that) const 158{ 159 // Subclasses: Call this method and then add more specific checks. 160 return typeid(*this) == typeid(that); 161} 162//--------------------------------------- 163 164/** 165 * Simple function for initializing a UParseError from a UnicodeString. 166 * 167 * @param pattern The pattern to copy into the parseError 168 * @param pos The position in pattern where the error occured 169 * @param parseError The UParseError object to fill in 170 * @draft ICU 2.4 171 */ 172void Format::syntaxError(const UnicodeString& pattern, 173 int32_t pos, 174 UParseError& parseError) { 175 parseError.offset = pos; 176 parseError.line=0; // we are not using line number 177 178 // for pre-context 179 int32_t start = (pos < U_PARSE_CONTEXT_LEN)? 0 : (pos - (U_PARSE_CONTEXT_LEN-1 180 /* subtract 1 so that we have room for null*/)); 181 int32_t stop = pos; 182 pattern.extract(start,stop-start,parseError.preContext,0); 183 //null terminate the buffer 184 parseError.preContext[stop-start] = 0; 185 186 //for post-context 187 start = pos+1; 188 stop = ((pos+U_PARSE_CONTEXT_LEN)<=pattern.length()) ? (pos+(U_PARSE_CONTEXT_LEN-1)) : 189 pattern.length(); 190 pattern.extract(start,stop-start,parseError.postContext,0); 191 //null terminate the buffer 192 parseError.postContext[stop-start]= 0; 193} 194 195Locale 196Format::getLocale(ULocDataLocaleType type, UErrorCode& status) const { 197 U_LOCALE_BASED(locBased, *this); 198 return locBased.getLocale(type, status); 199} 200 201const char * 202Format::getLocaleID(ULocDataLocaleType type, UErrorCode& status) const { 203 U_LOCALE_BASED(locBased, *this); 204 return locBased.getLocaleID(type, status); 205} 206 207void 208Format::setLocaleIDs(const char* valid, const char* actual) { 209 U_LOCALE_BASED(locBased, *this); 210 locBased.setLocaleIDs(valid, actual); 211} 212 213U_NAMESPACE_END 214 215#endif /* #if !UCONFIG_NO_FORMATTING */ 216 217//eof 218