1 /* GENERATED SOURCE. DO NOT MODIFY. */ 2 // © 2017 and later: Unicode, Inc. and others. 3 // License & terms of use: http://www.unicode.org/copyright.html#License 4 package ohos.global.icu.impl.locale; 5 6 import java.util.Objects; 7 8 /** 9 * @hide exposed on OHOS 10 */ 11 public final class LSR { 12 public static final int REGION_INDEX_LIMIT = 1001 + 26 * 26; 13 14 public static final int EXPLICIT_LSR = 7; 15 public static final int EXPLICIT_LANGUAGE = 4; 16 public static final int EXPLICIT_SCRIPT = 2; 17 public static final int EXPLICIT_REGION = 1; 18 public static final int IMPLICIT_LSR = 0; 19 public static final int DONT_CARE_FLAGS = 0; 20 21 public static final boolean DEBUG_OUTPUT = false; 22 23 public final String language; 24 public final String script; 25 public final String region; 26 /** Index for region, negative if ill-formed. @see indexForRegion */ 27 final int regionIndex; 28 public final int flags; 29 LSR(String language, String script, String region, int flags)30 public LSR(String language, String script, String region, int flags) { 31 this.language = language; 32 this.script = script; 33 this.region = region; 34 regionIndex = indexForRegion(region); 35 this.flags = flags; 36 } 37 38 /** 39 * Returns a positive index (>0) for a well-formed region code. 40 * Do not rely on a particular region->index mapping; it may change. 41 * Returns 0 for ill-formed strings. 42 */ indexForRegion(String region)43 public static final int indexForRegion(String region) { 44 if (region.length() == 2) { 45 int a = region.charAt(0) - 'A'; 46 if (a < 0 || 25 < a) { return 0; } 47 int b = region.charAt(1) - 'A'; 48 if (b < 0 || 25 < b) { return 0; } 49 return 26 * a + b + 1001; 50 } else if (region.length() == 3) { 51 int a = region.charAt(0) - '0'; 52 if (a < 0 || 9 < a) { return 0; } 53 int b = region.charAt(1) - '0'; 54 if (b < 0 || 9 < b) { return 0; } 55 int c = region.charAt(2) - '0'; 56 if (c < 0 || 9 < c) { return 0; } 57 return (10 * a + b) * 10 + c + 1; 58 } 59 return 0; 60 } 61 62 @Override toString()63 public String toString() { 64 StringBuilder result = new StringBuilder(language); 65 if (!script.isEmpty()) { 66 result.append('-').append(script); 67 } 68 if (!region.isEmpty()) { 69 result.append('-').append(region); 70 } 71 return result.toString(); 72 } 73 isEquivalentTo(LSR other)74 public boolean isEquivalentTo(LSR other) { 75 return language.equals(other.language) 76 && script.equals(other.script) 77 && region.equals(other.region); 78 } 79 80 @Override equals(Object obj)81 public boolean equals(Object obj) { 82 LSR other; 83 return this == obj || 84 (obj != null 85 && obj.getClass() == this.getClass() 86 && language.equals((other = (LSR) obj).language) 87 && script.equals(other.script) 88 && region.equals(other.region) 89 && flags == other.flags); 90 } 91 92 @Override hashCode()93 public int hashCode() { 94 return Objects.hash(language, script, region, flags); 95 } 96 } 97