@@ -114,7 +114,20 @@ uscript_getCode(const char* nameOrAbbrOrLocale,
114114 }
115115
116116 triedCode = false ;
117- if (uprv_strchr (nameOrAbbrOrLocale, ' -' )==nullptr && uprv_strchr (nameOrAbbrOrLocale, ' _' )==nullptr ){
117+ const char * lastSepPtr = uprv_strrchr (nameOrAbbrOrLocale, ' -' );
118+ if (lastSepPtr==nullptr ) {
119+ lastSepPtr = uprv_strrchr (nameOrAbbrOrLocale, ' _' );
120+ }
121+ // Favor interpretation of nameOrAbbrOrLocale as a script alias if either
122+ // 1. nameOrAbbrOrLocale does not contain -/_. Handles Han, Mro, Nko, etc.
123+ // 2. The last instance of -/_ is at offset 3, and the portion after that is
124+ // longer than 4 characters (i.e. not a script or region code). This handles
125+ // Old_Hungarian, Old_Italic, etc. ("old" is a valid language code)
126+ // 3. The last instance of -/_ is at offset 7, and the portion after that is
127+ // 3 characters. This handles New_Tai_Lue ("new" is a valid language code).
128+ if (lastSepPtr==nullptr
129+ || (lastSepPtr-nameOrAbbrOrLocale == 3 && uprv_strlen (nameOrAbbrOrLocale) > 8 )
130+ || (lastSepPtr-nameOrAbbrOrLocale == 7 && uprv_strlen (nameOrAbbrOrLocale) == 11 ) ) {
118131 /* try long and abbreviated script names first */
119132 UScriptCode code = (UScriptCode) u_getPropertyValueEnum (UCHAR_SCRIPT, nameOrAbbrOrLocale);
120133 if (code!=USCRIPT_INVALID_CODE) {
0 commit comments