Tabnine Logo
LangTag
Code IndexAdd Tabnine to your IDE (free)

How to use
LangTag
in
com.nimbusds.langtag

Best Java code snippets using com.nimbusds.langtag.LangTag (Showing top 20 results out of 315)

origin: com.nimbusds/lang-tag

/**
 * Parses a language tag array from the specified string values.
 *
 * @param values The string values. May be {@code null}.
 *
 * @return The language tag array, or {@code null} if the parsed string
 *         array is null.
 *
 * @throws LangTagException If parsing failed.
 */
public static LangTag[] parseLangTagArray(final String ... values)
  throws LangTagException {
  if (values == null)
    return null;
  LangTag[] out = new LangTag[values.length];
  for (int i=0; i < values.length; i++) {
    out[i] = LangTag.parse(values[i]);
  }
  return out;
}
origin: com.nimbusds/lang-tag

/**
 * Overrides {@code Object.hashCode()}.
 *
 * @return The object hash code.
 */
@Override
public int hashCode() {

  return toString().hashCode();
}

origin: com.nimbusds/lang-tag

/**
 * Sets the region.
 *
 * <p>See RFC 5646 section 2.2.4.
 *
 * @param region The region, as a two-letter ISO 3166-1 code or a three-
 *               digit UN M.49 code. {@code null} if not defined.
 *
 * @throws LangTagException If the region syntax is invalid.
 */
public void setRegion(final String region)
  throws LangTagException {
  
  if (region == null) {
    this.region = null;
    return;
  }
  
  ensureMaxLength(region);
  
  if (! isRegion(region))
    throw new LangTagException("Invalid region subtag: Must be a two-letter ISO 3166-1 code or a three-digit UN M.49 code");

  this.region = region.toUpperCase();
}

origin: com.nimbusds/lang-tag

/**
 * Sets the private use.
 *
 * <p>See RFC 5646 section 2.2.7.
 *
 * @param privateUse The private use. {@code null} if not defined.
 *
 * @throws LangTagException If the extension syntax is invalid.
 */
public void setPrivateUse(final String privateUse)
  throws LangTagException {

  if (privateUse == null) {
    this.privateUse = null;
    return;
  }
  
  ensureMaxLength(privateUse);
  
  if (! isPrivateUse(privateUse))
    throw new LangTagException("Invalid private use subtag");

  this.privateUse = privateUse.toLowerCase();
}

origin: com.nimbusds/lang-tag

List<String> extLangSubtags = new LinkedList<String>();
if (isPrimaryLanguage(subtags[0]))
  primaryLang = subtags[pos++];
while (pos < subtags.length && isExtendedLanguageSubtag(subtags[pos]))
  extLangSubtags.add(subtags[pos++]);
LangTag langTag = new LangTag(primaryLang, extLangSubtags.toArray(new String[]{}));
if (pos < subtags.length && isScript(subtags[pos]))
  langTag.setScript(subtags[pos++]);
if (pos < subtags.length && isRegion(subtags[pos]))
  langTag.setRegion(subtags[pos++]);
while (pos < subtags.length && isVariant(subtags[pos]))
  variantSubtags.add(subtags[pos++]);
  langTag.setVariants(variantSubtags.toArray(new String[]{}));
