ICU-10070 Add plain C wrappers for Region class
X-SVN-Rev: 33520
This commit is contained in:
parent
a1d5c9a04e
commit
947bd7d1b6
3
.gitattributes
vendored
3
.gitattributes
vendored
@ -74,6 +74,8 @@ 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/unicode/uregion.h -text
|
||||
icu4c/source/i18n/uregion.cpp -text
|
||||
icu4c/source/io/io.vcxproj -text
|
||||
icu4c/source/io/io.vcxproj.filters -text
|
||||
icu4c/source/layout/layout.vcxproj -text
|
||||
@ -133,6 +135,7 @@ icu4c/source/stubdata/stubdata.vcxproj -text
|
||||
icu4c/source/stubdata/stubdata.vcxproj.filters -text
|
||||
icu4c/source/test/cintltst/cintltst.vcxproj -text
|
||||
icu4c/source/test/cintltst/cintltst.vcxproj.filters -text
|
||||
icu4c/source/test/cintltst/uregiontest.c -text
|
||||
icu4c/source/test/intltest/intltest.vcxproj -text
|
||||
icu4c/source/test/intltest/intltest.vcxproj.filters -text
|
||||
icu4c/source/test/iotest/iotest.vcxproj -text
|
||||
|
@ -86,7 +86,7 @@ tmunit.o tmutamt.o tmutfmt.o currpinf.o \
|
||||
uspoof.o uspoof_impl.o uspoof_build.o uspoof_conf.o uspoof_wsconf.o decfmtst.o smpdtfst.o \
|
||||
ztrans.o zrule.o vzone.o fphdlimp.o fpositer.o locdspnm.o \
|
||||
decNumber.o decContext.o alphaindex.o tznames.o tznames_impl.o tzgnames.o \
|
||||
tzfmt.o compactdecimalformat.o gender.o region.o scriptset.o identifier_info.o
|
||||
tzfmt.o compactdecimalformat.o gender.o region.o uregion.o scriptset.o identifier_info.o
|
||||
|
||||
## Header files to install
|
||||
HEADERS = $(srcdir)/unicode/*.h
|
||||
|
@ -249,6 +249,7 @@
|
||||
<ClCompile Include="coleitr.cpp" />
|
||||
<ClCompile Include="coll.cpp" />
|
||||
<ClCompile Include="region.cpp" />
|
||||
<ClCompile Include="uregion.cpp" />
|
||||
<ClCompile Include="search.cpp" />
|
||||
<ClCompile Include="sortkey.cpp" />
|
||||
<ClCompile Include="stsearch.cpp" />
|
||||
@ -599,7 +600,34 @@
|
||||
<Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">copy "%(FullPath)" ..\..\include\unicode</Command>
|
||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">..\..\include\unicode\%(Filename)%(Extension);%(Outputs)</Outputs>
|
||||
</CustomBuild>
|
||||
<ClInclude Include="unicode\region.h" />
|
||||
<CustomBuild Include="unicode\region.h">
|
||||
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">copy "%(FullPath)" ..\..\include\unicode
|
||||
</Command>
|
||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">..\..\include\unicode\%(Filename)%(Extension);%(Outputs)</Outputs>
|
||||
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">copy "%(FullPath)" ..\..\include\unicode
|
||||
</Command>
|
||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">..\..\include\unicode\%(Filename)%(Extension);%(Outputs)</Outputs>
|
||||
<Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">copy "%(FullPath)" ..\..\include\unicode
|
||||
</Command>
|
||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">..\..\include\unicode\%(Filename)%(Extension);%(Outputs)</Outputs>
|
||||
<Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">copy "%(FullPath)" ..\..\include\unicode
|
||||
</Command>
|
||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">..\..\include\unicode\%(Filename)%(Extension);%(Outputs)</Outputs>
|
||||
</CustomBuild>
|
||||
<CustomBuild Include="unicode\uregion.h">
|
||||
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">copy "%(FullPath)" ..\..\include\unicode
|
||||
</Command>
|
||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">..\..\include\unicode\%(Filename)%(Extension);%(Outputs)</Outputs>
|
||||
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">copy "%(FullPath)" ..\..\include\unicode
|
||||
</Command>
|
||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">..\..\include\unicode\%(Filename)%(Extension);%(Outputs)</Outputs>
|
||||
<Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">copy "%(FullPath)" ..\..\include\unicode
|
||||
</Command>
|
||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">..\..\include\unicode\%(Filename)%(Extension);%(Outputs)</Outputs>
|
||||
<Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">copy "%(FullPath)" ..\..\include\unicode
|
||||
</Command>
|
||||
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">..\..\include\unicode\%(Filename)%(Extension);%(Outputs)</Outputs>
|
||||
</CustomBuild>
|
||||
<ClInclude Include="usrchimp.h" />
|
||||
<ClInclude Include="astro.h" />
|
||||
<CustomBuild Include="unicode\basictz.h">
|
||||
|
@ -502,6 +502,9 @@
|
||||
<ClCompile Include="region.cpp">
|
||||
<Filter>formatting</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="uregion.cpp">
|
||||
<Filter>formatting</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="bocsu.h">
|
||||
@ -807,6 +810,9 @@
|
||||
<ClInclude Include="unicode\region.h">
|
||||
<Filter>formatting</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="unicode\uregion.h">
|
||||
<Filter>formatting</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="i18n.rc">
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
*******************************************************************************
|
||||
* Copyright (C) 2013, International Business Machines Corporation
|
||||
* Copyright (C) 2013, International Business Machines Corporation and others.
|
||||
* All Rights Reserved.
|
||||
*******************************************************************************
|
||||
*/
|
||||
@ -14,71 +14,10 @@
|
||||
*/
|
||||
|
||||
#include "unicode/utypes.h"
|
||||
|
||||
#ifndef U_HIDE_DRAFT_API
|
||||
/**
|
||||
* URegionType is an enumeration defining the different types of regions. Current possible
|
||||
* values are URGN_WORLD, URGN_CONTINENT, URGN_SUBCONTINENT, URGN_TERRITORY, URGN_GROUPING,
|
||||
* URGN_DEPRECATED, and URGN_UNKNOWN.
|
||||
*
|
||||
* @draft ICU 51
|
||||
*/
|
||||
|
||||
typedef enum URegionType {
|
||||
/**
|
||||
* Type representing the unknown region.
|
||||
* @draft ICU 51
|
||||
*/
|
||||
URGN_UNKNOWN,
|
||||
|
||||
/**
|
||||
* Type representing a territory.
|
||||
* @draft ICU 51
|
||||
*/
|
||||
URGN_TERRITORY,
|
||||
|
||||
/**
|
||||
* Type representing the whole world.
|
||||
* @draft ICU 51
|
||||
*/
|
||||
URGN_WORLD,
|
||||
|
||||
/**
|
||||
* Type representing a continent.
|
||||
* @draft ICU 51
|
||||
*/
|
||||
URGN_CONTINENT,
|
||||
|
||||
/**
|
||||
* Type representing a sub-continent.
|
||||
* @draft ICU 51
|
||||
*/
|
||||
URGN_SUBCONTINENT,
|
||||
|
||||
/**
|
||||
* Type representing a grouping of territories that is not to be used in
|
||||
* the normal WORLD/CONTINENT/SUBCONTINENT/TERRITORY containment tree.
|
||||
* @draft ICU 51
|
||||
*/
|
||||
URGN_GROUPING,
|
||||
|
||||
/**
|
||||
* Type representing a region whose code has been deprecated, usually
|
||||
* due to a country splitting into multiple territories or changing its name.
|
||||
* @draft ICU 51
|
||||
*/
|
||||
URGN_DEPRECATED,
|
||||
|
||||
/**
|
||||
* Maximum value for this unumeration.
|
||||
* @draft ICU 51
|
||||
*/
|
||||
URGN_LIMIT
|
||||
} URegionType;
|
||||
|
||||
|
||||
#include "unicode/uregion.h"
|
||||
|
||||
#if !UCONFIG_NO_FORMATTING
|
||||
#ifndef U_HIDE_DRAFT_API
|
||||
|
||||
#include "unicode/uobject.h"
|
||||
#include "unicode/uniset.h"
|
||||
@ -282,8 +221,8 @@ private:
|
||||
|
||||
U_NAMESPACE_END
|
||||
|
||||
#endif /* #if !UCONFIG_NO_FORMATTING */
|
||||
#endif /* U_HIDE_DRAFT_API */
|
||||
#endif /* #if !UCONFIG_NO_FORMATTING */
|
||||
#endif // REGION_H
|
||||
|
||||
//eof
|
||||
|
253
icu4c/source/i18n/unicode/uregion.h
Normal file
253
icu4c/source/i18n/unicode/uregion.h
Normal file
@ -0,0 +1,253 @@
|
||||
/*
|
||||
*****************************************************************************************
|
||||
* Copyright (C) 2013, International Business Machines
|
||||
* Corporation and others. All Rights Reserved.
|
||||
*****************************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef UREGION_H
|
||||
#define UREGION_H
|
||||
|
||||
#include "unicode/utypes.h"
|
||||
#include "unicode/uenum.h"
|
||||
|
||||
/**
|
||||
* \file
|
||||
* \brief C API: URegion (territory containment and mapping)
|
||||
*
|
||||
* URegion objects represent data associated with a particular Unicode Region Code, also known as a
|
||||
* Unicode Region Subtag, which is defined based upon the BCP 47 standard. These include:
|
||||
* * Two-letter codes defined by ISO 3166-1, with special LDML treatment of certain private-use or
|
||||
* reserved codes;
|
||||
* * A subset of 3-digit numeric codes defined by UN M.49.
|
||||
* URegion objects can also provide mappings to and from additional codes. There are different types
|
||||
* of regions that are important to distinguish:
|
||||
* <p>
|
||||
* Macroregion - A code for a "macro geographical (continental) region, geographical sub-region, or
|
||||
* selected economic and other grouping" as defined in UN M.49. These are typically 3-digit codes,
|
||||
* but contain some 2-letter codes for LDML extensions, such as "QO" for Outlying Oceania.
|
||||
* Macroregions are represented in ICU by one of three region types: WORLD (code 001),
|
||||
* CONTINENTS (regions contained directly by WORLD), and SUBCONTINENTS (regions contained directly
|
||||
* by a continent ).
|
||||
* <p>
|
||||
* TERRITORY - A Region that is not a Macroregion. These are typically codes for countries, but also
|
||||
* include areas that are not separate countries, such as the code "AQ" for Antarctica or the code
|
||||
* "HK" for Hong Kong (SAR China). Overseas dependencies of countries may or may not have separate
|
||||
* codes. The codes are typically 2-letter codes aligned with ISO 3166, but BCP47 allows for the use
|
||||
* of 3-digit codes in the future.
|
||||
* <p>
|
||||
* UNKNOWN - The code ZZ is defined by Unicode LDML for use in indicating that region is unknown,
|
||||
* or that the value supplied as a region was invalid.
|
||||
* <p>
|
||||
* DEPRECATED - Region codes that have been defined in the past but are no longer in modern usage,
|
||||
* usually due to a country splitting into multiple territories or changing its name.
|
||||
* <p>
|
||||
* GROUPING - A widely understood grouping of territories that has a well defined membership such
|
||||
* that a region code has been assigned for it. Some of these are UN M.49 codes that don't fall into
|
||||
* the world/continent/sub-continent hierarchy, while others are just well-known groupings that have
|
||||
* their own region code. Region "EU" (European Union) is one such region code that is a grouping.
|
||||
* Groupings will never be returned by the uregion_getContainingRegion, since a different type of region
|
||||
* (WORLD, CONTINENT, or SUBCONTINENT) will always be the containing region instead.
|
||||
*
|
||||
* URegion objects are const/immutable, owned and maintained by ICU itself, so there are not functions
|
||||
* to open or close them.
|
||||
*/
|
||||
|
||||
#ifndef U_HIDE_DRAFT_API
|
||||
/**
|
||||
* URegionType is an enumeration defining the different types of regions. Current possible
|
||||
* values are URGN_WORLD, URGN_CONTINENT, URGN_SUBCONTINENT, URGN_TERRITORY, URGN_GROUPING,
|
||||
* URGN_DEPRECATED, and URGN_UNKNOWN.
|
||||
*
|
||||
* @draft ICU 51
|
||||
*/
|
||||
typedef enum URegionType {
|
||||
/**
|
||||
* Type representing the unknown region.
|
||||
* @draft ICU 51
|
||||
*/
|
||||
URGN_UNKNOWN,
|
||||
|
||||
/**
|
||||
* Type representing a territory.
|
||||
* @draft ICU 51
|
||||
*/
|
||||
URGN_TERRITORY,
|
||||
|
||||
/**
|
||||
* Type representing the whole world.
|
||||
* @draft ICU 51
|
||||
*/
|
||||
URGN_WORLD,
|
||||
|
||||
/**
|
||||
* Type representing a continent.
|
||||
* @draft ICU 51
|
||||
*/
|
||||
URGN_CONTINENT,
|
||||
|
||||
/**
|
||||
* Type representing a sub-continent.
|
||||
* @draft ICU 51
|
||||
*/
|
||||
URGN_SUBCONTINENT,
|
||||
|
||||
/**
|
||||
* Type representing a grouping of territories that is not to be used in
|
||||
* the normal WORLD/CONTINENT/SUBCONTINENT/TERRITORY containment tree.
|
||||
* @draft ICU 51
|
||||
*/
|
||||
URGN_GROUPING,
|
||||
|
||||
/**
|
||||
* Type representing a region whose code has been deprecated, usually
|
||||
* due to a country splitting into multiple territories or changing its name.
|
||||
* @draft ICU 51
|
||||
*/
|
||||
URGN_DEPRECATED,
|
||||
|
||||
/**
|
||||
* Maximum value for this unumeration.
|
||||
* @draft ICU 51
|
||||
*/
|
||||
URGN_LIMIT
|
||||
} URegionType;
|
||||
#endif /* U_HIDE_DRAFT_API */
|
||||
|
||||
#if !UCONFIG_NO_FORMATTING
|
||||
|
||||
#ifndef U_HIDE_DRAFT_API
|
||||
|
||||
/**
|
||||
* Opaque URegion object for use in C programs.
|
||||
* @draft ICU 52
|
||||
*/
|
||||
struct URegion;
|
||||
typedef struct URegion URegion;
|
||||
|
||||
/**
|
||||
* Returns a pointer to a URegion for the specified region code: A 2-letter or 3-letter ISO 3166
|
||||
* code, UNM.49 numeric code (superset of ISO 3166 numeric codes), or other valid Unicode Region
|
||||
* Code as defined by the LDML specification. The code will be canonicalized internally. If the
|
||||
* region code is NULL or not recognized, the appropriate error code will be set
|
||||
* (U_ILLEGAL_ARGUMENT_ERROR).
|
||||
* @draft ICU 52
|
||||
*/
|
||||
U_DRAFT const URegion* U_EXPORT2
|
||||
uregion_getRegionFromCode(const char *regionCode, UErrorCode *status);
|
||||
|
||||
/**
|
||||
* Returns a pointer to a URegion for the specified numeric region code. If the numeric region
|
||||
* code is not recognized, the appropriate error code will be set (U_ILLEGAL_ARGUMENT_ERROR).
|
||||
* @draft ICU 52
|
||||
*/
|
||||
U_DRAFT const URegion* U_EXPORT2
|
||||
uregion_getRegionFromNumericCode (int32_t code, UErrorCode *status);
|
||||
|
||||
/**
|
||||
* Returns an enumeration over the canonical codes of all known regions that match the given type.
|
||||
* The enumeration must be closed with with uenum_close().
|
||||
* @draft ICU 52
|
||||
*/
|
||||
U_DRAFT UEnumeration* U_EXPORT2
|
||||
uregion_getAvailable(URegionType type, UErrorCode *status);
|
||||
|
||||
/**
|
||||
* Returns true if the specified uregion is equal to the specified otherRegion.
|
||||
* @draft ICU 52
|
||||
*/
|
||||
U_DRAFT UBool U_EXPORT2
|
||||
uregion_isEqualTo(const URegion* uregion, const URegion* otherRegion);
|
||||
|
||||
/**
|
||||
* Returns a pointer to the URegion that contains the specified uregion. Returns NULL if the
|
||||
* specified uregion is code "001" (World) or "ZZ" (Unknown region). For example, calling
|
||||
* this method with region "IT" (Italy) returns the URegion for "039" (Southern Europe).
|
||||
* @draft ICU 52
|
||||
*/
|
||||
U_DRAFT const URegion* U_EXPORT2
|
||||
uregion_getContainingRegion(const URegion* uregion);
|
||||
|
||||
/**
|
||||
* Return a pointer to the URegion that geographically contains this uregion and matches the
|
||||
* specified type, moving multiple steps up the containment chain if necessary. Returns NULL if no
|
||||
* containing region can be found that matches the specified type. Will return NULL if URegionType
|
||||
* is URGN_GROUPING, URGN_DEPRECATED, or URGN_UNKNOWN which are not appropriate for this API.
|
||||
* For example, calling this method with uregion "IT" (Italy) for type URGN_CONTINENT returns the
|
||||
* URegion "150" (Europe).
|
||||
* @draft ICU 52
|
||||
*/
|
||||
U_DRAFT const URegion* U_EXPORT2
|
||||
uregion_getContainingRegionOfType(const URegion* uregion, URegionType type);
|
||||
|
||||
/**
|
||||
* Return an enumeration over the canonical codes of all the regions that are immediate children
|
||||
* of the specified uregion in the region hierarchy. These returned regions could be either macro
|
||||
* regions, territories, or a mixture of the two, depending on the containment data as defined in
|
||||
* CLDR. This API returns NULL if this uregion doesn't have any sub-regions. For example, calling
|
||||
* this function for uregion "150" (Europe) returns an enumeration containing the various
|
||||
* sub-regions of Europe: "039" (Southern Europe), "151" (Eastern Europe), "154" (Northern Europe),
|
||||
* and "155" (Western Europe). The enumeration must be closed with with uenum_close().
|
||||
* @draft ICU 52
|
||||
*/
|
||||
U_DRAFT UEnumeration* U_EXPORT2
|
||||
uregion_getContainedRegions(const URegion* uregion, UErrorCode *status);
|
||||
|
||||
/**
|
||||
* Returns an enumeration over the canonical codes of all the regions that are children of the
|
||||
* specified uregion anywhere in the region hierarchy and match the given type. This API may return
|
||||
* an empty enumeration if this uregion doesn't have any sub-regions that match the given type.
|
||||
* For example, calling this method with region "150" (Europe) and type URGN_TERRITORY" returns an
|
||||
* enumeration containing all the territories in Europe: "FR" (France), "IT" (Italy), "DE" (Germany),
|
||||
* etc. The enumeration must be closed with with uenum_close().
|
||||
* @draft ICU 52
|
||||
*/
|
||||
U_DRAFT UEnumeration* U_EXPORT2
|
||||
uregion_getContainedRegionsOfType(const URegion* uregion, URegionType type, UErrorCode *status);
|
||||
|
||||
/**
|
||||
* Returns true if the specified uregion contains the specified otherRegion anywhere in the region
|
||||
* hierarchy.
|
||||
* @draft ICU 52
|
||||
*/
|
||||
U_DRAFT UBool U_EXPORT2
|
||||
uregion_contains(const URegion* uregion, const URegion* otherRegion);
|
||||
|
||||
/**
|
||||
* If the specified uregion is deprecated, returns an enumeration over the canonical codes of the
|
||||
* regions that are the preferred replacement regions for the specified uregion. If the specified
|
||||
* uregion is not deprecated, returns NULL. For example, calling this method with uregion
|
||||
* "SU" (Soviet Union) returns a list of the regions containing "RU" (Russia), "AM" (Armenia),
|
||||
* "AZ" (Azerbaijan), etc... The enumeration must be closed with with uenum_close().
|
||||
* @draft ICU 52
|
||||
*/
|
||||
U_DRAFT UEnumeration* U_EXPORT2
|
||||
uregion_getPreferredValues(const URegion* uregion, UErrorCode *status);
|
||||
|
||||
/**
|
||||
* Returns the specified uregion's canonical code.
|
||||
* @draft ICU 52
|
||||
*/
|
||||
U_DRAFT const char* U_EXPORT2
|
||||
uregion_getRegionCode(const URegion* uregion);
|
||||
|
||||
/**
|
||||
* Returns the specified uregion's numeric code, or a negative value if there is no numeric code
|
||||
* for the specified uregion.
|
||||
* @draft ICU 52
|
||||
*/
|
||||
U_DRAFT int32_t U_EXPORT2
|
||||
uregion_getNumericCode(const URegion* uregion);
|
||||
|
||||
/**
|
||||
* Returns the URegionType of the specified uregion.
|
||||
* @draft ICU 52
|
||||
*/
|
||||
U_DRAFT URegionType U_EXPORT2
|
||||
uregion_getType(const URegion* uregion);
|
||||
|
||||
#endif /* U_HIDE_DRAFT_API */
|
||||
|
||||
#endif /* #if !UCONFIG_NO_FORMATTING */
|
||||
|
||||
#endif
|
110
icu4c/source/i18n/uregion.cpp
Normal file
110
icu4c/source/i18n/uregion.cpp
Normal file
@ -0,0 +1,110 @@
|
||||
/*
|
||||
*****************************************************************************************
|
||||
* Copyright (C) 2013, International Business Machines Corporation and others.
|
||||
* All Rights Reserved.
|
||||
*****************************************************************************************
|
||||
*/
|
||||
|
||||
#include "unicode/utypes.h"
|
||||
|
||||
#if !UCONFIG_NO_FORMATTING
|
||||
|
||||
#include "unicode/uregion.h"
|
||||
#include "unicode/region.h"
|
||||
#include "unicode/uenum.h"
|
||||
|
||||
U_NAMESPACE_USE
|
||||
|
||||
|
||||
U_CAPI const URegion* U_EXPORT2
|
||||
uregion_getRegionFromCode(const char *regionCode, UErrorCode *status)
|
||||
{
|
||||
return (URegion*)Region::getInstance(regionCode, *status);
|
||||
}
|
||||
|
||||
|
||||
U_CAPI const URegion* U_EXPORT2
|
||||
uregion_getRegionFromNumericCode (int32_t code, UErrorCode *status)
|
||||
{
|
||||
return (URegion*)Region::getInstance(code, *status);
|
||||
}
|
||||
|
||||
|
||||
U_CAPI UEnumeration* U_EXPORT2
|
||||
uregion_getAvailable(URegionType type, UErrorCode *status)
|
||||
{
|
||||
return uenum_openFromStringEnumeration( Region::getAvailable(type), status );
|
||||
}
|
||||
|
||||
|
||||
U_CAPI UBool U_EXPORT2
|
||||
uregion_isEqualTo(const URegion* uregion, const URegion* otherRegion)
|
||||
{
|
||||
return ( (Region*)uregion == (Region*)otherRegion );
|
||||
}
|
||||
|
||||
|
||||
U_CAPI const URegion* U_EXPORT2
|
||||
uregion_getContainingRegion(const URegion* uregion)
|
||||
{
|
||||
return (URegion*)((Region*)uregion)->getContainingRegion();
|
||||
}
|
||||
|
||||
|
||||
U_CAPI const URegion* U_EXPORT2
|
||||
uregion_getContainingRegionOfType(const URegion* uregion, URegionType type)
|
||||
{
|
||||
return (URegion*)((Region*)uregion)->getContainingRegion(type);
|
||||
}
|
||||
|
||||
|
||||
U_CAPI UEnumeration* U_EXPORT2
|
||||
uregion_getContainedRegions(const URegion* uregion, UErrorCode *status)
|
||||
{
|
||||
return uenum_openFromStringEnumeration( ((Region*)uregion)->getContainedRegions(), status);
|
||||
}
|
||||
|
||||
|
||||
U_CAPI UEnumeration* U_EXPORT2
|
||||
uregion_getContainedRegionsOfType(const URegion* uregion, URegionType type, UErrorCode *status)
|
||||
{
|
||||
return uenum_openFromStringEnumeration( ((Region*)uregion)->getContainedRegions(type), status);
|
||||
}
|
||||
|
||||
|
||||
U_CAPI UBool U_EXPORT2
|
||||
uregion_contains(const URegion* uregion, const URegion* otherRegion)
|
||||
{
|
||||
return ((Region*)uregion)->contains(*((Region*)otherRegion));
|
||||
}
|
||||
|
||||
|
||||
U_CAPI UEnumeration* U_EXPORT2
|
||||
uregion_getPreferredValues(const URegion* uregion, UErrorCode *status)
|
||||
{
|
||||
return uenum_openFromStringEnumeration( ((Region*)uregion)->getPreferredValues(), status);
|
||||
}
|
||||
|
||||
|
||||
U_CAPI const char* U_EXPORT2
|
||||
uregion_getRegionCode(const URegion* uregion)
|
||||
{
|
||||
return ((Region*)uregion)->getRegionCode();
|
||||
}
|
||||
|
||||
|
||||
U_CAPI int32_t U_EXPORT2
|
||||
uregion_getNumericCode(const URegion* uregion)
|
||||
{
|
||||
return ((Region*)uregion)->getNumericCode();
|
||||
}
|
||||
|
||||
|
||||
U_CAPI URegionType U_EXPORT2
|
||||
uregion_getType(const URegion* uregion)
|
||||
{
|
||||
return ((Region*)uregion)->getType();
|
||||
}
|
||||
|
||||
|
||||
#endif /* #if !UCONFIG_NO_FORMATTING */
|
@ -1,6 +1,6 @@
|
||||
#******************************************************************************
|
||||
#
|
||||
# Copyright (C) 1999-2012, International Business Machines
|
||||
# Copyright (C) 1999-2013, International Business Machines
|
||||
# Corporation and others. All Rights Reserved.
|
||||
#
|
||||
#******************************************************************************
|
||||
@ -49,7 +49,7 @@ ncnvfbts.o ncnvtst.o putiltst.o cstrtest.o udatpg_test.o utf8tst.o \
|
||||
stdnmtst.o usrchtst.o custrtrn.o sorttest.o trietest.o trie2test.o usettest.o \
|
||||
uenumtst.o utmstest.o currtest.o \
|
||||
idnatest.o nfsprep.o spreptst.o sprpdata.o \
|
||||
hpmufn.o tracetst.o reapits.o utexttst.o ucsdetst.o spooftest.o \
|
||||
hpmufn.o tracetst.o reapits.o uregiontest.o utexttst.o ucsdetst.o spooftest.o \
|
||||
cgendtst.o
|
||||
|
||||
DEPS = $(OBJECTS:.o=.d)
|
||||
|
@ -1,6 +1,6 @@
|
||||
/********************************************************************
|
||||
* COPYRIGHT:
|
||||
* Copyright (c) 1997-2007,2011, International Business Machines
|
||||
* Copyright (c) 1997-2007,2011,2013, International Business Machines
|
||||
* Corporation and others. All Rights Reserved.
|
||||
********************************************************************/
|
||||
/********************************************************************************
|
||||
@ -34,6 +34,7 @@ void addDtFrDepTest(TestNode**);
|
||||
void addUtmsTest(TestNode**);
|
||||
void addCurrencyTest(TestNode**);
|
||||
void addPluralRulesTest(TestNode**);
|
||||
void addURegionTest(TestNode** root);
|
||||
|
||||
void addFormatTest(TestNode** root);
|
||||
|
||||
@ -51,6 +52,7 @@ void addFormatTest(TestNode** root)
|
||||
addUtmsTest(root);
|
||||
addCurrencyTest(root);
|
||||
addPluralRulesTest(root);
|
||||
addURegionTest(root);
|
||||
}
|
||||
/*Internal functions used*/
|
||||
|
||||
|
@ -318,6 +318,7 @@
|
||||
<ClCompile Include="spreptst.c" />
|
||||
<ClCompile Include="sprpdata.c" />
|
||||
<ClCompile Include="spooftest.c" />
|
||||
<ClCompile Include="uregiontest.c" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="cbiditst.h" />
|
||||
|
@ -210,6 +210,9 @@
|
||||
<ClCompile Include="utmstest.c">
|
||||
<Filter>formatting</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="uregiontest.c">
|
||||
<Filter>formatting</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="cldrtest.c">
|
||||
<Filter>locales & resources</Filter>
|
||||
</ClCompile>
|
||||
|
486
icu4c/source/test/cintltst/uregiontest.c
Normal file
486
icu4c/source/test/cintltst/uregiontest.c
Normal file
@ -0,0 +1,486 @@
|
||||
/********************************************************************
|
||||
* Copyright (c) 2013, International Business Machines Corporation
|
||||
* and others. All Rights Reserved.
|
||||
********************************************************************/
|
||||
/* C API TEST FOR UREGION */
|
||||
/***********************************************************************
|
||||
* Test cases ported from ICU4J ( RegionTest.java )
|
||||
* to C++ (regiontst.cpp) to here.
|
||||
* Try to keep them in sync if at all possible...!
|
||||
***********************************************************************/
|
||||
|
||||
#include "unicode/utypes.h"
|
||||
|
||||
#if !UCONFIG_NO_FORMATTING
|
||||
|
||||
#include "unicode/ustring.h"
|
||||
#include "unicode/uregion.h"
|
||||
#include "unicode/uenum.h"
|
||||
#include "cintltst.h"
|
||||
#include "cmemory.h"
|
||||
|
||||
static void TestKnownRegions(void);
|
||||
static void TestGetContainedRegions(void);
|
||||
static void TestGetContainedRegionsWithType(void);
|
||||
static void TestGetContainingRegion(void);
|
||||
static void TestGetContainingRegionWithType(void);
|
||||
|
||||
void addURegionTest(TestNode** root);
|
||||
|
||||
#define TESTCASE(x) addTest(root, &x, "tsformat/uregiontest/" #x)
|
||||
|
||||
void addURegionTest(TestNode** root)
|
||||
{
|
||||
TESTCASE(TestKnownRegions);
|
||||
TESTCASE(TestGetContainedRegions);
|
||||
TESTCASE(TestGetContainedRegionsWithType);
|
||||
TESTCASE(TestGetContainingRegion);
|
||||
TESTCASE(TestGetContainingRegionWithType);
|
||||
}
|
||||
|
||||
typedef struct KnownRegion {
|
||||
const char *code;
|
||||
int32_t numeric;
|
||||
const char *parent;
|
||||
URegionType type;
|
||||
const char *containingContinent;
|
||||
} KnownRegion;
|
||||
|
||||
#define LENGTHOF(array) (int32_t)(sizeof(array) / sizeof((array)[0]))
|
||||
|
||||
static KnownRegion knownRegions[] = {
|
||||
// Code, Num, Parent, Type, Containing Continent
|
||||
{ "TP" , 626, "035", URGN_TERRITORY, "142" },
|
||||
{ "001", 1, NULL , URGN_WORLD, NULL },
|
||||
{ "002", 2, "001", URGN_CONTINENT, NULL },
|
||||
{ "003", 3, NULL, URGN_GROUPING, NULL },
|
||||
{ "005", 5, "019", URGN_SUBCONTINENT, "019" },
|
||||
{ "009", 9, "001", URGN_CONTINENT, NULL},
|
||||
{ "011", 11, "002", URGN_SUBCONTINENT, "002" },
|
||||
{ "013", 13, "019", URGN_SUBCONTINENT, "019" },
|
||||
{ "014", 14, "002", URGN_SUBCONTINENT, "002" },
|
||||
{ "015", 15, "002", URGN_SUBCONTINENT, "002" },
|
||||
{ "017", 17, "002", URGN_SUBCONTINENT, "002" },
|
||||
{ "018", 18, "002", URGN_SUBCONTINENT, "002" },
|
||||
{ "019", 19, "001", URGN_CONTINENT, NULL },
|
||||
{ "021", 21, "019", URGN_SUBCONTINENT, "019" },
|
||||
{ "029", 29, "019", URGN_SUBCONTINENT, "019" },
|
||||
{ "030", 30, "142", URGN_SUBCONTINENT, "142" },
|
||||
{ "034", 34, "142", URGN_SUBCONTINENT, "142" },
|
||||
{ "035", 35, "142", URGN_SUBCONTINENT, "142" },
|
||||
{ "039", 39, "150", URGN_SUBCONTINENT, "150"},
|
||||
{ "053", 53, "009", URGN_SUBCONTINENT, "009" },
|
||||
{ "054", 54, "009", URGN_SUBCONTINENT, "009" },
|
||||
{ "057", 57, "009", URGN_SUBCONTINENT, "009" },
|
||||
{ "061", 61, "009", URGN_SUBCONTINENT, "009" },
|
||||
{ "142", 142, "001", URGN_CONTINENT, NULL },
|
||||
{ "143", 143, "142", URGN_SUBCONTINENT, "142" },
|
||||
{ "145", 145, "142", URGN_SUBCONTINENT, "142" },
|
||||
{ "150", 150, "001", URGN_CONTINENT, NULL },
|
||||
{ "151", 151, "150", URGN_SUBCONTINENT, "150" },
|
||||
{ "154", 154, "150", URGN_SUBCONTINENT, "150" },
|
||||
{ "155", 155, "150", URGN_SUBCONTINENT, "150" },
|
||||
{ "419", 419, NULL, URGN_GROUPING , NULL},
|
||||
{ "AC" , -1, "QO" , URGN_TERRITORY, "009" },
|
||||
{ "AD" , 20, "039", URGN_TERRITORY, "150" },
|
||||
{ "AE" , 784, "145", URGN_TERRITORY, "142" },
|
||||
{ "AF" , 4, "034", URGN_TERRITORY, "142" },
|
||||
{ "AG" , 28, "029", URGN_TERRITORY, "019" },
|
||||
{ "AI" , 660, "029", URGN_TERRITORY, "019" },
|
||||
{ "AL" , 8, "039", URGN_TERRITORY, "150" },
|
||||
{ "AM" , 51, "145", URGN_TERRITORY, "142" },
|
||||
{ "AN" , 530, NULL, URGN_DEPRECATED, NULL },
|
||||
{ "AO" , 24, "017", URGN_TERRITORY, "002" },
|
||||
{ "AQ" , 10, "QO" , URGN_TERRITORY, "009" },
|
||||
{ "AR" , 32, "005", URGN_TERRITORY, "019" },
|
||||
{ "AS" , 16, "061", URGN_TERRITORY, "009" },
|
||||
{ "AT" , 40, "155", URGN_TERRITORY, "150" },
|
||||
{ "AU" , 36, "053", URGN_TERRITORY, "009" },
|
||||
{ "AW" , 533, "029", URGN_TERRITORY, "019" },
|
||||
{ "AX" , 248, "154", URGN_TERRITORY, "150" },
|
||||
{ "AZ" , 31, "145", URGN_TERRITORY, "142" },
|
||||
{ "BA" , 70, "039", URGN_TERRITORY, "150" },
|
||||
{ "BB" , 52, "029", URGN_TERRITORY, "019" },
|
||||
{ "BD" , 50, "034", URGN_TERRITORY, "142" },
|
||||
{ "BE" , 56, "155", URGN_TERRITORY, "150" },
|
||||
{ "BF" , 854, "011", URGN_TERRITORY, "002" },
|
||||
{ "BG" , 100, "151", URGN_TERRITORY, "150" },
|
||||
{ "BH" , 48, "145", URGN_TERRITORY, "142" },
|
||||
{ "BI" , 108, "014", URGN_TERRITORY, "002" },
|
||||
{ "BJ" , 204, "011", URGN_TERRITORY, "002" },
|
||||
{ "BL" , 652, "029", URGN_TERRITORY, "019" },
|
||||
{ "BM" , 60, "021", URGN_TERRITORY, "019" },
|
||||
{ "BN" , 96, "035", URGN_TERRITORY, "142" },
|
||||
{ "BO" , 68, "005", URGN_TERRITORY, "019" },
|
||||
{ "BQ" , 535, "029", URGN_TERRITORY, "019" },
|
||||
{ "BR" , 76, "005", URGN_TERRITORY, "019" },
|
||||
{ "BS" , 44, "029", URGN_TERRITORY, "019" },
|
||||
{ "BT" , 64, "034", URGN_TERRITORY, "142" },
|
||||
{ "BU" , 104, "035", URGN_TERRITORY, "142" },
|
||||
{ "BV" , 74, "QO" , URGN_TERRITORY, "009" },
|
||||
{ "BW" , 72, "018", URGN_TERRITORY, "002" },
|
||||
{ "BY" , 112, "151", URGN_TERRITORY, "150" },
|
||||
{ "BZ" , 84, "013", URGN_TERRITORY, "019" },
|
||||
{ "CA" , 124, "021", URGN_TERRITORY, "019" },
|
||||
{ "CC" , 166, "QO" , URGN_TERRITORY, "009" },
|
||||
{ "CD" , 180, "017", URGN_TERRITORY, "002" },
|
||||
{ "CF" , 140, "017", URGN_TERRITORY, "002" },
|
||||
{ "CG" , 178, "017", URGN_TERRITORY, "002" },
|
||||
{ "CH" , 756, "155", URGN_TERRITORY, "150" },
|
||||
{ "CI" , 384, "011", URGN_TERRITORY, "002" },
|
||||
{ "CK" , 184, "061", URGN_TERRITORY, "009" },
|
||||
{ "CL" , 152, "005", URGN_TERRITORY, "019" },
|
||||
{ "CM" , 120, "017", URGN_TERRITORY, "002" },
|
||||
{ "CN" , 156, "030", URGN_TERRITORY, "142" },
|
||||
{ "CO" , 170, "005", URGN_TERRITORY, "019" },
|
||||
{ "CP" , -1 , "QO" , URGN_TERRITORY, "009" },
|
||||
{ "CR" , 188, "013", URGN_TERRITORY, "019" },
|
||||
{ "CU" , 192, "029", URGN_TERRITORY, "019" },
|
||||
{ "CV" , 132, "011", URGN_TERRITORY, "002" },
|
||||
{ "CW" , 531, "029", URGN_TERRITORY, "019" },
|
||||
{ "CX" , 162, "QO" , URGN_TERRITORY, "009" },
|
||||
{ "CY" , 196, "145", URGN_TERRITORY, "142" },
|
||||
{ "CZ" , 203, "151", URGN_TERRITORY, "150" },
|
||||
{ "DD" , 276, "155", URGN_TERRITORY, "150" },
|
||||
{ "DE" , 276, "155", URGN_TERRITORY, "150" },
|
||||
{ "DG" , -1 , "QO" , URGN_TERRITORY, "009" },
|
||||
{ "DJ" , 262, "014", URGN_TERRITORY, "002" },
|
||||
{ "DK" , 208, "154", URGN_TERRITORY, "150" },
|
||||
{ "DM" , 212, "029", URGN_TERRITORY, "019" },
|
||||
{ "DO" , 214, "029", URGN_TERRITORY, "019" },
|
||||
{ "DZ" , 12, "015", URGN_TERRITORY, "002" },
|
||||
{ "EA" , -1, "015", URGN_TERRITORY, "002" },
|
||||
{ "EC" , 218, "005", URGN_TERRITORY, "019" },
|
||||
{ "EE" , 233, "154", URGN_TERRITORY, "150" },
|
||||
{ "EG" , 818, "015", URGN_TERRITORY, "002" },
|
||||
{ "EH" , 732, "015", URGN_TERRITORY, "002" },
|
||||
{ "ER" , 232, "014", URGN_TERRITORY, "002" },
|
||||
{ "ES" , 724, "039", URGN_TERRITORY, "150" },
|
||||
{ "ET" , 231, "014", URGN_TERRITORY, "002" },
|
||||
{ "EU" , 967, NULL, URGN_GROUPING, NULL },
|
||||
{ "FI" , 246, "154", URGN_TERRITORY, "150" },
|
||||
{ "FJ" , 242, "054", URGN_TERRITORY, "009" },
|
||||
{ "FK" , 238, "005", URGN_TERRITORY, "019" },
|
||||
{ "FM" , 583, "057", URGN_TERRITORY, "009" },
|
||||
{ "FO" , 234, "154", URGN_TERRITORY, "150" },
|
||||
{ "FR" , 250, "155", URGN_TERRITORY, "150" },
|
||||
{ "FX" , 250, "155", URGN_TERRITORY, "150" },
|
||||
{ "GA" , 266, "017", URGN_TERRITORY, "002" },
|
||||
{ "GB" , 826, "154", URGN_TERRITORY, "150" },
|
||||
{ "GD" , 308, "029", URGN_TERRITORY, "019" },
|
||||
{ "GE" , 268, "145", URGN_TERRITORY, "142" },
|
||||
{ "GF" , 254, "005", URGN_TERRITORY, "019" },
|
||||
{ "GG" , 831, "154", URGN_TERRITORY, "150" },
|
||||
{ "GH" , 288, "011", URGN_TERRITORY, "002" },
|
||||
{ "GI" , 292, "039", URGN_TERRITORY, "150" },
|
||||
{ "GL" , 304, "021", URGN_TERRITORY, "019" },
|
||||
{ "GM" , 270, "011", URGN_TERRITORY, "002" },
|
||||
{ "GN" , 324, "011", URGN_TERRITORY, "002" },
|
||||
{ "GP" , 312, "029", URGN_TERRITORY, "019" },
|
||||
{ "GQ" , 226, "017", URGN_TERRITORY, "002" },
|
||||
{ "GR" , 300, "039", URGN_TERRITORY, "150" },
|
||||
{ "GS" , 239, "QO" , URGN_TERRITORY, "009" },
|
||||
{ "GT" , 320, "013", URGN_TERRITORY, "019" },
|
||||
{ "GU" , 316, "057", URGN_TERRITORY, "009" },
|
||||
{ "GW" , 624, "011", URGN_TERRITORY, "002" },
|
||||
{ "GY" , 328, "005", URGN_TERRITORY, "019" },
|
||||
{ "HK" , 344, "030", URGN_TERRITORY, "142" },
|
||||
{ "HM" , 334, "QO" , URGN_TERRITORY, "009" },
|
||||
{ "HN" , 340, "013", URGN_TERRITORY, "019" },
|
||||
{ "HR" , 191, "039", URGN_TERRITORY, "150" },
|
||||
{ "HT" , 332, "029", URGN_TERRITORY, "019" },
|
||||
{ "HU" , 348, "151", URGN_TERRITORY, "150" },
|
||||
{ "IC" , -1, "015", URGN_TERRITORY, "002" },
|
||||
{ "ID" , 360, "035", URGN_TERRITORY, "142" },
|
||||
{ "IE" , 372, "154", URGN_TERRITORY, "150" },
|
||||
{ "IL" , 376, "145", URGN_TERRITORY, "142" },
|
||||
{ "IM" , 833, "154", URGN_TERRITORY, "150" },
|
||||
{ "IN" , 356, "034", URGN_TERRITORY, "142" },
|
||||
{ "IO" , 86, "QO" , URGN_TERRITORY, "009" },
|
||||
{ "IQ" , 368, "145", URGN_TERRITORY, "142" },
|
||||
{ "IR" , 364, "034", URGN_TERRITORY, "142" },
|
||||
{ "IS" , 352, "154", URGN_TERRITORY, "150" },
|
||||
{ "IT" , 380, "039", URGN_TERRITORY, "150" },
|
||||
{ "JE" , 832, "154", URGN_TERRITORY, "150" },
|
||||
{ "JM" , 388, "029", URGN_TERRITORY, "019" },
|
||||
{ "JO" , 400, "145", URGN_TERRITORY, "142" },
|
||||
{ "JP" , 392, "030", URGN_TERRITORY, "142" },
|
||||
{ "KE" , 404, "014", URGN_TERRITORY, "002" },
|
||||
{ "KG" , 417, "143", URGN_TERRITORY, "142" },
|
||||
{ "KH" , 116, "035", URGN_TERRITORY, "142" },
|
||||
{ "KI" , 296, "057", URGN_TERRITORY, "009" },
|
||||
{ "KM" , 174, "014", URGN_TERRITORY, "002" },
|
||||
{ "KN" , 659, "029", URGN_TERRITORY, "019" },
|
||||
{ "KP" , 408, "030", URGN_TERRITORY, "142" },
|
||||
{ "KR" , 410, "030", URGN_TERRITORY, "142" },
|
||||
{ "KW" , 414, "145", URGN_TERRITORY, "142" },
|
||||
{ "KY" , 136, "029", URGN_TERRITORY, "019" },
|
||||
{ "KZ" , 398, "143", URGN_TERRITORY, "142" },
|
||||
{ "LA" , 418, "035", URGN_TERRITORY, "142" },
|
||||
{ "LB" , 422, "145", URGN_TERRITORY, "142" },
|
||||
{ "LC" , 662, "029", URGN_TERRITORY, "019" },
|
||||
{ "LI" , 438, "155", URGN_TERRITORY, "150" },
|
||||
{ "LK" , 144, "034", URGN_TERRITORY, "142" },
|
||||
{ "LR" , 430, "011", URGN_TERRITORY, "002" },
|
||||
{ "LS" , 426, "018", URGN_TERRITORY, "002" },
|
||||
{ "LT" , 440, "154", URGN_TERRITORY, "150" },
|
||||
{ "LU" , 442, "155", URGN_TERRITORY, "150" },
|
||||
{ "LV" , 428, "154", URGN_TERRITORY, "150" },
|
||||
{ "LY" , 434, "015", URGN_TERRITORY, "002" },
|
||||
{ "MA" , 504, "015", URGN_TERRITORY, "002" },
|
||||
{ "MC" , 492, "155", URGN_TERRITORY, "150" },
|
||||
{ "MD" , 498, "151", URGN_TERRITORY, "150" },
|
||||
{ "ME" , 499, "039", URGN_TERRITORY, "150" },
|
||||
{ "MF" , 663, "029", URGN_TERRITORY, "019" },
|
||||
{ "MG" , 450, "014", URGN_TERRITORY, "002" },
|
||||
{ "MH" , 584, "057", URGN_TERRITORY, "009" },
|
||||
{ "MK" , 807, "039", URGN_TERRITORY, "150" },
|
||||
{ "ML" , 466, "011", URGN_TERRITORY, "002" },
|
||||
{ "MM" , 104, "035", URGN_TERRITORY, "142" },
|
||||
{ "MN" , 496, "030", URGN_TERRITORY, "142" },
|
||||
{ "MO" , 446, "030", URGN_TERRITORY, "142" },
|
||||
{ "MP" , 580, "057", URGN_TERRITORY, "009" },
|
||||
{ "MQ" , 474, "029", URGN_TERRITORY, "019" },
|
||||
{ "MR" , 478, "011", URGN_TERRITORY, "002" },
|
||||
{ "MS" , 500, "029", URGN_TERRITORY, "019" },
|
||||
{ "MT" , 470, "039", URGN_TERRITORY, "150" },
|
||||
{ "MU" , 480, "014", URGN_TERRITORY, "002" },
|
||||
{ "MV" , 462, "034", URGN_TERRITORY, "142" },
|
||||
{ "MW" , 454, "014", URGN_TERRITORY, "002" },
|
||||
{ "MX" , 484, "013", URGN_TERRITORY, "019"},
|
||||
{ "MY" , 458, "035", URGN_TERRITORY, "142" },
|
||||
{ "MZ" , 508, "014", URGN_TERRITORY, "002" },
|
||||
{ "NA" , 516, "018", URGN_TERRITORY, "002" },
|
||||
{ "NC" , 540, "054", URGN_TERRITORY, "009" },
|
||||
{ "NE" , 562, "011", URGN_TERRITORY, "002" },
|
||||
{ "NF" , 574, "053", URGN_TERRITORY, "009" },
|
||||
{ "NG" , 566, "011", URGN_TERRITORY, "002" },
|
||||
{ "NI" , 558, "013", URGN_TERRITORY, "019" },
|
||||
{ "NL" , 528, "155", URGN_TERRITORY, "150" },
|
||||
{ "NO" , 578, "154", URGN_TERRITORY, "150" },
|
||||
{ "NP" , 524, "034", URGN_TERRITORY, "142" },
|
||||
{ "NR" , 520, "057", URGN_TERRITORY, "009" },
|
||||
{ "NT" , 536, NULL , URGN_DEPRECATED, NULL },
|
||||
{ "NU" , 570, "061", URGN_TERRITORY, "009" },
|
||||
{ "NZ" , 554, "053", URGN_TERRITORY, "009" },
|
||||
{ "OM" , 512, "145", URGN_TERRITORY, "142" },
|
||||
{ "PA" , 591, "013", URGN_TERRITORY, "019" },
|
||||
{ "PE" , 604, "005", URGN_TERRITORY, "019" },
|
||||
{ "PF" , 258, "061", URGN_TERRITORY, "009" },
|
||||
{ "PG" , 598, "054", URGN_TERRITORY, "009" },
|
||||
{ "PH" , 608, "035", URGN_TERRITORY, "142" },
|
||||
{ "PK" , 586, "034", URGN_TERRITORY, "142" },
|
||||
{ "PL" , 616, "151", URGN_TERRITORY, "150" },
|
||||
{ "PM" , 666, "021", URGN_TERRITORY, "019" },
|
||||
{ "PN" , 612, "061", URGN_TERRITORY, "009" },
|
||||
{ "PR" , 630, "029", URGN_TERRITORY, "019" },
|
||||
{ "PS" , 275, "145", URGN_TERRITORY, "142" },
|
||||
{ "PT" , 620, "039", URGN_TERRITORY, "150" },
|
||||
{ "PW" , 585, "057", URGN_TERRITORY, "009" },
|
||||
{ "PY" , 600, "005", URGN_TERRITORY, "019" },
|
||||
{ "QA" , 634, "145", URGN_TERRITORY, "142" },
|
||||
{ "QO" , 961, "009", URGN_SUBCONTINENT, "009" },
|
||||
{ "QU" , 967, NULL, URGN_GROUPING, NULL },
|
||||
{ "RE" , 638, "014", URGN_TERRITORY, "002" },
|
||||
{ "RO" , 642, "151", URGN_TERRITORY, "150" },
|
||||
{ "RS" , 688, "039", URGN_TERRITORY, "150" },
|
||||
{ "RU" , 643, "151", URGN_TERRITORY, "150" },
|
||||
{ "RW" , 646, "014", URGN_TERRITORY, "002" },
|
||||
{ "SA" , 682, "145", URGN_TERRITORY, "142" },
|
||||
{ "SB" , 90, "054", URGN_TERRITORY, "009" },
|
||||
{ "SC" , 690, "014", URGN_TERRITORY, "002" },
|
||||
{ "SD" , 729, "015", URGN_TERRITORY, "002" },
|
||||
{ "SE" , 752, "154", URGN_TERRITORY, "150" },
|
||||
{ "SG" , 702, "035", URGN_TERRITORY, "142" },
|
||||
{ "SH" , 654, "011", URGN_TERRITORY, "002" },
|
||||
{ "SI" , 705, "039", URGN_TERRITORY, "150" },
|
||||
{ "SJ" , 744, "154", URGN_TERRITORY, "150" },
|
||||
{ "SK" , 703, "151", URGN_TERRITORY, "150" },
|
||||
{ "SL" , 694, "011", URGN_TERRITORY, "002" },
|
||||
{ "SM" , 674, "039", URGN_TERRITORY, "150" },
|
||||
{ "SN" , 686, "011", URGN_TERRITORY, "002" },
|
||||
{ "SO" , 706, "014", URGN_TERRITORY, "002" },
|
||||
{ "SR" , 740, "005", URGN_TERRITORY, "019" },
|
||||
{ "SS" , 728, "015", URGN_TERRITORY, "002" },
|
||||
{ "ST" , 678, "017", URGN_TERRITORY, "002" },
|
||||
{ "SU" , 810, NULL , URGN_DEPRECATED , NULL},
|
||||
{ "SV" , 222, "013", URGN_TERRITORY, "019" },
|
||||
{ "SX" , 534, "029", URGN_TERRITORY, "019" },
|
||||
{ "SY" , 760, "145", URGN_TERRITORY, "142" },
|
||||
{ "SZ" , 748, "018", URGN_TERRITORY, "002" },
|
||||
{ "TA" , -1, "QO", URGN_TERRITORY, "009" },
|
||||
{ "TC" , 796, "029", URGN_TERRITORY, "019" },
|
||||
{ "TD" , 148, "017", URGN_TERRITORY, "002" },
|
||||
{ "TF" , 260, "QO" , URGN_TERRITORY, "009" },
|
||||
{ "TG" , 768, "011", URGN_TERRITORY, "002" },
|
||||
{ "TH" , 764, "035", URGN_TERRITORY, "142" },
|
||||
{ "TJ" , 762, "143", URGN_TERRITORY, "142" },
|
||||
{ "TK" , 772, "061", URGN_TERRITORY, "009" },
|
||||
{ "TL" , 626, "035", URGN_TERRITORY, "142" },
|
||||
{ "TM" , 795, "143", URGN_TERRITORY, "142" },
|
||||
{ "TN" , 788, "015", URGN_TERRITORY, "002" },
|
||||
{ "TO" , 776, "061", URGN_TERRITORY, "009" },
|
||||
{ "TP" , 626, "035", URGN_TERRITORY, "142" },
|
||||
{ "TR" , 792, "145", URGN_TERRITORY, "142" },
|
||||
{ "TT" , 780, "029", URGN_TERRITORY, "019" },
|
||||
{ "TV" , 798, "061", URGN_TERRITORY, "009" },
|
||||
{ "TW" , 158, "030", URGN_TERRITORY, "142" },
|
||||
{ "TZ" , 834, "014", URGN_TERRITORY, "002" },
|
||||
{ "UA" , 804, "151", URGN_TERRITORY, "150" },
|
||||
{ "UG" , 800, "014", URGN_TERRITORY, "002" },
|
||||
{ "UM" , 581, "QO" , URGN_TERRITORY, "009" },
|
||||
{ "US" , 840, "021", URGN_TERRITORY, "019" },
|
||||
{ "UY" , 858, "005", URGN_TERRITORY, "019" },
|
||||
{ "UZ" , 860, "143", URGN_TERRITORY, "142" },
|
||||
{ "VA" , 336, "039", URGN_TERRITORY, "150" },
|
||||
{ "VC" , 670, "029", URGN_TERRITORY, "019" },
|
||||
{ "VE" , 862, "005", URGN_TERRITORY, "019" },
|
||||
{ "VG" , 92, "029", URGN_TERRITORY, "019" },
|
||||
{ "VI" , 850, "029", URGN_TERRITORY, "019" },
|
||||
{ "VN" , 704, "035", URGN_TERRITORY, "142" },
|
||||
{ "VU" , 548, "054", URGN_TERRITORY, "009" },
|
||||
{ "WF" , 876, "061", URGN_TERRITORY, "009" },
|
||||
{ "WS" , 882, "061", URGN_TERRITORY, "009" },
|
||||
{ "YD" , 887, "145", URGN_TERRITORY, "142" },
|
||||
{ "YE" , 887, "145", URGN_TERRITORY, "142" },
|
||||
{ "YT" , 175, "014", URGN_TERRITORY, "002" },
|
||||
{ "ZA" , 710, "018", URGN_TERRITORY, "002" },
|
||||
{ "ZM" , 894, "014", URGN_TERRITORY, "002" },
|
||||
{ "ZR" , 180, "017", URGN_TERRITORY, "002" },
|
||||
{ "ZW" , 716, "014", URGN_TERRITORY, "002" },
|
||||
{ "ZZ" , 999, NULL , URGN_UNKNOWN, NULL },
|
||||
{ NULL , 0, NULL , URGN_UNKNOWN, NULL } /* terminator */
|
||||
};
|
||||
|
||||
|
||||
static void TestKnownRegions() {
|
||||
const KnownRegion * rd;
|
||||
for (rd = knownRegions; rd->code != NULL ; rd++ ) {
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
const URegion *r = uregion_getRegionFromCode(rd->code, &status);
|
||||
if ( U_SUCCESS(status) ) {
|
||||
int32_t n = uregion_getNumericCode(r);
|
||||
int32_t e = rd->numeric;
|
||||
if ( n != e ) {
|
||||
log_err("ERROR: Numeric code mismatch for region %s. Expected:%d Got:%d\n", uregion_getRegionCode(r), e, n );
|
||||
}
|
||||
if (uregion_getType(r) != rd->type) {
|
||||
log_err("ERROR: Expected region %s to be of type %d. Got: %d\n", uregion_getRegionCode(r), rd->type, uregion_getType(r) );
|
||||
}
|
||||
if ( e > 0 ) {
|
||||
const URegion *ncRegion = uregion_getRegionFromNumericCode(e, &status);
|
||||
if ( !uregion_isEqualTo(ncRegion, r) && e != 891 ) { // 891 is special case - CS and YU both deprecated codes for region 891
|
||||
log_err("ERROR: Creating region %s by its numeric code returned a different region. Got: %s instead.\n",
|
||||
uregion_getRegionCode(r), uregion_getRegionCode(ncRegion) );
|
||||
}
|
||||
}
|
||||
} else {
|
||||
log_data_err("ERROR: Known region %s was not recognized.\n", rd->code);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void TestGetContainedRegions() {
|
||||
const KnownRegion * rd;
|
||||
for (rd = knownRegions; rd->code != NULL ; rd++ ) {
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
const URegion *r = uregion_getRegionFromCode(rd->code, &status);
|
||||
if ( U_SUCCESS(status) ) {
|
||||
UEnumeration *containedRegions;
|
||||
const char *crID;
|
||||
if (uregion_getType(r) == URGN_GROUPING) {
|
||||
continue;
|
||||
}
|
||||
containedRegions = uregion_getContainedRegions(r, &status);
|
||||
while ((crID = uenum_next(containedRegions, NULL, &status)) != NULL && U_SUCCESS(status) ) {
|
||||
const URegion *cr = uregion_getRegionFromCode(crID, &status);
|
||||
const URegion *containingRegion = (cr)? uregion_getContainingRegion(cr) : NULL;
|
||||
if ( !containingRegion || !uregion_isEqualTo(containingRegion, r) ) {
|
||||
log_err("ERROR: Region: %s contains region %s. Expected containing region of this region to be the original region, but got %s\n",
|
||||
uregion_getRegionCode(r), uregion_getRegionCode(cr), (containingRegion)?uregion_getRegionCode(containingRegion):"NULL" );
|
||||
}
|
||||
}
|
||||
uenum_close(containedRegions);
|
||||
} else {
|
||||
log_data_err("ERROR: Known region %s was not recognized.\n", rd->code);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void TestGetContainedRegionsWithType() {
|
||||
const KnownRegion * rd;
|
||||
for (rd = knownRegions; rd->code != NULL ; rd++ ) {
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
const URegion *r = uregion_getRegionFromCode(rd->code, &status);
|
||||
if ( U_SUCCESS(status) ) {
|
||||
UEnumeration *containedRegions;
|
||||
const char *crID;
|
||||
if (uregion_getType(r) != URGN_CONTINENT) {
|
||||
continue;
|
||||
}
|
||||
containedRegions = uregion_getContainedRegionsOfType(r, URGN_TERRITORY, &status);
|
||||
while ((crID = uenum_next(containedRegions, NULL, &status)) != NULL && U_SUCCESS(status) ) {
|
||||
const URegion *cr = uregion_getRegionFromCode(crID, &status);
|
||||
const URegion *containingRegion = (cr)? uregion_getContainingRegionOfType(cr, URGN_CONTINENT) : NULL;
|
||||
if ( !containingRegion || !uregion_isEqualTo(containingRegion, r) ) {
|
||||
log_err("ERROR: Continent: %s contains territory %s. Expected containing continent of this region to be the original region, but got %s\n",
|
||||
uregion_getRegionCode(r), uregion_getRegionCode(cr), (containingRegion)?uregion_getRegionCode(containingRegion):"NULL" );
|
||||
}
|
||||
}
|
||||
uenum_close(containedRegions);
|
||||
} else {
|
||||
log_data_err("ERROR: Known region %s was not recognized.\n", rd->code);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void TestGetContainingRegion() {
|
||||
const KnownRegion * rd;
|
||||
for (rd = knownRegions; rd->code != NULL ; rd++ ) {
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
const URegion *r = uregion_getRegionFromCode(rd->code, &status);
|
||||
if ( U_SUCCESS(status) ) {
|
||||
const URegion *c = uregion_getContainingRegion(r);
|
||||
if (rd->parent == NULL) {
|
||||
if ( c ) {
|
||||
log_err("ERROR: Containing region for %s should have been NULL. Got: %s\n", uregion_getRegionCode(r), uregion_getRegionCode(c) );
|
||||
}
|
||||
} else {
|
||||
const URegion *p = uregion_getRegionFromCode(rd->parent, &status);
|
||||
if ( c == NULL || !uregion_isEqualTo(p, c) ) {
|
||||
log_err("ERROR: Expected containing continent of region %s to be %s. Got: %s\n",
|
||||
uregion_getRegionCode(r), (p)?uregion_getRegionCode(p):"NULL", (c)?uregion_getRegionCode(c):"NULL" );
|
||||
}
|
||||
}
|
||||
} else {
|
||||
log_data_err("ERROR: Known region %s was not recognized.\n", rd->code);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void TestGetContainingRegionWithType() {
|
||||
const KnownRegion * rd;
|
||||
for (rd = knownRegions; rd->code != NULL ; rd++ ) {
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
const URegion *r = uregion_getRegionFromCode(rd->code, &status);
|
||||
if ( U_SUCCESS(status) ) {
|
||||
const URegion *c = uregion_getContainingRegionOfType(r, URGN_CONTINENT);
|
||||
if (rd->containingContinent == NULL) {
|
||||
if ( c != NULL) {
|
||||
log_err("ERROR: Containing continent for %s should have been NULL. Got: %s\n", uregion_getRegionCode(r), uregion_getRegionCode(c) );
|
||||
}
|
||||
} else {
|
||||
const URegion *p = uregion_getRegionFromCode(rd->containingContinent, &status);
|
||||
if ( !uregion_isEqualTo(p, c) ) {
|
||||
log_err("ERROR: Expected containing continent of region %s to be %s. Got: %s\n",
|
||||
uregion_getRegionCode(r), (p)?uregion_getRegionCode(p):"NULL", (c)?uregion_getRegionCode(c):"NULL" );
|
||||
}
|
||||
}
|
||||
} else {
|
||||
log_data_err("ERROR: Known region %s was not recognized.\n", rd->code);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif /* #if !UCONFIG_NO_FORMATTING */
|
Loading…
Reference in New Issue
Block a user