ICU-8656 Implement NumberingSystem::getAvailableNames()
X-SVN-Rev: 30476
This commit is contained in:
parent
021caab7ea
commit
c651458559
1
.gitattributes
vendored
1
.gitattributes
vendored
@ -88,6 +88,7 @@ icu4c/source/extra/uconv/uconv.vcxproj -text
|
||||
icu4c/source/extra/uconv/uconv.vcxproj.filters -text
|
||||
icu4c/source/i18n/i18n.vcxproj -text
|
||||
icu4c/source/i18n/i18n.vcxproj.filters -text
|
||||
icu4c/source/i18n/numsys_impl.h -text
|
||||
icu4c/source/io/io.vcxproj -text
|
||||
icu4c/source/io/io.vcxproj.filters -text
|
||||
icu4c/source/layout/layout.vcxproj -text
|
||||
|
@ -577,6 +577,7 @@
|
||||
</Command>
|
||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">..\..\include\unicode\%(Filename)%(Extension);%(Outputs)</Outputs>
|
||||
</CustomBuild>
|
||||
<ClInclude Include="numsys_impl.h" />
|
||||
<ClInclude Include="tzfmt.h" />
|
||||
<ClInclude Include="tzgnames.h" />
|
||||
<ClInclude Include="tznames.h" />
|
||||
|
@ -30,9 +30,6 @@
|
||||
<ClCompile Include="bmsearch.cpp">
|
||||
<Filter>collation</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="bocsu.c">
|
||||
<Filter>collation</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="coleitr.cpp">
|
||||
<Filter>collation</Filter>
|
||||
</ClCompile>
|
||||
@ -492,6 +489,7 @@
|
||||
<ClCompile Include="tznames_impl.cpp">
|
||||
<Filter>formatting</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="bocsu.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="bocsu.h">
|
||||
@ -779,6 +777,9 @@
|
||||
<ClInclude Include="tznames_impl.h">
|
||||
<Filter>formatting</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="numsys_impl.h">
|
||||
<Filter>formatting</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="i18n.rc">
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include "unicode/numsys.h"
|
||||
#include "cstring.h"
|
||||
#include "uresimp.h"
|
||||
#include "numsys_impl.h"
|
||||
|
||||
#if !UCONFIG_NO_FORMATTING
|
||||
|
||||
@ -42,6 +43,7 @@ static const char gLatn[] = "latn";
|
||||
|
||||
|
||||
UOBJECT_DEFINE_RTTI_IMPLEMENTATION(NumberingSystem)
|
||||
UOBJECT_DEFINE_RTTI_IMPLEMENTATION(NumsysNameEnumeration)
|
||||
|
||||
/**
|
||||
* Default Constructor.
|
||||
@ -217,6 +219,44 @@ UBool NumberingSystem::isAlgorithmic() const {
|
||||
return ( algorithmic );
|
||||
}
|
||||
|
||||
StringEnumeration* NumberingSystem::getAvailableNames(UErrorCode &status) {
|
||||
|
||||
static StringEnumeration* availableNames = NULL;
|
||||
|
||||
if (U_FAILURE(status)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if ( availableNames == NULL ) {
|
||||
UVector *fNumsysNames = new UVector(status);
|
||||
if (U_FAILURE(status)) {
|
||||
status = U_MEMORY_ALLOCATION_ERROR;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
UErrorCode rbstatus = U_ZERO_ERROR;
|
||||
UResourceBundle *numberingSystemsInfo = ures_openDirect(NULL, "numberingSystems", &rbstatus);
|
||||
numberingSystemsInfo = ures_getByKey(numberingSystemsInfo,"numberingSystems",numberingSystemsInfo,&rbstatus);
|
||||
if(U_FAILURE(rbstatus)) {
|
||||
status = U_MISSING_RESOURCE_ERROR;
|
||||
ures_close(numberingSystemsInfo);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
while ( ures_hasNext(numberingSystemsInfo) ) {
|
||||
UResourceBundle *nsCurrent = ures_getNextResource(numberingSystemsInfo,NULL,&rbstatus);
|
||||
const char *nsName = ures_getKey(nsCurrent);
|
||||
fNumsysNames->addElement(new UnicodeString(nsName),status);
|
||||
ures_close(nsCurrent);
|
||||
}
|
||||
|
||||
ures_close(numberingSystemsInfo);
|
||||
availableNames = new NumsysNameEnumeration(fNumsysNames,status);
|
||||
|
||||
}
|
||||
|
||||
return availableNames;
|
||||
}
|
||||
|
||||
UBool NumberingSystem::isValidDigitString(const UnicodeString& str) {
|
||||
|
||||
@ -235,6 +275,33 @@ UBool NumberingSystem::isValidDigitString(const UnicodeString& str) {
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
NumsysNameEnumeration::NumsysNameEnumeration(UVector *fNameList, UErrorCode& /*status*/) {
|
||||
pos=0;
|
||||
fNumsysNames = fNameList;
|
||||
}
|
||||
|
||||
const UnicodeString*
|
||||
NumsysNameEnumeration::snext(UErrorCode& status) {
|
||||
if (U_SUCCESS(status) && pos < fNumsysNames->size()) {
|
||||
return (const UnicodeString*)fNumsysNames->elementAt(pos++);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void
|
||||
NumsysNameEnumeration::reset(UErrorCode& /*status*/) {
|
||||
pos=0;
|
||||
}
|
||||
|
||||
int32_t
|
||||
NumsysNameEnumeration::count(UErrorCode& /*status*/) const {
|
||||
return (fNumsysNames==NULL) ? 0 : fNumsysNames->size();
|
||||
}
|
||||
|
||||
NumsysNameEnumeration::~NumsysNameEnumeration() {
|
||||
delete fNumsysNames;
|
||||
}
|
||||
U_NAMESPACE_END
|
||||
|
||||
#endif /* #if !UCONFIG_NO_FORMATTING */
|
||||
|
43
icu4c/source/i18n/numsys_impl.h
Normal file
43
icu4c/source/i18n/numsys_impl.h
Normal file
@ -0,0 +1,43 @@
|
||||
/*
|
||||
*******************************************************************************
|
||||
* Copyright (C) 2011, International Business Machines Corporation and
|
||||
* others. All Rights Reserved. *
|
||||
*******************************************************************************
|
||||
*
|
||||
* File NUMSYS_IMPL.H
|
||||
*
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef __NUMSYS_IMPL_H__
|
||||
#define __NUMSYS_IMPL_H__
|
||||
|
||||
#include "unicode/utypes.h"
|
||||
|
||||
#if !UCONFIG_NO_FORMATTING
|
||||
|
||||
#include "unicode/numsys.h"
|
||||
#include "uvector.h"
|
||||
#include "unicode/strenum.h"
|
||||
|
||||
U_NAMESPACE_BEGIN
|
||||
|
||||
class NumsysNameEnumeration : public StringEnumeration {
|
||||
public:
|
||||
NumsysNameEnumeration(UVector *fNumsysNames, UErrorCode& status);
|
||||
virtual ~NumsysNameEnumeration();
|
||||
static UClassID U_EXPORT2 getStaticClassID(void);
|
||||
virtual UClassID getDynamicClassID(void) const;
|
||||
virtual const UnicodeString* snext(UErrorCode& status);
|
||||
virtual void reset(UErrorCode& status);
|
||||
virtual int32_t count(UErrorCode& status) const;
|
||||
private:
|
||||
int32_t pos;
|
||||
UVector *fNumsysNames;
|
||||
};
|
||||
|
||||
U_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
@ -115,6 +115,7 @@ void NumberFormatTest::runIndexedTest( int32_t index, UBool exec, const char* &n
|
||||
CASE(49,TestExponentParse);
|
||||
CASE(50,TestExplicitParents);
|
||||
CASE(51,TestLenientParse);
|
||||
CASE(52,TestAvailableNumberingSystems);
|
||||
default: name = ""; break;
|
||||
}
|
||||
}
|
||||
@ -6449,4 +6450,31 @@ void NumberFormatTest::TestExplicitParents() {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test available numbering systems API.
|
||||
*/
|
||||
void NumberFormatTest::TestAvailableNumberingSystems() {
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
StringEnumeration *availableNumberingSystems = NumberingSystem::getAvailableNames(status);
|
||||
|
||||
int32_t nsCount = availableNumberingSystems->count(status);
|
||||
if ( nsCount < 36 ) {
|
||||
errln("FAIL: Didn't get as many numbering systems as we had hoped for. Need at least 36, got %d",nsCount);
|
||||
}
|
||||
|
||||
/* A relatively simple test of the API. We call getAvailableNames() and cycle through */
|
||||
/* each name returned, attempting to create a numbering system based on that name and */
|
||||
/* verifying that the name returned from the resulting numbering system is the same */
|
||||
/* one that we initially thought. */
|
||||
|
||||
int32_t len;
|
||||
for ( int32_t i = 0 ; i < nsCount ; i++ ) {
|
||||
const char *nsname = availableNumberingSystems->next(&len,status);
|
||||
NumberingSystem* ns = NumberingSystem::createInstanceByName(nsname,status);
|
||||
if ( uprv_strcmp(nsname,ns->getName()) ) {
|
||||
errln("FAIL: Numbering system name didn't match for name = %s\n",nsname);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif /* #if !UCONFIG_NO_FORMATTING */
|
||||
|
@ -152,6 +152,8 @@ class NumberFormatTest: public CalendarTimeZoneTest {
|
||||
|
||||
void TestExponentParse();
|
||||
void TestExplicitParents();
|
||||
void TestAvailableNumberingSystems();
|
||||
|
||||
|
||||
private:
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user