Skip to content

Commit

Permalink
Fix getuniname for control's. Fixes RT122470 RT122471
Browse files Browse the repository at this point in the history
Also adds tests for the lowest and highest codepoint for each of the
ranges of control codepoints, as well as one above and below these
to ensure the range is correct.
  • Loading branch information
samcv committed Oct 5, 2017
1 parent 6dc507f commit 7954f9b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/vm/jvm/runtime/org/perl6/nqp/runtime/Ops.java
Expand Up @@ -7173,7 +7173,12 @@ public static String getuniname(long codePoint, ThreadContext tc) {
try {
if(codePoint < 0) {
name = "<illegal>";
} else {
}
/* Return <control-XXXX> for control characters */
else if (codePoint <= 0x1F || (0x7F <= codePoint && codePoint <= 0x9F)) {
name = String.format("<control-%04X>", codePoint);
}
else {
name = Character.getName(cp);
if(name == null) {
name = "<unassigned>";
Expand Down
9 changes: 8 additions & 1 deletion t/nqp/106-unicodenames.t
@@ -1,4 +1,4 @@
plan(19);
plan(26);
is(nqp::getstrfromname('FULL STOP'), '.', 'getstrfromname works');
is(nqp::codepointfromname('FULL STOP'), nqp::ord('.'), 'codepointfromname works');
is(nqp::getstrfromname('super fake not real name'), '', 'getstrfromname returns empty string for nonexistant codepoint names');
Expand Down Expand Up @@ -55,3 +55,10 @@ else {
is(nqp::codepointfromname('LATIN SMALL LETTER E WITH OGONEK AND TILDE'), -1, 'nqp::codepointfromname doesn\'t accept sequences');

is(nqp::getuniname(104), 'LATIN SMALL LETTER H', 'nqp::getuniname');
is(nqp::getuniname(0x0), '<control-0000>', 'nqp::getuniname for controls');
is(nqp::getuniname(0x1F), '<control-001F>', 'nqp::getuniname for controls');
is(nqp::getuniname(0x20), 'SPACE', 'nqp::getuniname for SPACE');
is(nqp::getuniname(0x7E), 'TILDE', 'nqp::getuniname for TILDE');
is(nqp::getuniname(0x7F), '<control-007F>', 'nqp::getuniname for controls');
is(nqp::getuniname(0x9F), '<control-009F>', 'nqp::getuniname for controls');
is(nqp::getuniname(0xA0), 'NO-BREAK SPACE', 'nqp::getuniname for controls');

0 comments on commit 7954f9b

Please sign in to comment.