Skip to content

Commit

Permalink
Make new appendStringUnsafe to see how latest change to appendString …
Browse files Browse the repository at this point in the history
…plays out
  • Loading branch information
enebo committed May 9, 2024
1 parent bbcad68 commit 476962b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
10 changes: 5 additions & 5 deletions core/src/main/java/org/jruby/RubyProc.java
Original file line number Diff line number Diff line change
Expand Up @@ -239,17 +239,17 @@ public IRubyObject to_s() {
string.setEncoding(RubyString.ASCII);

string.append(types(runtime, type()));
string.catString(":0x" + Integer.toString(System.identityHashCode(block), 16));
string.catStringUnsafe(":0x" + Integer.toString(System.identityHashCode(block), 16));

boolean isSymbolProc = block.getBody() instanceof RubySymbol.SymbolProcBody;
if (isSymbolProc) {
string.catString("(&:" + ((RubySymbol.SymbolProcBody) block.getBody()).getId() + ")");
string.catStringUnsafe("(&:" + ((RubySymbol.SymbolProcBody) block.getBody()).getId() + ")");
} else if ((file = block.getBody().getFile()) != null) {
string.catString(" " + file + ":" + (block.getBody().getLine() + 1));
string.catStringUnsafe(" " + file + ":" + (block.getBody().getLine() + 1));
}

if (isLambda()) string.catString(" (lambda)");
string.catString(">");
if (isLambda()) string.catStringUnsafe(" (lambda)");
string.catStringUnsafe(">");

return string;
}
Expand Down
14 changes: 14 additions & 0 deletions core/src/main/java/org/jruby/RubyString.java
Original file line number Diff line number Diff line change
Expand Up @@ -1524,6 +1524,20 @@ public final int catWithCodeRange(ByteList other, int codeRange) {
return EncodingUtils.encCrStrBufCat(metaClass.runtime, this, other, other.getEncoding(), codeRange);
}

/**
* Append a Java String to this RubyString assuming it will be the encoding of the RubyString. If it is
* not then then it will end up as an invalid string. Some methods assume an encoding of BINARY so that
* broken bytes are possible/expected (e.g. an error message with two names which are not compatible to be
* combined into a single Ruby String). Proc#to_s is an example of this.
* @param str to be appended
* @return this string after it has appended str
*/
public final RubyString catStringUnsafe(String str) {
ByteList other = encodeBytelist(str, getEncoding());
catWithCodeRange(other, CR_UNKNOWN);
return this;
}

public final RubyString catString(String str) {
ByteList other = encodeBytelist(str, UTF8);
catWithCodeRange(other, CR_VALID);
Expand Down

0 comments on commit 476962b

Please sign in to comment.