File: Lang.java

package info (click to toggle)
lib-xt-java 0.19990725-1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 1,224 kB
  • ctags: 2,133
  • sloc: java: 9,665; makefile: 54; xml: 28
file content (25 lines) | stat: -rw-r--r-- 642 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package com.jclark.xsl.tr;

import java.util.Locale;

/* Convert the value of an xml:lang attribute to a Locale. */

class Lang {
  /* lang may be null. */
  static Locale getLocale(String lang) {
    // FIXME handle non ISO 639 codes
    if (lang == null || lang.length() < 2 || lang.charAt(1) == '-')
      return null;
    return new Locale(lang.substring(0, 2), getCountryCode(lang));
  }

  static private String getCountryCode(String lang) {
    int len = lang.length();
    if (len < 5
	|| (len > 5 && lang.charAt(5) != '-')
	|| lang.charAt(4) == '-')
      return "";
    return lang.substring(3, 5);
  }
	
}