ICU-6694 Implementation of numbering systems and the @numbers keyword

X-SVN-Rev: 25285
This commit is contained in:
John Emmons 2009-01-22 04:46:35 +00:00
parent 146306ccc8
commit 6070262c2f
30 changed files with 625 additions and 32 deletions

2
.gitattributes vendored
View File

@ -129,11 +129,13 @@ icu4c/source/extra/uconv/pkgdataMakefile.in -text
icu4c/source/i18n/dtitv_impl.h -text
icu4c/source/i18n/dtitvfmt.cpp -text
icu4c/source/i18n/dtitvinf.cpp -text
icu4c/source/i18n/numsys.cpp -text
icu4c/source/i18n/tmunit.cpp -text
icu4c/source/i18n/tmutamt.cpp -text
icu4c/source/i18n/tmutfmt.cpp -text
icu4c/source/i18n/unicode/dtitvfmt.h -text
icu4c/source/i18n/unicode/dtitvinf.h -text
icu4c/source/i18n/unicode/numsys.h -text
icu4c/source/i18n/unicode/tmunit.h -text
icu4c/source/i18n/unicode/tmutamt.h -text
icu4c/source/i18n/unicode/tmutfmt.h -text

View File

@ -1,6 +1,6 @@
// ***************************************************************************
// *
// * Copyright (C) 2008 International Business Machines
// * Copyright (C) 2009 International Business Machines
// * Corporation and others. All Rights Reserved.
// * Tool: com.ibm.icu.dev.tool.cldr.LDML2ICUConverter.java
// * Source File:<path>/common/main/ar.xml
@ -2677,4 +2677,5 @@ ar{
ec{"واك"}
}
}
defaultNumberingSystem{"arabic-indic"}
}

View File

@ -1,6 +1,6 @@
// ***************************************************************************
// *
// * Copyright (C) 2008 International Business Machines
// * Copyright (C) 2009 International Business Machines
// * Corporation and others. All Rights Reserved.
// * Tool: com.ibm.icu.dev.tool.cldr.LDML2ICUConverter.java
// * Source File:<path>/common/main/ar_DZ.xml
@ -39,4 +39,5 @@ ar_DZ{
}
}
}
defaultNumberingSystem{"decimal"}
}

View File

@ -1,6 +1,6 @@
// ***************************************************************************
// *
// * Copyright (C) 2008 International Business Machines
// * Copyright (C) 2009 International Business Machines
// * Corporation and others. All Rights Reserved.
// * Tool: com.ibm.icu.dev.tool.cldr.LDML2ICUConverter.java
// * Source File:<path>/common/main/ar_MA.xml
@ -39,4 +39,5 @@ ar_MA{
}
}
}
defaultNumberingSystem{"decimal"}
}

View File

@ -1,6 +1,6 @@
// ***************************************************************************
// *
// * Copyright (C) 2008 International Business Machines
// * Copyright (C) 2009 International Business Machines
// * Corporation and others. All Rights Reserved.
// * Tool: com.ibm.icu.dev.tool.cldr.LDML2ICUConverter.java
// * Source File:<path>/common/main/ar_TN.xml
@ -58,4 +58,5 @@ ar_TN{
}
}
}
defaultNumberingSystem{"decimal"}
}

View File

@ -1,6 +1,6 @@
// ***************************************************************************
// *
// * Copyright (C) 2008 International Business Machines
// * Copyright (C) 2009 International Business Machines
// * Corporation and others. All Rights Reserved.
// * Tool: com.ibm.icu.dev.tool.cldr.LDML2ICUConverter.java
// * Source File:<path>/common/main/bn.xml
@ -3134,4 +3134,5 @@ bn{
hourFormat{"+HH:mm;-HH:mm"}
regionFormat{"{0} সময়"}
}
defaultNumberingSystem{"bengali"}
}

View File

