Skip to content

Commit

Permalink
8301119: Support for GB18030-2022
Browse files Browse the repository at this point in the history
8310947: gb18030-2000 not selectable with LANG=zh_CN.GB18030 after JDK-8301119

Co-authored-by: Severin Gehwolf <sgehwolf@openjdk.org>
Reviewed-by: stuefe, sgehwolf
Backport-of: 5c4e744dabcf7785c35168db5d0458ccebfd41e6
  • Loading branch information
gnu-andrew and jerboaa committed Jul 13, 2023
1 parent e575cb3 commit 4dc1305
Show file tree
Hide file tree
Showing 9 changed files with 979 additions and 115 deletions.
2 changes: 0 additions & 2 deletions jdk/src/share/classes/sun/nio/cs/AbstractCharsetProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,9 @@
import java.util.ArrayList;
import java.util.TreeMap;
import java.util.Iterator;
import java.util.Locale;
import java.util.Map;
import sun.misc.ASCIICaseInsensitiveComparator;


/**
* Abstract base class for charset providers.
*
Expand Down
50 changes: 39 additions & 11 deletions jdk/src/share/classes/sun/nio/cs/ext/ExtendedCharsets.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2002, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand All @@ -25,11 +25,9 @@

package sun.nio.cs.ext;

import java.lang.ref.SoftReference;
import java.nio.charset.Charset;
import java.nio.charset.spi.CharsetProvider;
import sun.nio.cs.AbstractCharsetProvider;
import java.security.AccessController;

import sun.security.action.GetPropertyAction;


Expand Down Expand Up @@ -115,9 +113,11 @@ public ExtendedCharsets() {
"CP936"
});

// The definition of this charset may be overridden by the init method
// below, if the jdk.charset.GB18030 property is set
charset("GB18030", "GB18030",
new String[] {
"gb18030-2000"
"gb18030-2022"
});

charset("GB2312", "EUC_CN",
Expand Down Expand Up @@ -1136,14 +1136,15 @@ public ExtendedCharsets() {
}

private boolean initialized = false;
private boolean isGB18030_2000 = false;

// If the sun.nio.cs.map property is defined on the command line we won't
// see it in the system-properties table until after the charset subsystem
// has been initialized. We therefore delay the effect of this property
// until after the JRE has completely booted.
// If the sun.nio.cs.map and/or jdk.charset.GB18030 properties are defined
// on the command line we won't see them in the system-properties table until
// after the charset subsystem has been initialized. We therefore delay
// the effect of these property until after the JRE has completely booted.
//
// At the moment following values for this property are supported, property
// value string is case insensitive.
// At the moment the following values for the sun.nio.cs.map property are
// supported and the property value string is case insensitive.
//
// (1)"Windows-31J/Shift_JIS"
// In 1.4.1 we added a correct implementation of the Shift_JIS charset
Expand Down Expand Up @@ -1176,6 +1177,10 @@ public ExtendedCharsets() {
// where each charset named to the left of a slash is intended to replace
// (most) uses of the charset named to the right of the slash.
//
// The jdk.charset.GB18030 property is simpler and accepts only the value
// "2000". If this value is given, the older GB18030-2000 variant of the
// character set replaces the default GB18030-2022 variant.
//
protected void init() {
if (initialized)
return;
Expand All @@ -1184,6 +1189,8 @@ protected void init() {

String map = AccessController.doPrivileged(
new GetPropertyAction("sun.nio.cs.map"));
boolean isGB18030_2000 = "2000".equals(AccessController.doPrivileged(
new GetPropertyAction("jdk.charset.GB18030")));
boolean sjisIsMS932 = false;
boolean iso2022jpIsMS50221 = false;
boolean iso2022jpIsMS50220 = false;
Expand All @@ -1202,6 +1209,16 @@ protected void init() {
}
}
}
if (isGB18030_2000) {
deleteCharset("GB18030",
new String[] {
"gb18030-2022"
});
charset("GB18030", "GB18030",
new String[] {
"gb18030-2000"
});
}
if (sjisIsMS932) {
deleteCharset("Shift_JIS",
new String[] {
Expand Down Expand Up @@ -1314,6 +1331,7 @@ protected void init() {
"x-compound-text"
});
}
this.isGB18030_2000 = isGB18030_2000;
initialized = true;
}

Expand All @@ -1322,4 +1340,14 @@ public static String[] aliasesFor(String charsetName) {
return null;
return instance.aliases(charsetName);
}

static boolean IS_2000() {
if (instance == null) {
return false;
}
if (!instance.initialized) {
instance.init();
}
return instance.isGB18030_2000;
}
}

1 comment on commit 4dc1305

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.