while (pos < subtags.length && isExtensionSingleton(subtags[pos])) {
  langTag.setExtensions(extSubtags.toArray(new String[]{}));
    throw new LangTagException("Invalid private use subtag");
  langTag.setPrivateUse("x-" + subtags[pos++]);
origin: com.nimbusds/lang-tag

/**
 * Sets the extended language subtags.
 *
 * <p>See RFC 5646 section 2.2.2.
 *
 * @param languageSubtags The extended language subtags, as three-letter
 *                        ISO 639-3 codes. {@code null} if none.
 */
private void setExtendedLanguageSubtags(final String... languageSubtags)
  throws LangTagException {
  
  if (languageSubtags == null || languageSubtags.length == 0) {
    this.languageSubtags = null;
    return;
  }
  this.languageSubtags = new String[languageSubtags.length];
  
  for (int i=0; i < languageSubtags.length; i++) {
  
    ensureMaxLength(languageSubtags[i]);
    if (! isExtendedLanguageSubtag(languageSubtags[i]))
      throw new LangTagException("Invalid extended language subtag: Must be a three-letter ISO 639-3 code");
    this.languageSubtags[i] = languageSubtags[i].toLowerCase();
  }
}

origin: com.nimbusds/lang-tag

/**
 * Sets the primary language subtag.
 *
 * <p>See RFC 5646 section 2.2.1.
 *
 * @param primaryLanguage The primary language, as the shortest two or
 *                        three-letter ISO 639 code. May be 
 *                        {@code null}.
 *
 * @throws LangTagException If the primary language syntax is invalid.
 */
private void setPrimaryLanguage(final String primaryLanguage)
  throws LangTagException {
  
  if (primaryLanguage == null) {
    this.primaryLanguage = null;
    return;
  }
  
  ensureMaxLength(primaryLanguage);
  
  if (! isPrimaryLanguage(primaryLanguage))
    throw new LangTagException("Invalid primary language subtag: Must be a two or three-letter ISO 639 code");
  
  this.primaryLanguage = primaryLanguage.toLowerCase();
}

origin: com.nimbusds/lang-tag

/**
 * Sets the extensions.
 *
 * <p>See RFC 5646 section 2.2.6.
 *
 * @param extensions The extensions. {@code null} if not defined.
 *
 * @throws LangTagException If the extension syntax is invalid.
 */
public void setExtensions(final String... extensions)
  throws LangTagException {
  
  if (extensions == null || extensions.length == 0) {
    this.extensions = null;
    return;
  }

  this.extensions = new String[extensions.length];
  
  for (int i=0; i < extensions.length; i++) {
  
    ensureMaxLength(extensions[i]);
    if (! isExtension(extensions[i]))
      throw new LangTagException("Invalid extension subtag");
    this.extensions[i] = extensions[i].toLowerCase();
  }
}

origin: com.nimbusds/lang-tag

/**
 * Sets the variants.
 *
 * <p>See RFC 5646 section 2.2.5.
 *
 * @param variants The variants. {@code null} if not defined.
 *
 * @throws LangTagException If the variant syntax is invalid.
 */
public void setVariants(final String... variants)
  throws LangTagException {
  
  if (variants == null || variants.length == 0) {
    this.variants = null;
    return;
  }

  this.variants = new String[variants.length];
  
  for (int i=0; i < variants.length; i++) {
  
    ensureMaxLength(variants[i]);
    if (! isVariant(variants[i]))
      throw new LangTagException("Invalid variant subtag");
    this.variants[i] = variants[i].toLowerCase();
  }
}

origin: com.nimbusds/lang-tag

/**
 * Sets the script.
 *
 * <p>See RFC 5646 section 2.2.3.
 *
 * @param script The script, as a four-letter ISO 15924 code. 
 *               {@code null} if not defined.
 *
 * @throws LangTagException If the script syntax is invalid.
 */
public void setScript(final String script)
  throws LangTagException {

  if (script == null) {
    this.script = null;
    return;
  }
  
  ensureMaxLength(script);
  
  if (! isScript(script))
    throw new LangTagException("Invalid script subtag: Must be a four-letter ISO 15924 code");
  
  this.script = script.substring(0, 1).toUpperCase() + 
         script.substring(1).toLowerCase();
}

origin: com.nimbusds/lang-tag

@Override
public String toString() {
  StringBuilder sb = new StringBuilder(getLanguage());
origin: com.nimbusds/lang-tag

/**
 * Parses a language tag list from the specified string values.
 *
 * @param values The string values. May be {@code null}.
 *
 * @return The language tag list, or {@code null} if the parsed string
 *         array is null.
 *
 * @throws LangTagException If parsing failed.
 */
public static List<LangTag> parseLangTagList(final String ... values)
  throws LangTagException {
  if (values == null)
    return null;
  List<LangTag> out = new ArrayList<LangTag>(values.length);
  for (String s: values) {
    out.add(LangTag.parse(s));
  }
  return out;
}
origin: com.nimbusds/lang-tag

/**
 * Returns a string array representation of the specified language tags
 * collection.
 *
 * @param langTags The language tags list. May be {@code null}.
 *
 * @return The string list, or {@code null} if the original list is
 *         {@code null}.
 */
public static String[] toStringArray(final Collection<LangTag> langTags) {
  if (langTags == null)
    return null;
  String[] out = new String[langTags.size()];
  int i=0;
  for (LangTag lt: langTags) {
    out[i++] = lt.toString();
  }
  return out;
}
origin: com.nimbusds/lang-tag

/**
 * Parses a language tag list from the specified string collection.
 *
 * @param collection The string collection. May be {@code null}.
 *
 * @return The language tag list, or {@code null} if the parsed string
 *         collection is null.
 *
 * @throws LangTagException If parsing failed.
 */
public static List<LangTag> parseLangTagList(final Collection<String> collection)
  throws LangTagException {
  if (collection == null)
    return null;
  List<LangTag> out = new ArrayList<LangTag>(collection.size());
  for (String s: collection) {
    out.add(LangTag.parse(s));
  }
  return out;
}
origin: com.nimbusds/lang-tag

/**
 * Overrides {@code Object.equals()}.
 *
 * @param object The object to compare to.
 *
 * @return {@code true} if the objects have the same value, otherwise
 *         {@code false}.
 */
@Override
public boolean equals(Object object) {

  return object != null &&
      object instanceof LangTag && 
      this.toString().equals(object.toString());
}

origin: com.nimbusds/lang-tag

/**
 * Extracts the language tag, if any is found, from the specified
 * string.
 *
 * <p>Example:
 *
 * <pre>
 * "name#bg-BG" => "bg-BG"
 * "name#"      => null
 * "name"       => null
 * </pre>
 *
 * @param s The string. May contain a language tag. May be
 *          {@code null}.
 *
 * @return The extracted language tag, {@code null} if not found.
 *
 * @throws LangTagException If the language tag is invalid.
 */
public static LangTag extract(final String s)
  throws LangTagException {
  if (s == null)
    return null;
  final int pos = s.indexOf('#');
  if (pos < 0 || s.length() < pos + 1)
    return null;
  return LangTag.parse(s.substring(pos + 1));
}
origin: com.nimbusds/lang-tag

/**
 * Returns a string list representation of the specified language tags
 * collection.
 *
 * @param langTags The language tags list. May be {@code null}.
 *
 * @return The string list, or {@code null} if the original list is
 *         {@code null}.
 */
public static List<String> toStringList(final Collection<LangTag> langTags) {
  if (langTags == null)
    return null;
  List<String> out = new ArrayList<String>(langTags.size());
  for (LangTag lt: langTags) {
    out.add(lt.toString());
  }
  return out;
}
origin: com.nimbusds/lang-tag

langTag = LangTag.parse(parts[1]);
origin: com.nimbusds/common

ldapAttributeName += ";lang-" + langTag.toString();
origin: com.nimbusds/common

langTag = LangTag.parse(opt.substring("lang-".length()));
break;
com.nimbusds.langtagLangTag

Javadoc

Language tag according to RFC 5646.

Supports normal language tags. Special private language tags beginning with "x" and grandfathered tags beginning with "i" are not supported.

To construct a new language tag from scratch:

 
// English as used in the United States 
LangTag tag = new LangTag("en"); 
tag.setRegion("US"); 
// Returns "en-US" 
tag.toString(); 

To parse a language tag:

 
// Chinese, Mandarin, Simplified script, as used in China 
LangTag tag = LangTag.parse("zh-cmn-Hans-CN"); 
// Returns "zh" 
tag.getPrimaryLanguage(); 
// Returns "cmn" 
tag.getExtendedLanguageSubtags()[0]; 
// Returns "zh-cmn" 
tag.getLanguage(); 
// Returns "Hans" 
tag.getScript(); 
// Returns "CN" 
tag.getRegion(); 

See RFC 5646.

Most used methods

  • parse
    Parses the specified string representation of a language tag.
  • toString
  • <init>
    Creates a new extended language tag.Use for extended language tags such as "zh-cmn" (Mandarin Chines
  • ensureMaxLength
    Ensures the specified subtag has a valid maximum length of eight characters.
  • getLanguage
  • isExtendedLanguageSubtag
    Checks if the specified string has a valid extended language subtag syntax.
  • isExtension
    Checks if the specified string has a valid extension subtag syntax.
  • isExtensionSingleton
    Checks if the specified string has a valid extension singleton syntax.
  • isPrimaryLanguage
    Checks if the specified string has a valid primary language subtag syntax.
  • isPrivateUse
    Checks if the specified string has a valid private use subtag syntax.
  • isRegion
    Checks if the specified string has a valid region subtag syntax.
  • isScript
    Checks if the specified string has a valid script subtag syntax.
  • isRegion,
  • isScript,
  • isVariant,
  • setExtendedLanguageSubtags,
  • setExtensions,
  • setPrimaryLanguage,
  • setPrivateUse,
  • setRegion,
  • setScript,
  • setVariants

Popular in Java

  • Updating database using SQL prepared statement
  • putExtra (Intent)
  • notifyDataSetChanged (ArrayAdapter)
  • scheduleAtFixedRate (ScheduledExecutorService)
  • URL (java.net)
    A Uniform Resource Locator that identifies the location of an Internet resource as specified by RFC
  • Connection (java.sql)
    A connection represents a link from a Java application to a database. All SQL statements and results
  • DateFormat (java.text)
    Formats or parses dates and times.This class provides factories for obtaining instances configured f
  • Annotation (javassist.bytecode.annotation)
    The annotation structure.An instance of this class is returned bygetAnnotations() in AnnotationsAttr
  • Cipher (javax.crypto)
    This class provides access to implementations of cryptographic ciphers for encryption and decryption
  • JList (javax.swing)
  • From CI to AI: The AI layer in your organization
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now