@ -1,6 +1,6 @@
// ***************************************************************************
// *
// * Copyright (C) 2008 International Business Machines
// * Copyright (C) 2009 International Business Machines
// * Corporation and others. All Rights Reserved.
// * Tool: com.ibm.icu.dev.tool.cldr.LDML2ICUConverter.java
// * Source File:<path>/common/main/fa.xml
@ -2029,6 +2029,7 @@ fa{
script{"خط: {0}"}
territory{"ناحیه: {0}"}
}
defaultNumberingSystem{"persian"}
delimiters{
alternateQuotationEnd{""}
alternateQuotationStart{""}

View File

@ -1,6 +1,6 @@
// ***************************************************************************
// *
// * Copyright (C) 2008 International Business Machines
// * Copyright (C) 2009 International Business Machines
// * Corporation and others. All Rights Reserved.
// * Tool: com.ibm.icu.dev.tool.cldr.LDML2ICUConverter.java
// * Source File:<path>/common/main/gu.xml
@ -131,6 +131,7 @@ gu{
}
}
}
defaultNumberingSystem{"gujarati"}
delimiters{
alternateQuotationEnd{"\""}
alternateQuotationStart{"\""}

View File

@ -1,6 +1,6 @@
// ***************************************************************************
// *
// * Copyright (C) 2008 International Business Machines
// * Copyright (C) 2009 International Business Machines
// * Corporation and others. All Rights Reserved.
// * Tool: com.ibm.icu.dev.tool.cldr.LDML2ICUConverter.java
// * Source File:<path>/common/main/hi.xml
@ -2012,6 +2012,7 @@ hi{
}
}
}
defaultNumberingSystem{"devanagari"}
delimiters{
alternateQuotationEnd{"\""}
alternateQuotationStart{"\""}

View File

@ -1,6 +1,6 @@
// ***************************************************************************
// *
// * Copyright (C) 2008 International Business Machines
// * Copyright (C) 2009 International Business Machines
// * Corporation and others. All Rights Reserved.
// * Tool: com.ibm.icu.dev.tool.cldr.LDML2ICUConverter.java
// * Source File:<path>/common/main/ne.xml
@ -655,6 +655,7 @@ ne{
}
}
}
defaultNumberingSystem{"devanagari"}
delimiters{
alternateQuotationEnd{"\""}
alternateQuotationStart{"\""}

View File

@ -1,6 +1,6 @@
// ***************************************************************************
// *
// * Copyright (C) 2008 International Business Machines
// * Copyright (C) 2009 International Business Machines
// * Corporation and others. All Rights Reserved.
// * Tool: com.ibm.icu.dev.tool.cldr.LDML2ICUConverter.java
// * Source File:<path>/common/main/or.xml
@ -117,4 +117,5 @@ or{
}
}
}
defaultNumberingSystem{"oriya"}
}

View File

@ -1,6 +1,6 @@
// ***************************************************************************
// *
// * Copyright (C) 2008 International Business Machines
// * Copyright (C) 2009 International Business Machines
// * Corporation and others. All Rights Reserved.
// * Tool: com.ibm.icu.dev.tool.cldr.LDML2ICUConverter.java
// * Source File:<path>/common/main/pa.xml
@ -147,4 +147,5 @@ pa{
}
}
}
defaultNumberingSystem{"gurmukhi"}
}

View File

@ -1,6 +1,6 @@
// ***************************************************************************
// *
// * Copyright (C) 2008 International Business Machines
// * Copyright (C) 2009 International Business Machines
// * Corporation and others. All Rights Reserved.
// * Tool: com.ibm.icu.dev.tool.cldr.LDML2ICUConverter.java
// * Source File:<path>/common/main/ps.xml
@ -237,6 +237,7 @@ ps{
}
}
}
defaultNumberingSystem{"persian"}
layout{
characters{"right-to-left"}
lines{"top-to-bottom"}

View File

@ -1378,6 +1378,7 @@ root{
script{"{0}"}
territory{"{0}"}
}
defaultNumberingSystem{"decimal"}
delimiters{
alternateQuotationEnd{""}
alternateQuotationStart{""}

View File

@ -1,6 +1,6 @@
// ***************************************************************************
// *
// * Copyright (C) 2008 International Business Machines
// * Copyright (C) 2009 International Business Machines
// * Corporation and others. All Rights Reserved.
// * Tool: com.ibm.icu.dev.tool.cldr.LDML2ICUConverter.java
// * Source File:<path>/common/main/te.xml
@ -182,4 +182,5 @@ te{
}
}
}
defaultNumberingSystem{"telugu"}
}

View File

