Permalink
Browse files

backport chr() 'cannot be negative' error from Moar to JVM

  • Loading branch information...
1 parent 1863ae2 commit e3e35ca0faa252f52782e06acccd5f3ca7e4c900 @dwarring dwarring committed Mar 8, 2014
Showing with 11 additions and 8 deletions.
  1. +11 −8 src/vm/jvm/runtime/org/perl6/nqp/runtime/Ops.java
@@ -3007,18 +3007,21 @@ public static String concat(String valA, String valB) {
return valA + valB;
}
- public static String chr(long val, ThreadContext tc) {
+ public static String chr(long ord, ThreadContext tc) {
// http://en.wikipedia.org/wiki/Mapping_of_Unicode_characters
- if ((val >= 0xfdd0
- && (val <= 0xfdef // non character
- || ((val & 0xfffe) == 0xfffe) // non character
- || val > 0x10ffff) // out of range
+ if ((ord >= 0xfdd0
+ && (ord <= 0xfdef // non character
+ || ((ord & 0xfffe) == 0xfffe) // non character
+ || ord > 0x10ffff) // out of range
)
- || (val >= 0xd800 && val <= 0xdfff) // surrogate
+ || (ord >= 0xd800 && ord <= 0xdfff) // surrogate
) {
- throw ExceptionHandling.dieInternal(tc, "Invalid code-point U+" + String.format("%05X", val));
+ throw ExceptionHandling.dieInternal(tc, "Invalid code-point U+" + String.format("%05X", ord));
}
- return (new StringBuffer()).append(Character.toChars((int)val)).toString();
+ if (ord < 0)
+ throw ExceptionHandling.dieInternal(tc, "chr codepoint cannot be negative");
+
+ return (new StringBuffer()).append(Character.toChars((int)ord)).toString();
}
public static String join(String delimiter, SixModelObject arr, ThreadContext tc) {

0 comments on commit e3e35ca

Please sign in to comment.