diff options
author | Victor Chang <vichang@google.com> | 2021-05-04 16:26:40 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2021-05-04 16:26:40 +0000 |
commit | 6d9823b87c7138330326a0b6c55198c99ff23068 (patch) | |
tree | 2592ba5e76cee10499b2b9c073e4a97843e480c7 | |
parent | d905447c9d562de54fca68f06e35365e7b1a581f (diff) | |
parent | 0793dc321ae731829f08c2ba6bafd8905c8d0e89 (diff) | |
download | icu-6d9823b87c7138330326a0b6c55198c99ff23068.tar.gz |
Rename ExtendedTimeZoneNames.matchName method am: 0793dc321a
Original change: https://android-review.googlesource.com/c/platform/external/icu/+/1695658
Change-Id: I67abeaed0e195e41695a934e9c14286ba90ffb81
-rw-r--r-- | android_icu4j/api/intra/current.txt | 7 | ||||
-rw-r--r-- | android_icu4j/libcore_bridge/src/java/com/android/icu/text/ExtendedTimeZoneNames.java | 80 |
2 files changed, 87 insertions, 0 deletions
diff --git a/android_icu4j/api/intra/current.txt b/android_icu4j/api/intra/current.txt index d3cc4cc87..317a84368 100644 --- a/android_icu4j/api/intra/current.txt +++ b/android_icu4j/api/intra/current.txt @@ -74,6 +74,13 @@ package com.android.icu.text { method @NonNull public static com.android.icu.text.ExtendedTimeZoneNames getInstance(@NonNull android.icu.util.ULocale); method @NonNull public android.icu.text.TimeZoneNames getTimeZoneNames(); method @Nullable public com.android.icu.text.ExtendedTimeZoneNames.MatchedTimeZone matchName(@NonNull CharSequence, int, @NonNull String); + method @Nullable public com.android.icu.text.ExtendedTimeZoneNames.Match matchNameToBeRenamed(@NonNull CharSequence, int, @NonNull String); + } + + public static final class ExtendedTimeZoneNames.Match { + method public int getMatchLength(); + method @NonNull public String getTzId(); + method public boolean isDst(); } public static class ExtendedTimeZoneNames.MatchedTimeZone { diff --git a/android_icu4j/libcore_bridge/src/java/com/android/icu/text/ExtendedTimeZoneNames.java b/android_icu4j/libcore_bridge/src/java/com/android/icu/text/ExtendedTimeZoneNames.java index 57c7367bc..37c60635f 100644 --- a/android_icu4j/libcore_bridge/src/java/com/android/icu/text/ExtendedTimeZoneNames.java +++ b/android_icu4j/libcore_bridge/src/java/com/android/icu/text/ExtendedTimeZoneNames.java @@ -54,7 +54,55 @@ public class ExtendedTimeZoneNames { private final ULocale locale; private final TimeZoneNames timeZoneNames; +/** + * A class representing the return result of {@link #matchName(CharSequence, int, String)} + * + * @hide + */ + @IntraCoreApi + public static final class Match { + + private final int matchLength; + private final @NonNull String tzId; + private final boolean isDst; + private Match(int matchLength, @NonNull String tzId, boolean isDst) { + this.matchLength = matchLength; + this.tzId = tzId; + this.isDst = isDst; + } + + /** + * Returns the number of chars in the matched name. + * + * @hide + */ + @IntraCoreApi + public int getMatchLength() { + return matchLength; + } + + /** + * Returns the time zone id associated with the matched name. + * + * @hide + */ + @IntraCoreApi + public @NonNull String getTzId() { + return tzId; + } + + /** + * Returns true if the matched name is a display name for daylight saving time. For example, + * returns true for "Pacific Daylight Time", but false for "Pacific Standard Time". + * + * @hide + */ + @IntraCoreApi + public boolean isDst() { + return isDst; + } + } /** * A class representing the return result of {@link #matchName(CharSequence, int, String)} * @@ -131,6 +179,38 @@ public class ExtendedTimeZoneNames { } /** + * Returns {@link Match} if a time zone name in ICU can be matched against the input + * CharSequence {@code s}. + * The best match is found by the following principles: + * <ul> + * <li>Length of the matched name. Longest name matched to the given {@code s} has the + * highest priority.</li> + * <li>The current time zone and meta zones possible in the current country have higher + * priority than other zones.</li> + * <li>If only meta zones are matched, the country/region in the locale is used to select + * a reference time zone. For example, if the name is "Pacific Standard Time" and the country + * is US, America/Los_Angeles is returned.</li> + * </ul> + * + * @param text input string to be matched against time zone names in ICU + * @param start the begin index in the CharSequence {@code s} + * @param currentTzId the time zone ID prioritized to be matched if multiple time zone IDs can + * be matched and this is one of the matched IDs. + * @return null if no match is found + * + * @hide + */ + @IntraCoreApi + public @Nullable Match matchNameToBeRenamed(@NonNull CharSequence text, int start, + @NonNull String currentTzId) { + MatchedTimeZone matchedTimeZone = matchName(text, start, currentTzId); + if (matchedTimeZone == null) { + return null; + } + return new Match(matchedTimeZone.matchLength, matchedTimeZone.tzId, matchedTimeZone.isDst); + } + + /** * Returns {@link MatchedTimeZone} if a time zone name in ICU can be matched against the input * CharSequence {@code s}. * The best match is found by the following principles: |