Skip to content

Commit 0d0029d

Browse files
committed
0x7E is not a tilde in Shift-JIS{,-2004}
1 parent e4ee979 commit 0d0029d

File tree

4 files changed

+10
-5
lines changed

4 files changed

+10
-5
lines changed

ext/mbstring/libmbfl/filters/mbfilter_sjis.c

+4
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,10 @@ int mbfl_filt_conv_wchar_sjis(int c, mbfl_convert_filter *filter)
207207
/* Unicode 0x5C is a backslash; but Shift-JIS uses 0x5C for the
208208
* Yen sign. JIS X 0208 kuten 0x2140 is a backslash. */
209209
s1 = 0x2140;
210+
} else if (c == 0x7E) {
211+
/* Unicode 0x7E is a tilde, but Shift-JIS uses 0x7E for overline (or
212+
* macron). JIS X 0208 kuten 0x2141 is 'WAVE DASH' */
213+
s1 = 0x2141;
210214
} else if (c >= ucs_a1_jis_table_min && c < ucs_a1_jis_table_max) {
211215
s1 = ucs_a1_jis_table[c - ucs_a1_jis_table_min];
212216
} else if (c >= ucs_a2_jis_table_min && c < ucs_a2_jis_table_max) {

ext/mbstring/libmbfl/filters/unicode_table_jis2004.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1612,7 +1612,7 @@ static const unsigned short ucs_a1_jisx0213_table[] = { // 0x0000 - 0x045f
16121612
0x0060,0x0061,0x0062,0x0063,0x0064,0x0065,0x0066,0x0067,
16131613
0x0068,0x0069,0x006A,0x006B,0x006C,0x006D,0x006E,0x006F,
16141614
0x0070,0x0071,0x0072,0x0073,0x0074,0x0075,0x0076,0x0077,
1615-
0x0078,0x0079,0x007A,0x007B,0x007C,0x007D,0x007E,0x007F,
1615+
0x0078,0x0079,0x007A,0x007B,0x007C,0x007D,0x2141,0x007F,
16161616
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
16171617
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
16181618
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,

ext/mbstring/tests/sjis2004_encoding.phpt

+3-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ while ($line = fgets($fp, 256)) {
3636
}
3737
}
3838
}
39-
$fromUnicode["\x00\x7E"] = "\x7E"; /* Not reversible; SJIS 0x7E -> U+203E */
39+
40+
/* U+007E is TILDE, Shift-JIS 0x8160 is WAVE DASH */
41+
$fromUnicode["\x00\x7E"] = "\x81\x60";
4042

4143
/* U+005C is backslash, Shift-JIS 0x815F is REVERSE SOLIDUS
4244
* (ie. a fancy way to say "backslash") */

ext/mbstring/tests/sjis_encoding.phpt

+2-3
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,11 @@ for ($i = 0; $i < 0x20; $i++) {
1919
$fromUnicode["\x00" . chr($i)] = chr($i);
2020
}
2121

22+
/* U+007E is TILDE; convert to Shift-JIS 0x8160 (WAVE DASH) */
23+
$fromUnicode["\x00\x7E"] = "\x81\x60";
2224
/* DEL character */
2325
$validChars["\x7F"] = "\x00\x7F";
2426
$fromUnicode["\x00\x7F"] = "\x7F";
25-
/* Although Shift-JIS uses 0x7E for an overline, we will map Unicode 0x7E
26-
* (tilde) to Shift-JIS 0x7E (as iconv does) */
27-
$fromUnicode["\x00\x7E"] = "\x7E";
2827
/* Use fullwidth reverse solidus, not (halfwidth) backslash (0x5C) */
2928
$validChars["\x81\x5F"] = "\xFF\x3C";
3029
$fromUnicode["\xFF\x3C"] = "\x81\x5F";

0 commit comments

Comments
 (0)