ICU-9303 Check in tentative UDisplayContext enum and related LocaleDisplayNames APIs; still need full impl & tests

X-SVN-Rev: 32548
This commit is contained in:
Peter Edberg 2012-10-08 16:50:51 +00:00
parent b72359eca5
commit 7a826f4b61
7 changed files with 288 additions and 11 deletions

1
.gitattributes vendored
View file

@ -75,6 +75,7 @@ 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/gender.h -text
icu4c/source/i18n/unicode/udisplaycontext.h -text
icu4c/source/i18n/unicode/ugender.h -text
icu4c/source/io/io.vcxproj -text
icu4c/source/io/io.vcxproj.filters -text

View file

@ -1312,6 +1312,20 @@
</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\udisplaycontext.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>

View file

@ -961,6 +961,9 @@
<CustomBuild Include="unicode\udatpg.h">
<Filter>formatting</Filter>
</CustomBuild>
<CustomBuild Include="unicode\udisplaycontext.h">
<Filter>formatting</Filter>
</CustomBuild>
<CustomBuild Include="unicode\ugender.h">
<Filter>formatting</Filter>
</CustomBuild>

View file

@ -164,6 +164,7 @@ public:
virtual const Locale& getLocale() const;
virtual UDialectHandling getDialectHandling() const;
virtual UnicodeString& localeDisplayName(const Locale& locale,
UnicodeString& result) const;
virtual UnicodeString& localeDisplayName(const char* localeId,
@ -273,14 +274,17 @@ class LocaleDisplayNamesImpl : public LocaleDisplayNames {
UnicodeString sep;
MessageFormat *format;
MessageFormat *keyTypeFormat;
UDisplayContext capitalizationContext;
public:
// constructor
LocaleDisplayNamesImpl(const Locale& locale, UDialectHandling dialectHandling);
LocaleDisplayNamesImpl(const Locale& locale, UDisplayContext *contexts, int32_t length);
virtual ~LocaleDisplayNamesImpl();
virtual const Locale& getLocale() const;
virtual UDialectHandling getDialectHandling() const;
virtual UDisplayContext getContext(UDisplayContextType type) const;
virtual UnicodeString& localeDisplayName(const Locale& locale,
UnicodeString& result) const;
@ -305,6 +309,7 @@ private:
UnicodeString& localeIdName(const char* localeId,
UnicodeString& result) const;
UnicodeString& appendWithSep(UnicodeString& buffer, const UnicodeString& src) const;
void initialize(void);
};
LocaleDisplayNamesImpl::LocaleDisplayNamesImpl(const Locale& locale,
@ -314,7 +319,39 @@ LocaleDisplayNamesImpl::LocaleDisplayNamesImpl(const Locale& locale,
, regionData(U_ICUDATA_REGION, locale)
, format(NULL)
, keyTypeFormat(NULL)
, capitalizationContext(UDISPCTX_CAPITALIZATION_NONE)
{
initialize();
}
LocaleDisplayNamesImpl::LocaleDisplayNamesImpl(const Locale& locale,
UDisplayContext *contexts, int32_t length)
: dialectHandling(ULDN_STANDARD_NAMES)
, langData(U_ICUDATA_LANG, locale)
, regionData(U_ICUDATA_REGION, locale)
, format(NULL)
, keyTypeFormat(NULL)
, capitalizationContext(UDISPCTX_CAPITALIZATION_NONE)
{
while (length-- > 0) {
UDisplayContext value = *contexts++;
UDisplayContextType selector = (UDisplayContextType)(value & ~0xFF);
switch (selector) {
case UDISPCTX_TYPE_DIALECT_HANDLING:
dialectHandling = (UDialectHandling)value;
break;
case UDISPCTX_TYPE_CAPITALIZATION:
capitalizationContext = value;
break;
default:
break;
}
}
initialize();
}
void
LocaleDisplayNamesImpl::initialize(void) {
LocaleDisplayNamesImpl *nonConstThis = (LocaleDisplayNamesImpl *)this;
nonConstThis->locale = langData.getLocale() == Locale::getRoot()
? regionData.getLocale()
@ -356,6 +393,20 @@ LocaleDisplayNamesImpl::getDialectHandling() const {
return dialectHandling;
}
UDisplayContext
LocaleDisplayNamesImpl::getContext(UDisplayContextType type) const {
switch (type) {
case UDISPCTX_TYPE_DIALECT_HANDLING:
return (UDisplayContext)dialectHandling;
case UDISPCTX_TYPE_CAPITALIZATION:
return capitalizationContext;
default:
break;
}
return (UDisplayContext)0;
}
// TODO: Make the following depend on capitalizationContext
UnicodeString&
LocaleDisplayNamesImpl::localeDisplayName(const Locale& locale,
UnicodeString& result) const {
@ -542,6 +593,15 @@ LocaleDisplayNames::createInstance(const Locale& locale,
return new LocaleDisplayNamesImpl(locale, dialectHandling);
}
LocaleDisplayNames*
LocaleDisplayNames::createInstance(const Locale& locale,
UDisplayContext *contexts, int32_t length) {
if (contexts == NULL) {
length = 0;
}
return new LocaleDisplayNamesImpl(locale, contexts, length);
}
U_NAMESPACE_END
////////////////////////////////////////////////////////////////////////////////////////////////////
@ -561,6 +621,20 @@ uldn_open(const char * locale,
return (ULocaleDisplayNames *)LocaleDisplayNames::createInstance(Locale(locale), dialectHandling);
}
U_CAPI ULocaleDisplayNames * U_EXPORT2
uldn_openForContext(const char * locale,
UDisplayContext *contexts, int32_t length,
UErrorCode *pErrorCode) {
if (U_FAILURE(*pErrorCode)) {
return 0;
}
if (locale == NULL) {
locale = uloc_getDefault();
}
return (ULocaleDisplayNames *)LocaleDisplayNames::createInstance(Locale(locale), contexts, length);
}
U_CAPI void U_EXPORT2
uldn_close(ULocaleDisplayNames *ldn) {
delete (LocaleDisplayNames *)ldn;
@ -582,6 +656,16 @@ uldn_getDialectHandling(const ULocaleDisplayNames *ldn) {
return ULDN_STANDARD_NAMES;
}
U_CAPI UDisplayContext U_EXPORT2
uldn_getContext(const ULocaleDisplayNames *ldn,
UDisplayContextType type,
UErrorCode *pErrorCode) {
if (U_FAILURE(*pErrorCode)) {
return (UDisplayContext)0;
}
return ((const LocaleDisplayNames *)ldn)->getContext(type);
}
U_CAPI int32_t U_EXPORT2
uldn_localeDisplayName(const ULocaleDisplayNames *ldn,
const char *locale,

View file

@ -1,6 +1,6 @@
/*
******************************************************************************
* Copyright (C) 2010-2011, International Business Machines Corporation and
* Copyright (C) 2010-2012, International Business Machines Corporation and
* others. All Rights Reserved.
******************************************************************************
*/
@ -20,6 +20,7 @@
#include "unicode/locid.h"
#include "unicode/uscript.h"
#include "unicode/uldnames.h"
#include "unicode/udisplaycontext.h"
U_NAMESPACE_BEGIN
@ -58,7 +59,21 @@ public:
* @stable ICU 4.4
*/
static LocaleDisplayNames* U_EXPORT2 createInstance(const Locale& locale,
UDialectHandling dialectHandling);
UDialectHandling dialectHandling);
/**
* Returns an instance of LocaleDisplayNames that returns names formatted
* for the provided locale, using the provided UDisplayContext settings.
*
* @param locale the display locale
* @param contexts List of one or more context settings (e.g. for dialect
* handling, capitalization, etc.
* @param length Number of items in the contexts list
* @return a LocaleDisplayNames instance
* @internal ICU 50 technology preview
*/
static LocaleDisplayNames* U_EXPORT2 createInstance(const Locale& locale,
UDisplayContext *contexts, int32_t length);
// getters for state
/**
@ -76,6 +91,14 @@ public:
*/
virtual UDialectHandling getDialectHandling() const = 0;
/**
* Returns the UDisplayContext value for the specified UDisplayContextType.
* @param type the UDisplayContextType whose value to return
* @return the UDisplayContext for the specified type.
* @internal ICU 50 technology preview
*/
virtual UDisplayContext getContext(UDisplayContextType type) const = 0;
// names for entire locales
/**
* Returns the display name of the provided locale.
@ -85,7 +108,7 @@ public:
* @stable ICU 4.4
*/
virtual UnicodeString& localeDisplayName(const Locale& locale,
UnicodeString& result) const = 0;
UnicodeString& result) const = 0;
/**
* Returns the display name of the provided locale id.
@ -95,7 +118,7 @@ public:
* @stable ICU 4.4
*/
virtual UnicodeString& localeDisplayName(const char* localeId,
UnicodeString& result) const = 0;
UnicodeString& result) const = 0;
// names for components of a locale id
/**
@ -106,7 +129,7 @@ public:
* @stable ICU 4.4
*/
virtual UnicodeString& languageDisplayName(const char* lang,
UnicodeString& result) const = 0;
UnicodeString& result) const = 0;
/**
* Returns the display name of the provided script code.
@ -116,7 +139,7 @@ public:
* @stable ICU 4.4
*/
virtual UnicodeString& scriptDisplayName(const char* script,
UnicodeString& result) const = 0;
UnicodeString& result) const = 0;
/**
* Returns the display name of the provided script code.
@ -126,7 +149,7 @@ public:
* @stable ICU 4.4
*/
virtual UnicodeString& scriptDisplayName(UScriptCode scriptCode,
UnicodeString& result) const = 0;
UnicodeString& result) const = 0;
/**
* Returns the display name of the provided region code.
@ -136,7 +159,7 @@ public:
* @stable ICU 4.4
*/
virtual UnicodeString& regionDisplayName(const char* region,
UnicodeString& result) const = 0;
UnicodeString& result) const = 0;
/**
* Returns the display name of the provided variant.
@ -146,7 +169,7 @@ public:
* @stable ICU 4.4
*/
virtual UnicodeString& variantDisplayName(const char* variant,
UnicodeString& result) const = 0;
UnicodeString& result) const = 0;
/**
* Returns the display name of the provided locale key.
@ -156,7 +179,7 @@ public:
* @stable ICU 4.4
*/
virtual UnicodeString& keyDisplayName(const char* key,
UnicodeString& result) const = 0;
UnicodeString& result) const = 0;
/**
* Returns the display name of the provided value (used with the provided key).
@ -167,7 +190,7 @@ public:
* @stable ICU 4.4
*/
virtual UnicodeString& keyValueDisplayName(const char* key, const char* value,
UnicodeString& result) const = 0;
UnicodeString& result) const = 0;
private:
// No ICU "poor man's RTTI" for this class nor its subclasses.

