Skip to content

Commit

Permalink
Simplify String operations (#776)
Browse files Browse the repository at this point in the history
  • Loading branch information
turbanoff committed Mar 29, 2022
1 parent fe1a6ff commit c8fcdda
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1575,7 +1575,7 @@ private boolean vt100_write(int c) {
vt100_parse_func <<= 8;
vt100_parse_func += (char) c;
} else if (msb == 0x30 && vt100_parse_state == State.Csi) {
vt100_parse_param += new String(new char[]{(char) c});
vt100_parse_param += String.valueOf((char)c);
} else {
vt100_parse_func <<= 8;
vt100_parse_func += (char) c;
Expand Down
7 changes: 2 additions & 5 deletions builtins/src/main/java/org/jline/builtins/TTop.java
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ private synchronized void display() throws IOException {
long count = gc.getCollectionCount();
long time = gc.getCollectionTime();
sbc.append(gc.getName()).append(": ")
.append(Long.toString(count)).append(" col. / ")
.append(count).append(" col. / ")
.append(String.format("%d", time / 1000))
.append(".")
.append(String.format("%03d", time % 1000))
Expand Down Expand Up @@ -557,10 +557,7 @@ private static String padcut(String str, int nb) {
}
return sb.toString();
} else {
StringBuilder sb = new StringBuilder(nb);
sb.append(str, 0, nb - 3);
sb.append("...");
return sb.toString();
return str.substring(0, nb - 3) + "...";
}
}
private static String memory(long cur, long max) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ private static String doSubstVars(String val,
// Append the leading characters, the substituted value of
// the variable, and the trailing characters to get the new
// value.
val = val.substring(0, startDelim) + substValue + val.substring(stopDelim + DELIM_STOP.length(), val.length());
val = val.substring(0, startDelim) + substValue + val.substring(stopDelim + DELIM_STOP.length());

// Now perform substitution again, since there could still
// be substitutions to make.
Expand Down
2 changes: 1 addition & 1 deletion terminal/src/main/java/org/jline/utils/Colors.java
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ private static double calculateH(double h) {
H = 0;
return H;
} else {
throw new IllegalArgumentException("h outside assumed range 0..360: " + Double.toString(h));
throw new IllegalArgumentException("h outside assumed range 0..360: " + h);
}
}

Expand Down
2 changes: 1 addition & 1 deletion terminal/src/main/java/org/jline/utils/StyleResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ private AttributedStyle applyReference(final AttributedStyle style, final String
if (spec.length() == 1) {
log.warning("Invalid style-reference; missing discriminator: " + spec);
} else {
String name = spec.substring(1, spec.length());
String name = spec.substring(1);
String resolvedSpec = source.apply(name);
if (resolvedSpec != null) {
return apply(style, resolvedSpec);
Expand Down
2 changes: 1 addition & 1 deletion terminal/src/test/java/org/jline/utils/ScreenTerminal.java
Original file line number Diff line number Diff line change
Expand Up @@ -1572,7 +1572,7 @@ private boolean vt100_write(int c) {
vt100_parse_func <<= 8;
vt100_parse_func += (char) c;
} else if (msb == 0x30 && vt100_parse_state == State.Csi) {
vt100_parse_param += new String(new char[]{(char) c});
vt100_parse_param += String.valueOf((char)c);
} else {
vt100_parse_func <<= 8;
vt100_parse_func += (char) c;
Expand Down

0 comments on commit c8fcdda

Please sign in to comment.