Avoid using regex for CharSet name check.

This particular check is an overkill that breaks WASM compatibility.

GWT generally is not very accurate on exception types for the unhappy
codepath. An app using charset with incorrect format is considered
incorrect esp. since GWT only supports only a few hardcoded ones.

PiperOrigin-RevId: 378322445
Change-Id: I680165857b69d11038b405bc29cfb7f560818be3
diff --git a/user/super/com/google/gwt/emul/java/nio/charset/Charset.java b/user/super/com/google/gwt/emul/java/nio/charset/Charset.java
index aaa21e3..615b5f7 100644
--- a/user/super/com/google/gwt/emul/java/nio/charset/Charset.java
+++ b/user/super/com/google/gwt/emul/java/nio/charset/Charset.java
@@ -22,7 +22,6 @@
 import java.util.SortedMap;
 import java.util.TreeMap;
 import javaemul.internal.EmulatedCharset;
-import javaemul.internal.NativeRegExp;
 
 /**
  * A minimal emulation of {@link Charset}.
@@ -60,11 +59,7 @@
       return EmulatedCharset.UTF_8;
     }
 
-    if (new NativeRegExp("^[A-Za-z0-9][\\w-:\\.\\+]*$").test(charsetName)) {
-      throw new UnsupportedCharsetException(charsetName);
-    } else {
-      throw new IllegalCharsetNameException(charsetName);
-    }
+    throw new UnsupportedCharsetException(charsetName);
   }
 
   private final String name;
diff --git a/user/test/com/google/gwt/emultest/java/nio/charset/CharsetTest.java b/user/test/com/google/gwt/emultest/java/nio/charset/CharsetTest.java
index ad6f887..8811f06 100644
--- a/user/test/com/google/gwt/emultest/java/nio/charset/CharsetTest.java
+++ b/user/test/com/google/gwt/emultest/java/nio/charset/CharsetTest.java
@@ -17,7 +17,6 @@
 package com.google.gwt.emultest.java.nio.charset;
 
 import com.google.gwt.emultest.java.util.EmulTestBase;
-
 import java.nio.charset.Charset;
 import java.nio.charset.IllegalCharsetNameException;
 import java.nio.charset.UnsupportedCharsetException;
@@ -49,22 +48,22 @@
     try {
       Charset.forName("");
       fail();
-    } catch (IllegalCharsetNameException expected) {
+    } catch (IllegalCharsetNameException | UnsupportedCharsetException expected) {
     }
     try {
       Charset.forName("!@#$");
       fail();
-    } catch (IllegalCharsetNameException expected) {
+    } catch (IllegalCharsetNameException | UnsupportedCharsetException expected) {
     }
     try {
       Charset.forName("_UTF_8");
       fail();
-    } catch (IllegalCharsetNameException expected) {
+    } catch (IllegalCharsetNameException | UnsupportedCharsetException expected) {
     }
     try {
       Charset.forName("UTF_8#");
       fail();
-    } catch (IllegalCharsetNameException expected) {
+    } catch (IllegalCharsetNameException | UnsupportedCharsetException expected) {
     }
   }