private static String createTagString ( String lang , String script , String region , String trailing , String alternateTags ) { LocaleIDParser parser = null ; boolean regionAppended = false ; StringBuilder tag = new StringBuilder ( ) ; if ( ! isEmptyString ( lang ) ) { appendTag ( lang , tag ) ; } else if ( isEmptyString ( alternateTags ) ) { /* * Append the value for an unknown language, if * we found no language. */ appendTag ( UNDEFINED_LANGUAGE , tag ) ; } else { parser = new LocaleIDParser ( alternateTags ) ; String alternateLang = parser . getLanguage ( ) ; /* * Append the value for an unknown language, if * we found no language. */ appendTag ( ! isEmptyString ( alternateLang ) ? alternateLang : UNDEFINED_LANGUAGE , tag ) ; } if ( ! isEmptyString ( script ) ) { appendTag ( script , tag ) ; } else if ( ! isEmptyString ( alternateTags ) ) { /* * Parse the alternateTags string for the script. */ if ( parser == null ) { parser = new LocaleIDParser ( alternateTags ) ; } String alternateScript = parser . getScript ( ) ; if ( ! isEmptyString ( alternateScript ) ) { appendTag ( alternateScript , tag ) ; } } if ( ! isEmptyString ( region ) ) { appendTag ( region , tag ) ; regionAppended = true ; } else if ( ! isEmptyString ( alternateTags ) ) { /* * Parse the alternateTags string for the region. */ if ( parser == null ) { parser = new LocaleIDParser ( alternateTags ) ; } String alternateRegion = parser . getCountry ( ) ; if ( ! isEmptyString ( alternateRegion ) ) { appendTag ( alternateRegion , tag ) ; regionAppended = true ; } } if ( trailing != null && trailing . length ( ) > 1 ) { /* * The current ICU format expects two underscores * will separate the variant from the preceeding * parts of the tag, if there is no region. */ int separators = 0 ; if ( trailing . charAt ( 0 ) == UNDERSCORE ) { if ( trailing . charAt ( 1 ) == UNDERSCORE ) { separators = 2 ; } } else { separators = 1 ; } if ( regionAppended ) { /* * If we appended a region, we may need to strip * the extra separator from the variant portion. */ if ( separators == 2 ) { tag . append ( trailing . substring ( 1 ) ) ; } else { tag . append ( trailing ) ; } } else { /* * If we did not append a region, we may need to add * an extra separator to the variant portion. */ if ( separators == 1 ) { tag . append ( UNDERSCORE ) ; } tag . append ( trailing ) ; } } return tag . toString ( ) ; }
Create a tag string from the supplied parameters . The lang script and region parameters may be null references .