Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions core/src/main/java/org/jruby/util/Pack.java
Original file line number Diff line number Diff line change
Expand Up @@ -1150,6 +1150,9 @@ private static IRubyObject unpackInternal(ThreadContext context, RubyString enco
case 'w':
value = unpack_w(context, block, result, encode, occurrences, mode);
break;
case '^':
value = unpack_offset(context, block, result, encodedString, encode, mode);
break;
default:
unknownDirective(context, "unpack", type, formatString);
break;
Expand Down Expand Up @@ -2139,6 +2142,19 @@ private static void unknownDirective(ThreadContext context, String mode, int typ
throw argumentError(context, str(context.runtime, "unknown " + mode + " directive '", newString(context, unknown), "' in '", newString(context,formatString), "'"));
}

/**
* Unpack '^': the current byte offset from the start of the string (not from the offset: argument). A count
* is ignored, so '^3' still unpacks one value.
*/
@CRuby(value = "pack_unpack_internal", file = "pack.c", note = "'^' directive")
private static IRubyObject unpack_offset(ThreadContext context, Block block, RubyArray result,
ByteList encodedString, ByteBuffer encode, int mode) {
IRubyObject value = asFixnum(context, encode.position() - encodedString.begin());
if (mode == UNPACK_1) return value;
appendOrYield(context, block, result, value, mode);
return null;
}

/** An alignment parsed after x! or @!, and the format character that follows it. */
private record Alignment(long size, int next) {}

Expand Down
Loading