Some trivial implementations of methods that work with Locale javac
authorJaroslav Tulach <jaroslav.tulach@apidesign.org>
Sat, 28 Sep 2013 02:43:18 +0200
branchjavac
changeset 131766fdb47061aa
parent 1316 751852f49324
child 1319 be64f0e582bc
Some trivial implementations of methods that work with Locale
rt/emul/compact/src/test/java/org/apidesign/bck2brwsr/tck/CompareStringsTest.java
rt/emul/mini/src/main/java/java/lang/String.java
     1.1 --- a/rt/emul/compact/src/test/java/org/apidesign/bck2brwsr/tck/CompareStringsTest.java	Sat Sep 28 02:11:01 2013 +0200
     1.2 +++ b/rt/emul/compact/src/test/java/org/apidesign/bck2brwsr/tck/CompareStringsTest.java	Sat Sep 28 02:43:18 2013 +0200
     1.3 @@ -20,6 +20,7 @@
     1.4  import java.io.UnsupportedEncodingException;
     1.5  import java.net.MalformedURLException;
     1.6  import java.net.URL;
     1.7 +import java.util.Locale;
     1.8  import org.apidesign.bck2brwsr.vmtest.Compare;
     1.9  import org.apidesign.bck2brwsr.vmtest.VMTest;
    1.10  import org.testng.annotations.Factory;
    1.11 @@ -161,6 +162,19 @@
    1.12          assert res.equals("ba") : "Expecting ba: " + res;
    1.13          return res;
    1.14      }
    1.15 +    
    1.16 +    @Compare public String localeUS() {
    1.17 +        return Locale.US.toString();
    1.18 +    }
    1.19 +    
    1.20 +    @Compare public String localeFrench() {
    1.21 +        return Locale.FRENCH.toString();
    1.22 +    }
    1.23 +    
    1.24 +    
    1.25 +    @Compare public String formatSimple() {
    1.26 +        return String.format((Locale)null, "Hello %s!", "World");
    1.27 +    }
    1.28  
    1.29      @Factory
    1.30      public static Object[] create() {
     2.1 --- a/rt/emul/mini/src/main/java/java/lang/String.java	Sat Sep 28 02:11:01 2013 +0200
     2.2 +++ b/rt/emul/mini/src/main/java/java/lang/String.java	Sat Sep 28 02:43:18 2013 +0200
     2.3 @@ -27,6 +27,8 @@
     2.4  
     2.5  import java.io.UnsupportedEncodingException;
     2.6  import java.util.Comparator;
     2.7 +import java.util.Locale;
     2.8 +import java.util.Objects;
     2.9  import org.apidesign.bck2brwsr.core.ExtraJavaScript;
    2.10  import org.apidesign.bck2brwsr.core.JavaScriptBody;
    2.11  import org.apidesign.bck2brwsr.core.JavaScriptOnly;
    2.12 @@ -2454,7 +2456,9 @@
    2.13       * @see     java.lang.String#toUpperCase(Locale)
    2.14       * @since   1.1
    2.15       */
    2.16 -//    public String toLowerCase(Locale locale) {
    2.17 +    public String toLowerCase(java.util.Locale locale) {
    2.18 +        return toLowerCase();
    2.19 +    }
    2.20  //        if (locale == null) {
    2.21  //            throw new NullPointerException();
    2.22  //        }
    2.23 @@ -2569,7 +2573,7 @@
    2.24       */
    2.25      @JavaScriptBody(args = {}, body = "return this.toLowerCase();")
    2.26      public String toLowerCase() {
    2.27 -        throw new UnsupportedOperationException("Should be supported but without connection to locale");
    2.28 +        return null;
    2.29      }
    2.30  
    2.31      /**
    2.32 @@ -2620,8 +2624,10 @@
    2.33       * @see     java.lang.String#toLowerCase(Locale)
    2.34       * @since   1.1
    2.35       */
    2.36 +    public String toUpperCase(Locale locale) {
    2.37 +        return toUpperCase();
    2.38 +    }
    2.39      /* not for javascript 
    2.40 -    public String toUpperCase(Locale locale) {
    2.41          if (locale == null) {
    2.42              throw new NullPointerException();
    2.43          }
    2.44 @@ -2735,7 +2741,7 @@
    2.45       */
    2.46      @JavaScriptBody(args = {}, body = "return this.toUpperCase();")
    2.47      public String toUpperCase() {
    2.48 -        throw new UnsupportedOperationException();
    2.49 +        return null;
    2.50      }
    2.51  
    2.52      /**
    2.53 @@ -2846,7 +2852,7 @@
    2.54       * @since  1.5
    2.55       */
    2.56      public static String format(String format, Object ... args) {
    2.57 -        throw new UnsupportedOperationException();
    2.58 +        return format((Locale)null, format, args);
    2.59      }
    2.60  
    2.61      /**
    2.62 @@ -2889,9 +2895,14 @@
    2.63       * @see  java.util.Formatter
    2.64       * @since  1.5
    2.65       */
    2.66 -//    public static String format(Locale l, String format, Object ... args) {
    2.67 -//        return new Formatter(l).format(format, args).toString();
    2.68 -//    }
    2.69 +    public static String format(Locale l, String format, Object ... args) {
    2.70 +        String p = format;
    2.71 +        for (int i = 0; i < args.length; i++) {
    2.72 +            p = p.replaceFirst("%s", Objects.toString(args[i]));
    2.73 +        }
    2.74 +        return p;
    2.75 +        // return new Formatter(l).format(format, args).toString();
    2.76 +    }
    2.77  
    2.78      /**
    2.79       * Returns the string representation of the <code>Object</code> argument.