View file

@ -0,0 +1,115 @@
/*
*****************************************************************************************
* Copyright (C) 2012, International Business Machines
* Corporation and others. All Rights Reserved.
*****************************************************************************************
*/
#ifndef UDISPLAYCONTEXT_H
#define UDISPLAYCONTEXT_H
#include "unicode/utypes.h"
#if !UCONFIG_NO_FORMATTING
/* Dont hide with #ifndef U_HIDE_INTERNAL_API, needed by virtual methods */
/**
* Display context settings.
* Note, the specific numeric values are internal and may change.
* @internal ICU 50 technology preview
*/
enum UDisplayContext {
/**
* ================================
* DIALECT_HANDLING can be set to one of UDISPCTX_STANDARD_NAMES or
* UDISPCTX_DIALECT_NAMES. Use UDisplayContextType UDISPCTX_TYPE_DIALECT_HANDLING
* to get the value.
*/
/**
* A possible setting for DIALECT_HANDLING:
* use standard names when generating a locale name,
* e.g. en_GB displays as 'English (United Kingdom)'.
* @internal ICU 50 technology preview
*/
UDISPCTX_STANDARD_NAMES = 0,
/**
* A possible setting for DIALECT_HANDLING:
* use dialect names, when generating a locale name,
* e.g. en_GB displays as 'British English'.
* @internal ICU 50 technology preview
*/
UDISPCTX_DIALECT_NAMES = 1,
/**
* ================================
* CAPITALIZATION can be set to one of UDISPCTX_CAPITALIZATION_NONE,
* UDISPCTX_CAPITALIZATION_FOR_MIDDLE_OF_SENTENCE,
* UDISPCTX_CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE,
* UDISPCTX_CAPITALIZATION_FOR_UI_LIST_OR_MENU, or
* UDISPCTX_CAPITALIZATION_FOR_STANDALONE.
* Use UDisplayContextType UDISPCTX_TYPE_CAPITALIZATION to get the value.
*/
/**
* The capitalization context to be used is unknown (this is the default value).
* @internal ICU 50 technology preview
*/
UDISPCTX_CAPITALIZATION_NONE = 0x100,
/**
* The capitalization context if a date, date symbol or display name is to be
* formatted with capitalization appropriate for the middle of a sentence.
* @internal ICU 50 technology preview
*/
UDISPCTX_CAPITALIZATION_FOR_MIDDLE_OF_SENTENCE = 0x101,
/**
* The capitalization context if a date, date symbol or display name is to be
* formatted with capitalization appropriate for the beginning of a sentence.
* @internal ICU 50 technology preview
*/
UDISPCTX_CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE = 0x102,
/**
* The capitalization context if a date, date symbol or display name is to be
* formatted with capitalization appropriate for a user-interface list or menu item.
* @internal ICU 50 technology preview
*/
UDISPCTX_CAPITALIZATION_FOR_UI_LIST_OR_MENU = 0x103,
/**
* The capitalization context if a date, date symbol or display name is to be
* formatted with capitalization appropriate for stand-alone usage such as an
* isolated name on a calendar page.
* @internal ICU 50 technology preview
*/
UDISPCTX_CAPITALIZATION_FOR_STANDALONE = 0x104
};
/**
* @internal ICU 50 technology preview
*/
typedef enum UDisplayContext UDisplayContext;
/* Dont hide with #ifndef U_HIDE_INTERNAL_API, needed by virtual methods */
/**
* Display context types, for getting values of a particular setting.
* Note, the specific numeric values are internal and may change.
* @internal ICU 50 technology preview
*/
enum UDisplayContextType {
/**
* Type to retrieve the dialect handling setting, e.g.
* UDISPCTX_STANDARD_NAMES or UDISPCTX_DIALECT_NAMES.
* @internal ICU 50 technology preview
*/
UDISPCTX_TYPE_DIALECT_HANDLING = 0,
/**
* Type to retrieve the capitalization context setting, e.g.
* UDISPCTX_CAPITALIZATION_NONE, UDISPCTX_CAPITALIZATION_FOR_MIDDLE_OF_SENTENCE,
* UDISPCTX_CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE, etc.
* @internal ICU 50 technology preview
*/
UDISPCTX_TYPE_CAPITALIZATION = 0x100
};
/**
* @internal ICU 50 technology preview
*/
typedef enum UDisplayContextType UDisplayContextType;
#endif /* #if !UCONFIG_NO_FORMATTING */
#endif

View file

@ -16,6 +16,7 @@
#include "unicode/utypes.h"
#include "unicode/localpointer.h"
#include "unicode/uscript.h"
#include "unicode/udisplaycontext.h"
/**
* Enum used in LocaleDisplayNames::createInstance.
@ -265,6 +266,42 @@ uldn_keyValueDisplayName(const ULocaleDisplayNames *ldn,
int32_t maxResultSize,
UErrorCode *pErrorCode);
#ifndef U_HIDE_INTERNAL_API
/**
* Returns an instance of LocaleDisplayNames that returns names formatted
* for the provided locale, using the provided UDisplayContext settings.
*
* @param locale The display locale
* @param contexts List of one or more context settings (e.g. for dialect
* handling, capitalization, etc.
* @param length Number of items in the contexts list
* @param pErrorCode Pointer to UErrorCode input/output status. If at entry this indicates
* a failure status, the function will do nothing; otherwise this will be
* updated with any new status from the function.
* @return a ULocaleDisplayNames instance
* @internal ICU 50 technology preview
*/
U_INTERNAL ULocaleDisplayNames * U_EXPORT2
uldn_openForContext(const char * locale,
UDisplayContext *contexts, int32_t length,
UErrorCode *pErrorCode);
/**
* Returns the UDisplayContext value for the specified UDisplayContextType.
* @param ldn the ULocaleDisplayNames instance
* @param type the UDisplayContextType whose value to return
* @param pErrorCode Pointer to UErrorCode input/output status. If at entry this indicates
* a failure status, the function will do nothing; otherwise this will be
* updated with any new status from the function.
* @return the UDisplayContextValue for the specified type.
* @internal ICU 50 technology preview
*/
U_INTERNAL UDisplayContext U_EXPORT2
uldn_getContext(const ULocaleDisplayNames *ldn,
UDisplayContextType type,
UErrorCode *pErrorCode);
#endif /* U_HIDE_INTERNAL_API */
#endif /* !UCONFIG_NO_FORMATTING */
#endif /* __ULDNAMES_H__ */