Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Implement cheating nqp::readlinechompfh on JVM.
  • Loading branch information
jnthn committed Nov 5, 2015
1 parent 570054a commit 05d7b20
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/vm/jvm/QAST/Compiler.nqp
Expand Up @@ -2070,6 +2070,7 @@ QAST::OperationsJAST.map_classlib_core_op('printfh', $TYPE_OPS, 'printfh', [$RT_
QAST::OperationsJAST.map_classlib_core_op('sayfh', $TYPE_OPS, 'sayfh', [$RT_OBJ, $RT_STR], $RT_INT, :tc);
QAST::OperationsJAST.map_classlib_core_op('flushfh', $TYPE_OPS, 'flushfh', [$RT_OBJ], $RT_OBJ, :tc);
QAST::OperationsJAST.map_classlib_core_op('readlinefh', $TYPE_OPS, 'readlinefh', [$RT_OBJ], $RT_STR, :tc);
QAST::OperationsJAST.map_classlib_core_op('readlinechompfh', $TYPE_OPS, 'readlinechompfh', [$RT_OBJ], $RT_STR, :tc);
QAST::OperationsJAST.map_classlib_core_op('readallfh', $TYPE_OPS, 'readallfh', [$RT_OBJ], $RT_STR, :tc);
QAST::OperationsJAST.map_classlib_core_op('getcfh', $TYPE_OPS, 'getcfh', [$RT_OBJ], $RT_STR, :tc);
QAST::OperationsJAST.map_classlib_core_op('eoffh', $TYPE_OPS, 'eoffh', [$RT_OBJ], $RT_INT, :tc);
Expand Down
10 changes: 10 additions & 0 deletions src/vm/jvm/runtime/org/perl6/nqp/runtime/Ops.java
Expand Up @@ -673,6 +673,16 @@ public static String readlinefh(SixModelObject obj, ThreadContext tc) {
}
}

public static String readlinechompfh(SixModelObject obj, ThreadContext tc) {
String line = readlinefh(obj, tc);
if (line.endsWith("\r\n"))
return line.substring(0, line.length() - 2);
else if (line.endsWith("\n"))
return line.substring(0, line.length() - 1);
else
return line;
}

public static String readallfh(SixModelObject obj, ThreadContext tc) {
if (obj instanceof IOHandleInstance) {
IOHandleInstance h = (IOHandleInstance)obj;
Expand Down

0 comments on commit 05d7b20

Please sign in to comment.