Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix failing rubyspecs for String#unpack #675

Merged
merged 4 commits into from Apr 29, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 0 additions & 5 deletions spec/tags/1.9/ruby/core/string/unpack/comment_tags.txt

This file was deleted.

1 change: 0 additions & 1 deletion spec/tags/1.9/ruby/core/string/unpack/q_tags.txt

This file was deleted.

8 changes: 0 additions & 8 deletions spec/tags/1.9/ruby/core/string/unpack/s_tags.txt

This file was deleted.

1 change: 0 additions & 1 deletion spec/tags/1.9/ruby/core/string/unpack_tags.txt

This file was deleted.

17 changes: 12 additions & 5 deletions src/org/jruby/util/Pack.java
Expand Up @@ -950,12 +950,20 @@ public static RubyArray unpack(Ruby runtime, ByteList encodedString, ByteList fo
int type = 0; int type = 0;
int next = safeGet(format); int next = safeGet(format);


while (next != 0) { mainLoop: while (next != 0) {
type = next; type = next;
next = safeGet(format); next = safeGet(format);
if (UNPACK_IGNORE_NULL_CODES.indexOf(type) != -1 && next == 0) { if (UNPACK_IGNORE_NULL_CODES.indexOf(type) != -1 && next == 0) {
next = safeGetIgnoreNull(format); next = safeGetIgnoreNull(format);
} }

if (type == '#') {
while (type != '\n') {
if (next == 0) break mainLoop;
type = next;
next = safeGet(format);
}
}


// Next indicates to decode using native encoding format // Next indicates to decode using native encoding format
if (next == '_' || next == '!') { if (next == '_' || next == '!') {
Expand All @@ -978,6 +986,8 @@ public static RubyArray unpack(Ruby runtime, ByteList encodedString, ByteList fo
} }
type = ENDIANESS_CODES.charAt(index); type = ENDIANESS_CODES.charAt(index);
next = safeGet(format); next = safeGet(format);

if (next == '_' || next == '!') next = safeGet(format);
} }


// How many occurrences of 'type' we want // How many occurrences of 'type' we want
Expand Down Expand Up @@ -1574,11 +1584,8 @@ public static void decode(Ruby runtime, ByteBuffer encode, int occurrences,
result.append(converter.decode(runtime, encode)); result.append(converter.decode(runtime, encode));
} }


// MRI behavior: for 'Q', do not add trailing nils for (; lPadLength-- > 0;)
if (converter != converters['Q']) {
for (; lPadLength-- > 0;)
result.append(runtime.getNil()); result.append(runtime.getNil());
}
} }


public static int encode(Ruby runtime, int occurrences, ByteList result, public static int encode(Ruby runtime, int occurrences, ByteList result,
Expand Down