@ -1,6 +1,6 @@
// ***************************************************************************
// *
// * Copyright (C) 2008 International Business Machines
// * Copyright (C) 2009 International Business Machines
// * Corporation and others. All Rights Reserved.
// * Tool: com.ibm.icu.dev.tool.cldr.LDML2ICUConverter.java
// * Source File:<path>/common/main/uz_Arab.xml
@ -47,6 +47,7 @@ uz_Arab{
"+",
}
Version{"1.28"}
defaultNumberingSystem{"persian"}
layout{
characters{"right-to-left"}
lines{"top-to-bottom"}

View File

@ -1,4 +1,4 @@
# * Copyright (C) 2003-2008, International Business Machines
# * Copyright (C) 2003-2009, International Business Machines
# * Corporation and others. All Rights Reserved.
# A list of txt's to build
# Note:
@ -23,4 +23,4 @@
#
MISC_SOURCE = \
zoneinfo.txt supplementalData.txt metazoneInfo.txt likelySubtags.txt plurals.txt
zoneinfo.txt supplementalData.txt metazoneInfo.txt likelySubtags.txt plurals.txt numberingSystems.txt

View File

@ -1,4 +1,4 @@
// ***************************************************************************
// ***************************************************************************
// *
// * Copyright (C) 2009 International Business Machines
// * Corporation and others. All Rights Reserved.
@ -9,70 +9,87 @@
numberingSystems:table(nofallback){
numberingSystems{
arabic-indic{
algorithmic:int{0}
desc{"٠١٢٣٤٥٦٧٨٩"}
radix:int{10}
}
bengali{
algorithmic:int{0}
desc{"০১২৩৪৫৬৭৮৯"}
radix:int{10}
}
cambodian{
algorithmic:int{0}
desc{"០១២៣៤៥៦៧៨៩"}
radix:int{10}
}
decimal{
algorithmic:int{0}
desc{"0123456789"}
radix:int{10}
}
devanagari{
algorithmic:int{0}
desc{"०१२३४५६७८९"}
radix:int{10}
}
gujarati{
algorithmic:int{0}
desc{"૦૧૨૩૪૫૬૭૮૯"}
radix:int{10}
}
gurmukhi{
algorithmic:int{0}
desc{"੦੧੨੩੪੫੬੭੮੯"}
radix:int{10}
}
hebrew{
desc{"hebrew"}
radix:int{0}
algorithmic:int{1}
desc{"%hebrew"}
radix:int{10}
}
kannada{
algorithmic:int{0}
desc{"೦೧೨೩೪೫೬೭೮೯"}
radix:int{10}
}
lao{
algorithmic:int{0}
desc{"໐໑໒໓໔໕໖໗໘໙"}
radix:int{10}
}
malayalam{
algorithmic:int{0}
desc{"൦൧൨൩൪൬൭൮൯"}
radix:int{10}
}
mongolian{
algorithmic:int{0}
desc{"᠐᠑᠒᠓᠔᠕᠖᠗᠘᠙"}
radix:int{10}
}
myanmar{
algorithmic:int{0}
desc{"၀၁၂၃၄၅၆၇၈၉"}
radix:int{10}
}
oriya{
algorithmic:int{0}
desc{"୦୧୨୩୪୫୬୭୮୯"}
radix:int{10}
}
persian{
algorithmic:int{0}
desc{"۰۱۲۳۴۵۶۷۸۹"}
radix:int{10}
}
telugu{
algorithmic:int{0}
desc{"౦౧౨౩౪౫౬౭౮౯"}
radix:int{10}
}
thai{
algorithmic:int{0}
desc{"๐๑๒๓๔๕๖๗๘๙"}
radix:int{10}
}

View File

@ -65,7 +65,7 @@ OBJECTS = ucln_in.o \
fmtable.o format.o msgfmt.o umsg.o numfmt.o unum.o decimfmt.o dcfmtsym.o \
ucurr.o digitlst.o fmtable_cnv.o \
choicfmt.o datefmt.o smpdtfmt.o reldtfmt.o dtfmtsym.o udat.o dtptngen.o \
nfrs.o nfrule.o nfsubs.o rbnf.o ucsdet.o \
nfrs.o nfrule.o nfsubs.o rbnf.o numsys.o ucsdet.o \
ucal.o calendar.o gregocal.o timezone.o simpletz.o olsontz.o \
astro.o taiwncal.o buddhcal.o persncal.o islamcal.o japancal.o gregoimp.o hebrwcal.o \
indiancal.o chnsecal.o cecal.o coptccal.o ethpccal.o \

View File

@ -2034,6 +2034,50 @@
/>
</FileConfiguration>
</File>
<File
RelativePath=".\numsys.cpp"
>
</File>
<File
RelativePath=".\unicode\numsys.h"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCustomBuildTool"
CommandLine="copy &quot;$(InputPath)&quot; ..\..\include\unicode&#x0D;&#x0A;"
Outputs="..\..\include\unicode\$(InputFileName)"
/>
</FileConfiguration>
<FileConfiguration
Name="Release|x64"
>
<Tool
Name="VCCustomBuildTool"
CommandLine="copy &quot;$(InputPath)&quot; ..\..\include\unicode&#x0D;&#x0A;"
Outputs="..\..\include\unicode\$(InputFileName)"
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCustomBuildTool"
CommandLine="copy &quot;$(InputPath)&quot; ..\..\include\unicode&#x0D;&#x0A;"
Outputs="..\..\include\unicode\$(InputFileName)"
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|x64"
>
<Tool
Name="VCCustomBuildTool"
CommandLine="copy &quot;$(InputPath)&quot; ..\..\include\unicode&#x0D;&#x0A;"
Outputs="..\..\include\unicode\$(InputFileName)"
/>
</FileConfiguration>
</File>
<File
RelativePath=".\olsontz.cpp"
>

View File

@ -1,6 +1,6 @@
/*
*******************************************************************************
* Copyright (C) 1997-2008, International Business Machines Corporation and *
* Copyright (C) 1997-2009, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*
@ -33,6 +33,8 @@
#include "unicode/ustring.h"
#include "unicode/ucurr.h"
#include "unicode/curramt.h"
#include "unicode/numsys.h"
#include "unicode/rbnf.h"
#include "winnmfmt.h"
#include "uresimp.h"
#include "uhash.h"
@ -896,13 +898,29 @@ NumberFormat::makeInstance(const Locale& desiredLocale,
pattern.setTo(currPattern, u_strlen(currPattern));
}
}
f = new DecimalFormat(pattern, symbolsToAdopt, status);
if (U_FAILURE(status) || f == NULL) {
NumberingSystem *ns = NumberingSystem::createInstance(desiredLocale,status);
if (U_FAILURE(status)) {
goto cleanup;
}
if (ns->isAlgorithmic()) {
RuleBasedNumberFormat *r = new RuleBasedNumberFormat(URBNF_NUMBERING_SYSTEM,desiredLocale,status);
if (U_FAILURE(status) || r == NULL) {
goto cleanup;
}
r->setDefaultRuleSet(ns->getDescription(),status);
f = (NumberFormat *) r;
} else {
UnicodeString zeroDigit(ns->getDescription(),0,1);
symbolsToAdopt->setSymbol(DecimalFormatSymbols::kZeroDigitSymbol,zeroDigit);
f = new DecimalFormat(pattern, symbolsToAdopt, status);
}
f->setLocaleIDs(ures_getLocaleByType(numberPatterns, ULOC_VALID_LOCALE, &status),
ures_getLocaleByType(numberPatterns, ULOC_ACTUAL_LOCALE, &status));
cleanup:
ures_close(numberPatterns);
ures_close(resource);

View File

@ -0,0 +1,220 @@
/*
*******************************************************************************
* Copyright (C) 2009, International Business Machines Corporation and
* others. All Rights Reserved.
*******************************************************************************
*
*
* File NUMSYS.CPP
*
* Modification History:*
* Date Name Description
*
********************************************************************************
*/
#include "unicode/utypes.h"
#include "unicode/uchar.h"
#include "unicode/unistr.h"
#include "unicode/ures.h"
#include "unicode/ustring.h"
#include "unicode/uloc.h"
#include "unicode/schriter.h"
#include "unicode/numsys.h"
#include "uresimp.h"
#if !UCONFIG_NO_FORMATTING
U_NAMESPACE_BEGIN
// Useful constants
#define DEFAULT_DIGITS UNICODE_STRING_SIMPLE("0123456789");
static const char gNumberingSystems[] = "numberingSystems";
static const char gDefaultNumberingSystem[] = "defaultNumberingSystem";
static const char gDesc[] = "desc";
static const char gRadix[] = "radix";
static const char gAlgorithmic[] = "algorithmic";
UOBJECT_DEFINE_RTTI_IMPLEMENTATION(NumberingSystem)
/**
* Default Constructor.
*
* @draft ICU 4.2
*/
NumberingSystem::NumberingSystem() {
radix = 10;
algorithmic = FALSE;
UnicodeString defaultDigits = DEFAULT_DIGITS;
desc.setTo(defaultDigits);
}
/**
* Copy constructor.
* @draft ICU 4.2
*/
NumberingSystem::NumberingSystem(const NumberingSystem& other) {
*this=other;
}
NumberingSystem* U_EXPORT2
NumberingSystem::createInstance(int32_t radix_in, UBool isAlgorithmic_in, const UnicodeString & desc_in, UErrorCode &status) {
if ( radix_in < 2 ) {
status = U_ILLEGAL_ARGUMENT_ERROR;
return NULL;
}
if ( !isAlgorithmic_in ) {
if ( desc_in.countChar32() != radix_in || !isValidDigitString(desc_in)) {
status = U_ILLEGAL_ARGUMENT_ERROR;
return NULL;
}
}
NumberingSystem *ns = new NumberingSystem();
ns->setRadix(radix_in);
ns->setDesc(desc_in);
ns->setAlgorithmic(isAlgorithmic_in);
return ns;
}
NumberingSystem* U_EXPORT2
NumberingSystem::createInstance(const Locale & inLocale, UErrorCode& status) {
char buffer[ULOC_KEYWORDS_CAPACITY];
int32_t count = inLocale.getKeywordValue("numbers",buffer, sizeof(buffer),status);
if ( count > 0 ) { // @numbers keyword was specified in the locale
buffer[count] = '\0'; // Make sure it is null terminated.
return NumberingSystem::createInstanceByName(buffer,status);
} else { // Find the default numbering system for this locale.
UResourceBundle *resource = ures_open(NULL,inLocale.getName(),&status);
if (U_FAILURE(status)) {
status = U_USING_FALLBACK_WARNING;
NumberingSystem *ns = new NumberingSystem();
ures_close(resource);
return ns;
}
const UChar *defaultNSName = ures_getStringByKeyWithFallback(resource,gDefaultNumberingSystem,&count,&status);
if ( count > 0 && count < ULOC_KEYWORDS_CAPACITY ) { // Default numbering system found
u_UCharsToChars(defaultNSName,buffer,count);
buffer[count] = '\0'; // Make sure it is null terminated.
ures_close(resource);
return NumberingSystem::createInstanceByName(buffer,status);
} else {
status = U_USING_FALLBACK_WARNING;
NumberingSystem *ns = new NumberingSystem();
ures_close(resource);
return ns;
}
}
}
NumberingSystem* U_EXPORT2
NumberingSystem::createInstance(UErrorCode& status) {
return NumberingSystem::createInstance(Locale::getDefault(), status);
}
NumberingSystem* U_EXPORT2
NumberingSystem::createInstanceByName(const char *name, UErrorCode& status) {
UResourceBundle *numberingSystemsInfo = NULL;
UResourceBundle *nsCurrent = NULL;
const UChar* description = NULL;
int32_t radix = 10;
int32_t algorithmic = 0;
int32_t len;
numberingSystemsInfo = ures_openDirect(NULL,gNumberingSystems, &status);
numberingSystemsInfo = ures_getByKey(numberingSystemsInfo,gNumberingSystems,numberingSystemsInfo,&status);
numberingSystemsInfo = ures_getByKey(numberingSystemsInfo,name,numberingSystemsInfo,&status);
description = ures_getStringByKey(numberingSystemsInfo,gDesc,&len,&status);
nsCurrent = ures_getByKey(numberingSystemsInfo,gRadix,nsCurrent,&status);
radix = ures_getInt(nsCurrent,&status);
nsCurrent = ures_getByKey(numberingSystemsInfo,gAlgorithmic,nsCurrent,&status);
algorithmic = ures_getInt(nsCurrent,&status);
UBool isAlgorithmic = ( algorithmic == 1 );
UnicodeString nsd;
nsd.setTo(description);
if (U_FAILURE(status)) {
status = U_UNSUPPORTED_ERROR;
return NULL;
}
ures_close(numberingSystemsInfo);
return NumberingSystem::createInstance(radix,isAlgorithmic,nsd,status);
}
/**
* Destructor.
* @draft ICU 4.2
*/
NumberingSystem::~NumberingSystem() {
}
int32_t NumberingSystem::getRadix() {
return radix;
}
UnicodeString NumberingSystem::getDescription() {
return desc;
}
void NumberingSystem::setRadix(int32_t r) {
radix = r;
}
void NumberingSystem::setAlgorithmic(UBool c) {
algorithmic = c;
}
void NumberingSystem::setDesc(UnicodeString d) {
desc.setTo(d);
}
UBool NumberingSystem::isAlgorithmic() const {
return ( algorithmic );
}
UBool NumberingSystem::isValidDigitString(const UnicodeString& str) {
StringCharacterIterator it(str);
UChar32 c;
UChar32 prev = 0;
int32_t i = 0;
for ( it.setToStart(); it.hasNext(); ) {
c = it.next32PostInc();
if ( u_charDigitValue(c) != i ) { // Digits outside the Unicode decimal digit class are not currently supported
return FALSE;
}
if ( prev != 0 && c != prev + 1 ) { // Non-contiguous digits are not currently supported
return FALSE;
}
if ( c > 0xFFFF ) { // Digits outside the BMP are not currently supported
return FALSE;
}
i++;
prev = c;
}
return TRUE;
}
U_NAMESPACE_END
#endif /* #if !UCONFIG_NO_FORMATTING */
//eof

View File

@ -1,6 +1,6 @@
/*
*******************************************************************************
* Copyright (C) 1997-2008, International Business Machines Corporation
* Copyright (C) 1997-2009, International Business Machines Corporation
* and others. All Rights Reserved.
*******************************************************************************
*/
@ -739,6 +739,7 @@ RuleBasedNumberFormat::RuleBasedNumberFormat(URBNFRuleSetTag tag, const Locale&
case URBNF_SPELLOUT: fmt_tag = "SpelloutRules"; break;
case URBNF_ORDINAL: fmt_tag = "OrdinalRules"; break;
case URBNF_DURATION: fmt_tag = "DurationRules"; break;
case URBNF_NUMBERING_SYSTEM: fmt_tag = "NumberingSystemRules"; break;
default: status = U_ILLEGAL_ARGUMENT_ERROR; return;
}

View File

@ -0,0 +1,160 @@
/*
*******************************************************************************
* Copyright (C) 2009, International Business Machines Corporation and
* others. All Rights Reserved.
*******************************************************************************
*
*
* File NUMSYS.H
*
* Modification History:*
* Date Name Description
*
********************************************************************************
*/
#ifndef NUMSYS
#define NUMSYS
#include "unicode/utypes.h"
/**
* \file
* \brief C++ API: NumberingSystems object
*/
#if !UCONFIG_NO_FORMATTING
#include "unicode/format.h"
#include "unicode/uobject.h"
U_NAMESPACE_BEGIN
/**
* Defines numbering systems. Put more description here.
*/
class U_I18N_API NumberingSystem : public UObject {
public:
/**
* Default Constructor.
*
* @draft ICU 4.2
*/
NumberingSystem();
/**
* Copy constructor.
* @draft ICU 4.2
*/
NumberingSystem(const NumberingSystem& other);
/**
* Destructor.
* @draft ICU 4.2
*/
virtual ~NumberingSystem();
/**
* Create the default numbering system associated with the specified locale.
* @param inLocale The given locale.
* @draft ICU 4.2
*/
static NumberingSystem* U_EXPORT2 createInstance(const Locale & inLocale, UErrorCode& status);
/**
* Create the default numbering system associated with the default locale.
* @draft ICU 4.2
*/
static NumberingSystem* U_EXPORT2 createInstance(UErrorCode& status);
/**
* Create a numbering system using the specified radix, type, and description.
* @param radix The radix (base) for this numbering system.
* @param isAlgorithmic TRUE if the numbering system is algorithmic rather than numeric.
* @param description The string representing the set of digits used in a numeric system, or the name of the RBNF
* ruleset to be used in an algorithmic system.
* @draft ICU 4.2
*/
static NumberingSystem* U_EXPORT2 createInstance(int32_t radix, UBool isAlgorithmic, const UnicodeString& description, UErrorCode& status );
/**
* Return a StringEnumeration over all the names of numbering systems known to ICU.
* @draft ICU 4.2
*/
static StringEnumeration * U_EXPORT2 getAvailableNames(UErrorCode& status);
/**
* Create a numbering system from one of the predefined numbering systems known to ICU.
* @param name The name of the numbering system.
* @draft ICU 4.2
*/
static NumberingSystem* U_EXPORT2 createInstanceByName(const char* name, UErrorCode& status);
/**
* Returns the radix of this numbering system.
* @draft ICU 4.2
*/
int32_t getRadix();
/**
* Returns the description string of this numbering system, which is either
* the string of digits in the case of simple systems, or the ruleset name
* in the case of algorithmic systems.
* @draft ICU 4.2
*/
virtual UnicodeString getDescription();
/**
* Returns TRUE if the given numbering system is algorithmic
*
* @return TRUE if the numbering system is algorithmic.
* Otherwise, return FALSE.
* @draft ICU 4.2
*/
UBool isAlgorithmic() const;
/**
* ICU "poor man's RTTI", returns a UClassID for this class.
*
* @draft ICU 4.0
*
*/
static UClassID U_EXPORT2 getStaticClassID(void);
/**
* ICU "poor man's RTTI", returns a UClassID for the actual class.
*
* @draft ICU 4.0
*/
virtual UClassID getDynamicClassID() const;
private:
UnicodeString desc;
int32_t radix;
UBool algorithmic;
void setRadix(int32_t radix);
void setAlgorithmic(UBool algorithmic);
void setDesc(UnicodeString desc);
static UBool isValidDigitString(const UnicodeString &str);
UBool hasContiguousDecimalDigits() const;
};
U_NAMESPACE_END
#endif /* #if !UCONFIG_NO_FORMATTING */
#endif // _NUMSYS
//eof

View File

@ -1,6 +1,6 @@
/*
*******************************************************************************
* Copyright (C) 1997-2006, International Business Machines Corporation and others.
* Copyright (C) 1997-2009, International Business Machines Corporation and others.
* All Rights Reserved.
*******************************************************************************
*/
@ -49,6 +49,7 @@ enum URBNFRuleSetTag {
URBNF_SPELLOUT,
URBNF_ORDINAL,
URBNF_DURATION,
URBNF_NUMBERING_SYSTEM,
URBNF_COUNT
};
@ -596,10 +597,12 @@ public:
* code choosed among three possible predefined formats: spellout, ordinal,
* and duration.
* @param tag A selector code specifying which kind of formatter to create for that
* locale. There are three legal values: URBNF_SPELLOUT, which creates a formatter that
* locale. There are four legal values: URBNF_SPELLOUT, which creates a formatter that
* spells out a value in words in the desired language, URBNF_ORDINAL, which attaches
* an ordinal suffix from the desired language to the end of a number (e.g. "123rd"),
* and URBNF_DURATION, which formats a duration in seconds as hours, minutes, and seconds.
* URBNF_DURATION, which formats a duration in seconds as hours, minutes, and seconds,
* and URBNF_NUMBERING_SYSTEM, which is used to invoke rules for alternate numbering
* systems such as the Hebrew numbering system, or for Roman Numerals, etc.
* @param locale The locale for the formatter.
* @param status The status indicating whether the constructor succeeded.
* @stable ICU 2.0

View File

@ -1,6 +1,6 @@
/*
*******************************************************************************
* Copyright (C) 1997-2008, International Business Machines Corporation and others.
* Copyright (C) 1997-2009, International Business Machines Corporation and others.
* All Rights Reserved.
* Modification History:
*
@ -157,6 +157,11 @@ typedef enum UNumberFormatStyle {
* @stable ICU 3.0
*/
UNUM_DURATION,
/**
* Numbering system rule-based format
* @draft ICU 4.2
*/
UNUM_NUMBERING_SYSTEM,
/**
* Rule-based format defined by pattern
* @stable ICU 3.0

View File

@ -1,6 +1,6 @@
/*
*******************************************************************************
* Copyright (C) 1996-2008, International Business Machines
* Copyright (C) 1996-2009, International Business Machines
* Corporation and others. All Rights Reserved.
*******************************************************************************
* Modification History:
@ -130,6 +130,10 @@ unum_open( UNumberFormatStyle style,
case UNUM_DURATION:
retVal = (UNumberFormat*)new RuleBasedNumberFormat(URBNF_DURATION, Locale(locale), *status);
break;
case UNUM_NUMBERING_SYSTEM:
retVal = (UNumberFormat*)new RuleBasedNumberFormat(URBNF_NUMBERING_SYSTEM, Locale(locale), *status);
break;
#endif
default:

View File

@ -1,6 +1,6 @@
/********************************************************************
* COPYRIGHT:
* Copyright (c) 1997-2008, International Business Machines Corporation and
* Copyright (c) 1997-2009, International Business Machines Corporation and
* others. All Rights Reserved.
********************************************************************/
/* Modification History:
@ -86,6 +86,8 @@ void NumberFormatTest::runIndexedTest( int32_t index, UBool exec, const char* &n
CASE(34,TestCurrencyFormat);
CASE(35,TestRounding);
CASE(36,TestNonpositiveMultiplier);
CASE(37,TestNumberingSystems);
default: name = ""; break;
}
}
@ -2475,5 +2477,44 @@ void NumberFormatTest::TestNonpositiveMultiplier() {
}
/**
* Test using various numbering systems and numbering system keyword.
*/
void NumberFormatTest::TestNumberingSystems() {
UErrorCode ec = U_ZERO_ERROR;
Locale loc1("en", "US", "", "numbers=thai");
Locale loc2("en", "US", "", "numbers=hebrew");
Locale loc3("en", "US", "", "numbers=persian");
Locale loc4("en", "US", "", "numbers=foobar");
NumberFormat* fmt1= NumberFormat::createInstance(loc1, ec);
if (U_FAILURE(ec)) {
errln("FAIL: getInstance(en_US@numbers=thai)");
}
NumberFormat* fmt2= NumberFormat::createInstance(loc2, ec);
if (U_FAILURE(ec)) {
errln("FAIL: getInstance(en_US@numbers=hebrew)");
}
NumberFormat* fmt3= NumberFormat::createInstance(loc3, ec);
if (U_FAILURE(ec)) {
errln("FAIL: getInstance(en_US@numbers=persian)");
}
expect2(*fmt1, 1234.567, CharsToUnicodeString("\\u0E51,\\u0E52\\u0E53\\u0E54.\\u0E55\\u0E56\\u0E57"));
expect2(*fmt2, 5678.0, CharsToUnicodeString("\\u05D4\\u05F3\\u05EA\\u05E8\\u05E2\\u05F4\\u05D7"));
expect2(*fmt3, 1234.567, CharsToUnicodeString("\\u06F1,\\u06F2\\u06F3\\u06F4.\\u06F5\\u06F6\\u06F7"));
// Test bogus keyword value
NumberFormat* fmt4= NumberFormat::createInstance(loc4, ec);
if ( ec != U_UNSUPPORTED_ERROR ) {
errln("FAIL: getInstance(en_US@numbers=foobar) should have returned U_UNSUPPORTED_ERROR");
}
delete fmt1;
delete fmt2;
delete fmt3;
}
#endif /* #if !UCONFIG_NO_FORMATTING */

View File

@ -1,6 +1,6 @@
/********************************************************************
* COPYRIGHT:
* Copyright (c) 1997-2008, International Business Machines Corporation and
* Copyright (c) 1997-2009, International Business Machines Corporation and
* others. All Rights Reserved.
********************************************************************/
@ -131,6 +131,9 @@ class NumberFormatTest: public CalendarTimeZoneTest {
void TestRounding(void);
void TestNonpositiveMultiplier(void);
void TestNumberingSystems();
private:
static UBool equalValue(const Formattable& a, const Formattable& b);

View File

@ -1,6 +1,6 @@
// ***************************************************************************
// *
// * Copyright (C) 2004-2008 International Business Machines
// * Copyright (C) 2004-2009 International Business Machines
// * Corporation and others. All Rights Reserved.
// *
// ***************************************************************************
@ -3586,6 +3586,7 @@ structLocale:table(nofallback){
script{""}
territory{""}
}
defaultNumberingSystem{""}
delimiters{
quotationStart{""}
quotationEnd{""}
@ -6515,10 +6516,69 @@ structLocale:table(nofallback){
other{""}
}
}
unitsShort{
day{
zero{""}
one{""}
two{""}
few{""}
many{""}
other{""}
}
hour{
zero{""}
one{""}
two{""}
few{""}
many{""}
other{""}
}
minute{
zero{""}
one{""}
two{""}
few{""}
many{""}
other{""}
}
month{
zero{""}
one{""}
two{""}
few{""}
many{""}
other{""}
}
second{
zero{""}
one{""}
two{""}
few{""}
many{""}
other{""}
}
week{
zero{""}
one{""}
two{""}
few{""}
many{""}
other{""}
}
year{
zero{""}
one{""}
two{""}
few{""}
many{""}
other{""}
}
}
zoneStrings{
hoursFormat{""}
hourFormat{""}
gmtFormat{""}
gmtZeroFormat{""}
regionFormat{""}
fallbackFormat{""}
abbreviationFallback{""}