-
-
Save ChrisBr/1856b76b25d3663c2819bfbd37a3dc49 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@JRubyMethod(name = "delete_prefix") | |
public IRubyObject delete_prefix(ThreadContext context, IRubyObject arg) { | |
IRubyObject tmp = arg.checkStringType(); | |
if (tmp.isNil()) throw context.runtime.newTypeError("no implicit conversion of " + arg.getMetaClass().getName() + " into String"); | |
RubyString prefix = (RubyString)tmp; | |
if (this.start_with_p(context, prefix).isTrue()) { | |
RubyString result = (RubyString) substr19(context.runtime, prefix.strLength(), this.strLength() - prefix.strLength()); | |
return result.isEmpty() ? this : result; | |
} else { | |
return this; | |
} | |
} | |
@JRubyMethod(name = "delete_suffix") | |
public IRubyObject delete_suffix(ThreadContext context, IRubyObject arg) { | |
IRubyObject tmp = arg.checkStringType(); | |
if (tmp.isNil()) throw context.runtime.newTypeError("no implicit conversion of " + arg.getMetaClass().getName() + " into String"); | |
RubyString suffix = (RubyString)tmp; | |
if (this.end_with_p(context, suffix).isTrue()) { | |
RubyString result = (RubyString) substr19(context.runtime, 0, this.strLength() - suffix.strLength()); | |
return result.isEmpty() ? this : result; | |
} else { | |
return this; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment