1999-08-16 21:50:52 +00:00
|
|
|
/*
|
1999-11-22 20:25:35 +00:00
|
|
|
*******************************************************************************
|
2007-08-29 02:57:42 +00:00
|
|
|
* Copyright (C) 1997-2007, International Business Machines Corporation and *
|
1999-11-22 20:25:35 +00:00
|
|
|
* others. All Rights Reserved. *
|
|
|
|
*******************************************************************************
|
1999-08-16 21:50:52 +00:00
|
|
|
*
|
|
|
|
* File FORMAT.CPP
|
|
|
|
*
|
|
|
|
* Modification History:
|
|
|
|
*
|
|
|
|
* Date Name Description
|
|
|
|
* 02/19/97 aliu Converted from java.
|
|
|
|
* 03/17/97 clhuang Implemented with new APIs.
|
|
|
|
* 03/27/97 helena Updated to pass the simple test after code review.
|
1999-11-22 20:25:35 +00:00
|
|
|
* 07/20/98 stephen Added explicit init values for Field/ParsePosition
|
1999-08-16 21:50:52 +00:00
|
|
|
********************************************************************************
|
|
|
|
*/
|
|
|
|
// *****************************************************************************
|
|
|
|
// This file was generated from the java source file Format.java
|
|
|
|
// *****************************************************************************
|
|
|
|
|
2002-09-20 01:54:48 +00:00
|
|
|
#include "unicode/utypes.h"
|
|
|
|
|
2002-10-01 01:26:49 +00:00
|
|
|
/*
|
|
|
|
* Dummy code:
|
|
|
|
* If all modules in the I18N library are switched off, then there are no
|
|
|
|
* library exports and MSVC 6 writes a .dll but not a .lib file.
|
|
|
|
* Unless we export _something_ in that case...
|
|
|
|
*/
|
|
|
|
#if UCONFIG_NO_COLLATION && UCONFIG_NO_FORMATTING && UCONFIG_NO_TRANSLITERATION
|
|
|
|
U_CAPI int32_t U_EXPORT2
|
|
|
|
uprv_icuin_lib_dummy(int32_t i) {
|
|
|
|
return -i;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Format class implementation ---------------------------------------------- */
|
|
|
|
|
2002-09-20 01:54:48 +00:00
|
|
|
#if !UCONFIG_NO_FORMATTING
|
|
|
|
|
1999-12-28 23:57:50 +00:00
|
|
|
#include "unicode/format.h"
|
2004-09-03 15:24:16 +00:00
|
|
|
#include "unicode/ures.h"
|
2004-01-20 23:06:38 +00:00
|
|
|
#include "cstring.h"
|
|
|
|
#include "locbased.h"
|
2001-08-16 00:55:16 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
// *****************************************************************************
|
|
|
|
// class Format
|
|
|
|
// *****************************************************************************
|
2001-10-08 23:26:58 +00:00
|
|
|
|
|
|
|
U_NAMESPACE_BEGIN
|
|
|
|
|
2003-09-02 20:17:13 +00:00
|
|
|
UOBJECT_DEFINE_RTTI_IMPLEMENTATION(FieldPosition)
|
2003-11-05 21:59:41 +00:00
|
|
|
|
2003-09-02 20:17:13 +00:00
|
|
|
FieldPosition::~FieldPosition() {}
|
2001-10-08 23:26:58 +00:00
|
|
|
|
2003-11-05 21:59:41 +00:00
|
|
|
FieldPosition *
|
|
|
|
FieldPosition::clone() const {
|
|
|
|
return new FieldPosition(*this);
|
|
|
|
}
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
// -------------------------------------
|
|
|
|
// default constructor
|
|
|
|
|
|
|
|
Format::Format()
|
2002-07-02 23:58:34 +00:00
|
|
|
: UObject()
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2004-01-20 23:06:38 +00:00
|
|
|
*validLocale = *actualLocale = 0;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------------------------
|
|
|
|
|
|
|
|
Format::~Format()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------------------------
|
|
|
|
// copy constructor
|
|
|
|
|
2002-07-02 23:58:34 +00:00
|
|
|
Format::Format(const Format &that)
|
|
|
|
: UObject(that)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2004-01-20 23:06:38 +00:00
|
|
|
*this = that;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------------------------
|
|
|
|
// assignment operator
|
|
|
|
|
|
|
|
Format&
|
2004-01-20 23:06:38 +00:00
|
|
|
Format::operator=(const Format& that)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2004-01-20 23:06:38 +00:00
|
|
|
uprv_strcpy(validLocale, that.validLocale);
|
|
|
|
uprv_strcpy(actualLocale, that.actualLocale);
|
1999-08-16 21:50:52 +00:00
|
|
|
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,
|
|
|
|
UErrorCode& status) const
|
|
|
|
{
|
1999-10-18 22:48:32 +00:00
|
|
|
if (U_FAILURE(status)) return toAppendTo;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2004-04-21 17:58:13 +00:00
|
|
|
FieldPosition pos(FieldPosition::DONT_CARE);
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
return format(obj, toAppendTo, pos, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------------------------
|
|
|
|
// Parses the source string and create the corresponding
|
|
|
|
// result object. Checks the parse position for errors.
|
|
|
|
|
|
|
|
void
|
|
|
|
Format::parseObject(const UnicodeString& source,
|
|
|
|
Formattable& result,
|
|
|
|
UErrorCode& status) const
|
|
|
|
{
|
1999-10-18 22:48:32 +00:00
|
|
|
if (U_FAILURE(status)) return;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
ParsePosition parsePosition(0);
|
|
|
|
parseObject(source, result, parsePosition);
|
|
|
|
if (parsePosition.getIndex() == 0) {
|
1999-10-07 00:07:53 +00:00
|
|
|
status = U_INVALID_FORMAT_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------------------------
|
|
|
|
|
2000-05-18 22:08:39 +00:00
|
|
|
UBool
|
2004-02-13 01:50:59 +00:00
|
|
|
Format::operator==(const Format& that) const
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2004-02-13 01:50:59 +00:00
|
|
|
// Subclasses: Call this method and then add more specific checks.
|
|
|
|
return getDynamicClassID() == that.getDynamicClassID();
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
2001-08-17 02:20:35 +00:00
|
|
|
//---------------------------------------
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2003-01-27 17:26:06 +00:00
|
|
|
/**
|
|
|
|
* Simple function for initializing a UParseError from a UnicodeString.
|
|
|
|
*
|
|
|
|
* @param pattern The pattern to copy into the parseError
|
|
|
|
* @param pos The position in pattern where the error occured
|
|
|
|
* @param parseError The UParseError object to fill in
|
|
|
|
* @draft ICU 2.4
|
|
|
|
*/
|
|
|
|
void Format::syntaxError(const UnicodeString& pattern,
|
|
|
|
int32_t pos,
|
|
|
|
UParseError& parseError) {
|
|
|
|
parseError.offset = pos;
|
|
|
|
parseError.line=0; // we are not using line number
|
|
|
|
|
|
|
|
// for pre-context
|
2007-08-29 02:57:42 +00:00
|
|
|
int32_t start = (pos < U_PARSE_CONTEXT_LEN)? 0 : (pos - (U_PARSE_CONTEXT_LEN-1
|
2003-01-27 17:26:06 +00:00
|
|
|
/* 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)) :
|
|
|
|
pattern.length();
|
|
|
|
pattern.extract(start,stop-start,parseError.postContext,0);
|
|
|
|
//null terminate the buffer
|
|
|
|
parseError.postContext[stop-start]= 0;
|
|
|
|
}
|
|
|
|
|
2004-01-20 23:06:38 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2001-10-08 23:26:58 +00:00
|
|
|
U_NAMESPACE_END
|
|
|
|
|
2002-09-20 01:54:48 +00:00
|
|
|
#endif /* #if !UCONFIG_NO_FORMATTING */
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
//eof
|