/* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #ifndef intl_components_DateTimePatternGenerator_h_ #define intl_components_DateTimePatternGenerator_h_
/** * The DateTimePatternGenerator is the machinery used to work with DateTime * pattern manipulation. It is expensive to create one, and so generally it is * created once and then cached. It may be needed to be passed in as an argument * for different mozilla::intl APIs.
*/ class DateTimePatternGenerator final { public: explicit DateTimePatternGenerator(UDateTimePatternGenerator* aGenerator)
: mGenerator(aGenerator) {
MOZ_ASSERT(aGenerator);
};
// Transfer ownership of the UDateTimePatternGenerator in the move // constructor.
DateTimePatternGenerator(DateTimePatternGenerator&& other) noexcept;
// Transfer ownership of the UEnumeration in the move assignment operator.
DateTimePatternGenerator& operator=(
DateTimePatternGenerator&& other) noexcept;
enumclass PatternMatchOption { /** * Adjust the 'hour' field in the resolved pattern to match the input * skeleton width.
*/
HourField,
/** * Adjust the 'minute' field in the resolved pattern to match the input * skeleton width.
*/
MinuteField,
/** * Adjust the 'second' field in the resolved pattern to match the input * skeleton width.
*/
SecondField,
};
/** * Given a skeleton (a string with unordered datetime fields), get a best * pattern that will fit for that locale. This pattern will be filled into the * buffer. e.g. The skeleton "yMd" would return the pattern "M/d/y" for en-US, * or "dd/MM/y" for en-GB.
*/ template <typename B>
ICUResult GetBestPattern(Span<const char16_t> aSkeleton, B& aBuffer,
EnumSet<PatternMatchOption> options = {}) { return FillBufferWithICUCall(
aBuffer, [&](UChar* target, int32_t length, UErrorCode* status) { return udatpg_getBestPatternWithOptions(
mGenerator.GetMut(), aSkeleton.data(), static_cast<int32_t>(aSkeleton.Length()),
toUDateTimePatternMatchOptions(options), target, length, status);
});
}
/** * Get a skeleton (a string with unordered datetime fields) from a pattern. * For example, both "MMM-dd" and "dd/MMM" produce the skeleton "MMMdd".
*/ template <typename B> static ICUResult GetSkeleton(Span<const char16_t> aPattern, B& aBuffer) { // At one time udatpg_getSkeleton required a UDateTimePatternGenerator*, but // now it is valid to pass in a nullptr. return FillBufferWithICUCall(
aBuffer, [&](UChar* target, int32_t length, UErrorCode* status) { return udatpg_getSkeleton(nullptr, aPattern.data(), static_cast<int32_t>(aPattern.Length()),
target, length, status);
});
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.