Skip to content

Commit e424132

Browse files
committed
[jvm] Improve nqp::tc and nqp::tclc a bit.
Still lack support for most codepoints that don't have a 1 to 1 mapping.
1 parent 8460157 commit e424132

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/vm/jvm/QAST/Compiler.nqp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2287,7 +2287,8 @@ QAST::OperationsJAST.map_classlib_core_op('bitand_s', $TYPE_OPS, 'bitand_s', [$R
22872287
QAST::OperationsJAST.map_classlib_core_op('chars', $TYPE_OPS, 'chars', [$RT_STR], $RT_INT);
22882288
QAST::OperationsJAST.map_classlib_core_op('uc', $TYPE_OPS, 'uc', [$RT_STR], $RT_STR);
22892289
QAST::OperationsJAST.map_classlib_core_op('lc', $TYPE_OPS, 'lc', [$RT_STR], $RT_STR);
2290-
QAST::OperationsJAST.map_classlib_core_op('tc', $TYPE_OPS, 'uc', [$RT_STR], $RT_STR);
2290+
QAST::OperationsJAST.map_classlib_core_op('tc', $TYPE_OPS, 'tc', [$RT_STR], $RT_STR);
2291+
QAST::OperationsJAST.map_classlib_core_op('tclc', $TYPE_OPS, 'tclc', [$RT_STR], $RT_STR);
22912292
QAST::OperationsJAST.map_classlib_core_op('fc', $TYPE_OPS, 'lc', [$RT_STR], $RT_STR);
22922293
QAST::OperationsJAST.map_classlib_core_op('x', $TYPE_OPS, 'x', [$RT_STR, $RT_INT], $RT_STR, :tc);
22932294
QAST::OperationsJAST.map_classlib_core_op('iscclass', $TYPE_OPS, 'iscclass', [$RT_INT, $RT_STR, $RT_INT], $RT_INT);

src/vm/jvm/runtime/org/perl6/nqp/runtime/Ops.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3969,6 +3969,29 @@ public static String uc(String val) {
39693969
return val.toUpperCase();
39703970
}
39713971

3972+
static String codepointToTitleCase(int codepoint) {
3973+
if (codepoint == 223) return "Ss";
3974+
return new String(Character.toChars(Character.toTitleCase(codepoint)));
3975+
}
3976+
3977+
public static String tc(String val) {
3978+
String ret = "";
3979+
for (int offset = 0; offset < val.length(); ) {
3980+
int codepoint = val.codePointAt(offset);
3981+
ret += codepointToTitleCase(codepoint);
3982+
offset += Character.charCount(codepoint);
3983+
}
3984+
return ret;
3985+
}
3986+
3987+
public static String tclc(String in) {
3988+
if (in.length() == 0)
3989+
return in;
3990+
int first = in.codePointAt(0);
3991+
return codepointToTitleCase(first)
3992+
+ in.substring(Character.charCount(first)).toLowerCase();
3993+
}
3994+
39723995
public static String x(String val, long count, ThreadContext tc) {
39733996
if (count < 0)
39743997
throw ExceptionHandling.dieInternal(tc, "repeat count (" + count + ") cannot be negative");

0 commit comments

Comments
 (0)