Skip to content

Commit

Permalink
[jvm] Implement nqp::eqatic
Browse files Browse the repository at this point in the history
  • Loading branch information
pmurias committed Oct 20, 2017
1 parent 5bc5ead commit bae6331
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/vm/jvm/QAST/Compiler.nqp
Original file line number Diff line number Diff line change
Expand Up @@ -2331,7 +2331,8 @@ QAST::OperationsJAST.add_core_op('substr', -> $qastcomp, $op {
!! QAST::Op.new( :op('substr3'), |@operands ));
});

QAST::OperationsJAST.map_classlib_core_op('eqat', $TYPE_OPS, 'string_equal_at', [$RT_STR, $RT_STR, $RT_INT], $RT_INT);
QAST::OperationsJAST.map_classlib_core_op('eqat', $TYPE_OPS, 'eqat', [$RT_STR, $RT_STR, $RT_INT], $RT_INT);
QAST::OperationsJAST.map_classlib_core_op('eqatic', $TYPE_OPS, 'eqatic', [$RT_STR, $RT_STR, $RT_INT], $RT_INT);
# ord can be on a the first char in a string or at a particular char.
QAST::OperationsJAST.map_classlib_core_op('ordfirst', $TYPE_OPS, 'ordfirst', [$RT_STR], $RT_INT);
QAST::OperationsJAST.map_classlib_core_op('ordat', $TYPE_OPS, 'ordat', [$RT_STR, $RT_INT], $RT_INT);
Expand Down
17 changes: 15 additions & 2 deletions src/vm/jvm/runtime/org/perl6/nqp/runtime/Ops.java
Original file line number Diff line number Diff line change
Expand Up @@ -4145,8 +4145,13 @@ public static String substr3(String val, long offset, long length) {
return val.substring((int)offset, end);
}

// does haystack have needle as a substring at offset?
// keep this till we reboostrap
public static long string_equal_at(String haystack, String needle, long offset) {
return string_equal_at(false, haystack, needle, offset);
}

// does haystack have needle as a substring at offset?
private static long string_equal_at(boolean ignoreCase, String haystack, String needle, long offset) {
long haylen = haystack.length();
long needlelen = needle.length();

Expand All @@ -4159,7 +4164,15 @@ public static long string_equal_at(String haystack, String needle, long offset)
if (haylen - offset < needlelen) {
return 0;
}
return haystack.regionMatches((int)offset, needle, 0, (int)needlelen) ? 1 : 0;
return haystack.regionMatches(ignoreCase, (int)offset, needle, 0, (int)needlelen) ? 1 : 0;
}

public static long eqat(String haystack, String needle, long offset) {
return string_equal_at(false, haystack, needle, offset);
}

public static long eqatic(String haystack, String needle, long offset) {
return string_equal_at(true, haystack, needle, offset);
}

public static long ordfirst(String str) {
Expand Down

0 comments on commit bae6331

Please sign in to comment.