Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fixing IO.ungetc tagged specs! #688

Merged
merged 1 commit into from

2 participants

Jose Donizetti Charles Oliver Nutter
Jose Donizetti
Collaborator

@headius the refactoring on the ChannelStream to use ByteList instead LinkedList comes in the next pr.

Charles Oliver Nutter
Owner

Looks great, thank you!

Charles Oliver Nutter headius merged commit 86080d9 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 1, 2013
  1. Jose Donizetti
This page is out of date. Refresh to see the latest.
3  spec/tags/1.9/ruby/core/io/ungetc_tags.txt
View
@@ -1,3 +0,0 @@
-fails:IO#ungetc does not affect the stream and returns nil when passed nil
-fails:IO#ungetc puts one or more characters back in the stream
-fails:IO#ungetc calls #to_str to convert the argument if it is not an Integer
23 src/org/jruby/RubyIO.java
View
@@ -2619,27 +2619,28 @@ public IRubyObject ungetc(IRubyObject number) {
}
@JRubyMethod(name = "ungetc", required = 1, compat = CompatVersion.RUBY1_9)
- public IRubyObject ungetc19(IRubyObject number) {
+ public IRubyObject ungetc19(IRubyObject character) {
Ruby runtime = getRuntime();
- OpenFile myOpenFile = getOpenFileChecked();
- if (!myOpenFile.isReadBuffered()) {
+ if(character.isNil()) {
return runtime.getNil();
}
- if (number instanceof RubyFixnum) {
- int c = (int)number.convertToInteger().getLongValue();
-
+ if (character instanceof RubyFixnum) {
+ int c = (int)character.convertToInteger().getLongValue();
ungetcCommon(c);
- } else if (number instanceof RubyString) {
- RubyString str = (RubyString) number;
+ } else if (character instanceof RubyString || character.respondsTo("to_str")) {
+ RubyString str = (RubyString) character.callMethod(runtime.getCurrentContext(), "to_str");
if (str.isEmpty()) return runtime.getNil();
- int c = str.getEncoding().mbcToCode(str.getBytes(), 0, 1);
+ byte[] bytes = str.getBytes();
+ for(int i = bytes.length - 1; i >= 0; i-- ) {
+ int c = bytes[i];
+ ungetcCommon(c);
+ }
- ungetcCommon(c);
} else {
- throw runtime.newTypeError(number, runtime.getFixnum());
+ throw runtime.newTypeError(character, runtime.getFixnum());
}
return runtime.getNil();
Something went wrong with that request. Please try again.