ICU-11779 Introduce static versions of DTPNG getSkeleton and getBaseSkeleton
X-SVN-Rev: 37771
This commit is contained in:
parent
d3bb77fac4
commit
6ed4b6178a
@ -636,7 +636,8 @@ DateIntervalFormat::initializePattern(UErrorCode& status) {
|
||||
#endif
|
||||
// fSkeleton is already set by createDateIntervalInstance()
|
||||
// or by createInstance(UnicodeString skeleton, .... )
|
||||
fSkeleton = fDtpng->getSkeleton(fullPattern, status);
|
||||
fSkeleton = DateTimePatternGenerator::staticGetSkeleton(
|
||||
fullPattern, status);
|
||||
if ( U_FAILURE(status) ) {
|
||||
return;
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
*******************************************************************************
|
||||
* Copyright (C) 2007-2014, International Business Machines Corporation and
|
||||
* Copyright (C) 2007-2015, International Business Machines Corporation and
|
||||
* others. All Rights Reserved.
|
||||
*******************************************************************************
|
||||
*
|
||||
@ -441,16 +441,23 @@ DateTimePatternGenerator::initData(const Locale& locale, UErrorCode &status) {
|
||||
} // DateTimePatternGenerator::initData
|
||||
|
||||
UnicodeString
|
||||
DateTimePatternGenerator::getSkeleton(const UnicodeString& pattern, UErrorCode&
|
||||
/*status*/) {
|
||||
dtMatcher->set(pattern, fp);
|
||||
return dtMatcher->getSkeletonPtr()->getSkeleton();
|
||||
DateTimePatternGenerator::staticGetSkeleton(
|
||||
const UnicodeString& pattern, UErrorCode& /*status*/) {
|
||||
FormatParser fp;
|
||||
DateTimeMatcher matcher;
|
||||
PtnSkeleton localSkeleton;
|
||||
matcher.set(pattern, &fp, localSkeleton);
|
||||
return localSkeleton.getSkeleton();
|
||||
}
|
||||
|
||||
UnicodeString
|
||||
DateTimePatternGenerator::getBaseSkeleton(const UnicodeString& pattern, UErrorCode& /*status*/) {
|
||||
dtMatcher->set(pattern, fp);
|
||||
return dtMatcher->getSkeletonPtr()->getBaseSkeleton();
|
||||
DateTimePatternGenerator::staticGetBaseSkeleton(
|
||||
const UnicodeString& pattern, UErrorCode& /*status*/) {
|
||||
FormatParser fp;
|
||||
DateTimeMatcher matcher;
|
||||
PtnSkeleton localSkeleton;
|
||||
matcher.set(pattern, &fp, localSkeleton);
|
||||
return localSkeleton.getBaseSkeleton();
|
||||
}
|
||||
|
||||
void
|
||||
@ -1884,7 +1891,7 @@ FormatParser::getCanonicalIndex(const UnicodeString& s, UBool strict) {
|
||||
}
|
||||
|
||||
UBool
|
||||
FormatParser::isQuoteLiteral(const UnicodeString& s) const {
|
||||
FormatParser::isQuoteLiteral(const UnicodeString& s) {
|
||||
return (UBool)(s.charAt(0)==SINGLE_QUOTE);
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
*******************************************************************************
|
||||
* Copyright (C) 2007-2014, International Business Machines Corporation and
|
||||
* Copyright (C) 2007-2015, International Business Machines Corporation and
|
||||
* others. All Rights Reserved. *
|
||||
*******************************************************************************
|
||||
*
|
||||
@ -145,12 +145,11 @@ public:
|
||||
FormatParser();
|
||||
virtual ~FormatParser();
|
||||
void set(const UnicodeString& patternString);
|
||||
UBool isQuoteLiteral(const UnicodeString& s) const;
|
||||
void getQuoteLiteral(UnicodeString& quote, int32_t *itemIndex);
|
||||
int32_t getCanonicalIndex(const UnicodeString& s) { return getCanonicalIndex(s, TRUE); }
|
||||
int32_t getCanonicalIndex(const UnicodeString& s, UBool strict);
|
||||
UBool isPatternSeparator(UnicodeString& field);
|
||||
void setFilter(UErrorCode &status);
|
||||
static UBool isQuoteLiteral(const UnicodeString& s);
|
||||
static int32_t getCanonicalIndex(const UnicodeString& s) { return getCanonicalIndex(s, TRUE); }
|
||||
static int32_t getCanonicalIndex(const UnicodeString& s, UBool strict);
|
||||
|
||||
private:
|
||||
typedef enum TokenStatus {
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
*******************************************************************************
|
||||
*
|
||||
* Copyright (C) 2009-2012, International Business Machines
|
||||
* Copyright (C) 2009-2015, International Business Machines
|
||||
* Corporation and others. All Rights Reserved.
|
||||
*
|
||||
*******************************************************************************
|
||||
@ -82,7 +82,7 @@ udatpg_getBestPatternWithOptions(UDateTimePatternGenerator *dtpg,
|
||||
}
|
||||
|
||||
U_CAPI int32_t U_EXPORT2
|
||||
udatpg_getSkeleton(UDateTimePatternGenerator *dtpg,
|
||||
udatpg_getSkeleton(UDateTimePatternGenerator * /* dtpg */,
|
||||
const UChar *pattern, int32_t length,
|
||||
UChar *skeleton, int32_t capacity,
|
||||
UErrorCode *pErrorCode) {
|
||||
@ -94,12 +94,13 @@ udatpg_getSkeleton(UDateTimePatternGenerator *dtpg,
|
||||
return 0;
|
||||
}
|
||||
UnicodeString patternString((UBool)(length<0), pattern, length);
|
||||
UnicodeString result=((DateTimePatternGenerator *)dtpg)->getSkeleton(patternString, *pErrorCode);
|
||||
UnicodeString result=DateTimePatternGenerator::staticGetSkeleton(
|
||||
patternString, *pErrorCode);
|
||||
return result.extract(skeleton, capacity, *pErrorCode);
|
||||
}
|
||||
|
||||
U_CAPI int32_t U_EXPORT2
|
||||
udatpg_getBaseSkeleton(UDateTimePatternGenerator *dtpg,
|
||||
udatpg_getBaseSkeleton(UDateTimePatternGenerator * /* dtpg */,
|
||||
const UChar *pattern, int32_t length,
|
||||
UChar *skeleton, int32_t capacity,
|
||||
UErrorCode *pErrorCode) {
|
||||
@ -111,7 +112,8 @@ udatpg_getBaseSkeleton(UDateTimePatternGenerator *dtpg,
|
||||
return 0;
|
||||
}
|
||||
UnicodeString patternString((UBool)(length<0), pattern, length);
|
||||
UnicodeString result=((DateTimePatternGenerator *)dtpg)->getBaseSkeleton(patternString, *pErrorCode);
|
||||
UnicodeString result=DateTimePatternGenerator::staticGetBaseSkeleton(
|
||||
patternString, *pErrorCode);
|
||||
return result.extract(skeleton, capacity, *pErrorCode);
|
||||
}
|
||||
|
||||
|
@ -124,9 +124,25 @@ public:
|
||||
* @param status Output param set to success/failure code on exit,
|
||||
* which must not indicate a failure before the function call.
|
||||
* @return skeleton such as "MMMdd"
|
||||
* @draft ICU 56
|
||||
*/
|
||||
static UnicodeString staticGetSkeleton(const UnicodeString& pattern, UErrorCode& status);
|
||||
|
||||
/**
|
||||
* Utility to return a unique skeleton from a given pattern. For example,
|
||||
* both "MMM-dd" and "dd/MMM" produce the skeleton "MMMdd".
|
||||
* getSkeleton() works exactly like staticGetSkeleton().
|
||||
* Use staticGetSkeleton() instead of getSkeleton().
|
||||
*
|
||||
* @param pattern Input pattern, such as "dd/MMM"
|
||||
* @param status Output param set to success/failure code on exit,
|
||||
* which must not indicate a failure before the function call.
|
||||
* @return skeleton such as "MMMdd"
|
||||
* @stable ICU 3.8
|
||||
*/
|
||||
UnicodeString getSkeleton(const UnicodeString& pattern, UErrorCode& status);
|
||||
UnicodeString getSkeleton(const UnicodeString& pattern, UErrorCode& status) {
|
||||
return staticGetSkeleton(pattern, status);
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility to return a unique base skeleton from a given pattern. This is
|
||||
@ -138,10 +154,29 @@ public:
|
||||
* @param pattern Input pattern, such as "dd/MMM"
|
||||
* @param status Output param set to success/failure code on exit,
|
||||
* which must not indicate a failure before the function call.
|
||||
* @return base skeleton, such as "Md"
|
||||
* @return base skeleton, such as "MMMd"
|
||||
* @draft ICU 56
|
||||
*/
|
||||
static UnicodeString staticGetBaseSkeleton(const UnicodeString& pattern, UErrorCode& status);
|
||||
|
||||
/**
|
||||
* Utility to return a unique base skeleton from a given pattern. This is
|
||||
* the same as the skeleton, except that differences in length are minimized
|
||||
* so as to only preserve the difference between string and numeric form. So
|
||||
* for example, both "MMM-dd" and "d/MMM" produce the skeleton "MMMd"
|
||||
* (notice the single d).
|
||||
* getBaseSkeleton() works exactly like staticGetBaseSkeleton().
|
||||
* Use staticGetBaseSkeleton() instead of getBaseSkeleton().
|
||||
*
|
||||
* @param pattern Input pattern, such as "dd/MMM"
|
||||
* @param status Output param set to success/failure code on exit,
|
||||
* which must not indicate a failure before the function call.
|
||||
* @return base skeleton, such as "MMMd"
|
||||
* @stable ICU 3.8
|
||||
*/
|
||||
UnicodeString getBaseSkeleton(const UnicodeString& pattern, UErrorCode& status);
|
||||
UnicodeString getBaseSkeleton(const UnicodeString& pattern, UErrorCode& status) {
|
||||
return staticGetBaseSkeleton(pattern, status);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a pattern to the generator. If the pattern has the same skeleton as
|
||||
|
@ -260,6 +260,7 @@ udatpg_getBestPatternWithOptions(UDateTimePatternGenerator *dtpg,
|
||||
* but this function cannot be used concurrently on a single generator object.
|
||||
*
|
||||
* @param dtpg a pointer to UDateTimePatternGenerator.
|
||||
* This parameter is no longer used. Callers may pass NULL.
|
||||
* @param pattern input pattern, such as "dd/MMM".
|
||||
* @param length the length of pattern.
|
||||
* @param skeleton such as "MMMdd"
|
||||
@ -270,7 +271,7 @@ udatpg_getBestPatternWithOptions(UDateTimePatternGenerator *dtpg,
|
||||
* @stable ICU 3.8
|
||||
*/
|
||||
U_STABLE int32_t U_EXPORT2
|
||||
udatpg_getSkeleton(UDateTimePatternGenerator *dtpg,
|
||||
udatpg_getSkeleton(UDateTimePatternGenerator *unusedDtpg,
|
||||
const UChar *pattern, int32_t length,
|
||||
UChar *skeleton, int32_t capacity,
|
||||
UErrorCode *pErrorCode);
|
||||
@ -289,6 +290,7 @@ udatpg_getSkeleton(UDateTimePatternGenerator *dtpg,
|
||||
* but this function cannot be used concurrently on a single generator object.
|
||||
*
|
||||
* @param dtpg a pointer to UDateTimePatternGenerator.
|
||||
* This parameter is no longer used. Callers may pass NULL.
|
||||
* @param pattern input pattern, such as "dd/MMM".
|
||||
* @param length the length of pattern.
|
||||
* @param baseSkeleton such as "Md"
|
||||
@ -299,7 +301,7 @@ udatpg_getSkeleton(UDateTimePatternGenerator *dtpg,
|
||||
* @stable ICU 3.8
|
||||
*/
|
||||
U_STABLE int32_t U_EXPORT2
|
||||
udatpg_getBaseSkeleton(UDateTimePatternGenerator *dtpg,
|
||||
udatpg_getBaseSkeleton(UDateTimePatternGenerator *unusedDtpg,
|
||||
const UChar *pattern, int32_t length,
|
||||
UChar *baseSkeleton, int32_t capacity,
|
||||
UErrorCode *pErrorCode);
|
||||
|
Loading…
Reference in New Issue
Block a user