Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4239494

RFE: java.util.Locale should have a constructor that takes a locale string

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Won't Fix
    • Icon: P4 P4
    • None
    • 1.1.6, 1.2.2
    • core-libs



      Name: vi73552 Date: 05/19/99


      The java.util.Locale class should have a constructor that takes a string representation of a Locale (The string representation is language underscore country underscore variant)

      When I have a string representation I have to parse it and pass each part separately.
      (Review ID: 83259)
      ======================================================================

      4291668 suggests a method Locale.valueOf for the same problem:

      public static Locale valueOf(String s) {
          String language = "";
          String country = "";
          String variant = "";
                  
          int i = s.indexOf('_');
          if (i < 0) {
              language = s;
          } else {
              language = s.substring(0, i);
                      
              int j = s.indexOf('_', i + 1);
              if (j < 0) {
                  country = s.substring(i + 1);
              } else {
                  country = s.substring(i + 1, j);
                  variant = s.substring(j + 1);
              }
          }
                  
          return new Locale(language, country, variant);
      }

            joconnersunw John Oconner (Inactive)
            vasya Vassili Igouchkine (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: