Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3b6bba5
commit a5f75c6
Showing
2 changed files
with
32 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
src/vm/jvm/runtime/org/perl6/nqp/truffle/nodes/expression/NQPTclcNode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package org.perl6.nqp.truffle.nodes.expression; | ||
import com.oracle.truffle.api.frame.VirtualFrame; | ||
import com.oracle.truffle.api.nodes.NodeInfo; | ||
import org.perl6.nqp.truffle.nodes.NQPNode; | ||
import org.perl6.nqp.dsl.Deserializer; | ||
|
||
@NodeInfo(shortName = "tclc") | ||
public final class NQPTclcNode extends NQPNode { | ||
@Child private NQPNode argNode; | ||
|
||
@Deserializer | ||
public NQPTclcNode(NQPNode argNode) { | ||
this.argNode = argNode; | ||
} | ||
|
||
static String codepointToTitleCase(int codepoint) { | ||
if (codepoint == 223) return "Ss"; | ||
return new String(Character.toChars(Character.toTitleCase(codepoint))); | ||
} | ||
|
||
@Override | ||
public String executeStr(VirtualFrame frame) { | ||
String in = argNode.executeStr(frame); | ||
if (in.length() == 0) | ||
return in; | ||
int first = in.codePointAt(0); | ||
return codepointToTitleCase(first) | ||
+ in.substring(Character.charCount(first)).toLowerCase(); | ||
} | ||
} |