public Text[] splitLines() { List<Text> result = new ArrayList<Text>(); int start = 0, end = 0; for (int i = 0; i < plain.length(); i++, end = i) { char c = plain.charAt(i); boolean eol = c == '\n'; if (c == '\r' && i + 1 < plain.length() && plain.charAt(i + 1) == '\n') { eol = true; i++; } // \r\n eol |= c == '\r'; if (eol) { result.add(this.substring(start, end)); start = i + 1; } } // add remainder (may be empty string) result.add(this.substring(start, plain.length())); return result.toArray(new Text[result.size()]); }
private Text createLongOptionText(OptionSpec option, IParamLabelRenderer renderer, ColorScheme scheme, String longOption) { Text paramLabelText = renderer.renderParameterLabel(option, scheme.ansi(), scheme.optionParamStyles); // if no long option, fill in the space between the short option name and the param label value if (paramLabelText.length > 0 && longOption.length() == 0) { sep = renderer.separator(); // #181 paramLabelText may be =LABEL or [=LABEL...] int sepStart = paramLabelText.plainString().indexOf(sep); Text prefix = paramLabelText.substring(0, sepStart); paramLabelText = prefix.concat(paramLabelText.substring(sepStart + sep.length())); } Text longOptionText = scheme.optionText(longOption); longOptionText = longOptionText.concat(paramLabelText); return longOptionText; }
private int copy(BreakIterator line, Text text, Text columnValue, int offset) { // Deceive the BreakIterator to ensure no line breaks after '-' character line.setText(text.plainString().replace("-", "\u00ff")); int done = 0; for (int start = line.first(), end = line.next(); end != BreakIterator.DONE; start = end, end = line.next()) { Text word = text.substring(start, end); //.replace("\u00ff", "-"); // not needed if (columnValue.maxLength >= offset + done + length(word)) { done += copy(word, columnValue, offset + done); // TODO messages length } else { break; } } if (done == 0 && length(text) + offset > columnValue.maxLength) { // The value is a single word that is too big to be written to the column. Write as much as we can. done = copy(text, columnValue, offset); } return done; } private static int copy(Text value, Text destination, int offset) {
? copy(BreakIterator.getLineInstance(), value, textAt(row, col), indent) : copy(value, textAt(row, col), indent); value = value.substring(charsWritten); indent = 0; if (value.length > 0) { // value did not fit in column do { int charsWritten = copy(lineBreakIterator, value, textAt(row, col), indent); value = value.substring(charsWritten); indent = column.indent + indentWrappedLines; if (value.length > 0) { // value did not fit in column
Ansi ansi = Ansi.ON; Ansi.Text txt = ansi.new Text("@|bold 01234|@").concat("56").concat("@|underline 7890|@"); assertEquals(ansi.new Text("@|bold 01234|@56@|underline 7890|@"), txt.substring(0)); assertEquals(ansi.new Text("@|bold 1234|@56@|underline 7890|@"), txt.substring(1)); assertEquals(ansi.new Text("@|bold 234|@56@|underline 7890|@"), txt.substring(2)); assertEquals(ansi.new Text("@|bold 34|@56@|underline 7890|@"), txt.substring(3)); assertEquals(ansi.new Text("@|bold 4|@56@|underline 7890|@"), txt.substring(4)); assertEquals(ansi.new Text("56@|underline 7890|@"), txt.substring(5)); assertEquals(ansi.new Text("6@|underline 7890|@"), txt.substring(6)); assertEquals(ansi.new Text("@|underline 7890|@"), txt.substring(7)); assertEquals(ansi.new Text("@|underline 890|@"), txt.substring(8)); assertEquals(ansi.new Text("@|underline 90|@"), txt.substring(9)); assertEquals(ansi.new Text("@|underline 0|@"), txt.substring(10)); assertEquals(ansi.new Text(""), txt.substring(11)); assertEquals(ansi.new Text("@|bold 01234|@56@|underline 7890|@"), txt.substring(0, 11)); assertEquals(ansi.new Text("@|bold 01234|@56@|underline 789|@"), txt.substring(0, 10)); assertEquals(ansi.new Text("@|bold 01234|@56@|underline 78|@"), txt.substring(0, 9)); assertEquals(ansi.new Text("@|bold 01234|@56@|underline 7|@"), txt.substring(0, 8)); assertEquals(ansi.new Text("@|bold 01234|@56"), txt.substring(0, 7)); assertEquals(ansi.new Text("@|bold 01234|@5"), txt.substring(0, 6)); assertEquals(ansi.new Text("@|bold 01234|@"), txt.substring(0, 5)); assertEquals(ansi.new Text("@|bold 0123|@"), txt.substring(0, 4)); assertEquals(ansi.new Text("@|bold 012|@"), txt.substring(0, 3)); assertEquals(ansi.new Text("@|bold 01|@"), txt.substring(0, 2)); assertEquals(ansi.new Text("@|bold 0|@"), txt.substring(0, 1)); assertEquals(ansi.new Text(""), txt.substring(0, 0)); assertEquals(ansi.new Text("@|bold 1234|@56@|underline 789|@"), txt.substring(1, 10)); assertEquals(ansi.new Text("@|bold 234|@56@|underline 78|@"), txt.substring(2, 9)); assertEquals(ansi.new Text("@|bold 34|@56@|underline 7|@"), txt.substring(3, 8));
private int copy(BreakIterator line, Text text, Text columnValue, int offset) { // Deceive the BreakIterator to ensure no line breaks after '-' character line.setText(text.plainString().replace("-", "\u00ff")); int done = 0; for (int start = line.first(), end = line.next(); end != BreakIterator.DONE; start = end, end = line.next()) { Text word = text.substring(start, end); //.replace("\u00ff", "-"); // not needed if (columnValue.maxLength >= offset + done + length(word)) { done += copy(word, columnValue, offset + done); // TODO messages length } else { break; } } if (done == 0 && length(text) + offset > columnValue.maxLength) { // The value is a single word that is too big to be written to the column. Write as much as we can. done = copy(text, columnValue, offset); } return done; } private static int copy(Text value, Text destination, int offset) {
public Text[] splitLines() { List<Text> result = new ArrayList<Text>(); int start = 0, end = 0; for (int i = 0; i < plain.length(); i++, end = i) { char c = plain.charAt(i); boolean eol = c == '\n'; if (c == '\r' && i + 1 < plain.length() && plain.charAt(i + 1) == '\n') { eol = true; i++; } // \r\n eol |= c == '\r'; if (eol) { result.add(this.substring(start, end)); start = i + 1; } } // add remainder (may be empty string) result.add(this.substring(start, plain.length())); return result.toArray(new Text[result.size()]); }
private Text createLongOptionText(OptionSpec option, IParamLabelRenderer renderer, ColorScheme scheme, String longOption) { Text paramLabelText = renderer.renderParameterLabel(option, scheme.ansi(), scheme.optionParamStyles); // if no long option, fill in the space between the short option name and the param label value if (paramLabelText.length > 0 && longOption.length() == 0) { sep = renderer.separator(); // #181 paramLabelText may be =LABEL or [=LABEL...] int sepStart = paramLabelText.plainString().indexOf(sep); Text prefix = paramLabelText.substring(0, sepStart); paramLabelText = prefix.concat(paramLabelText.substring(sepStart + sep.length())); } Text longOptionText = scheme.optionText(longOption); longOptionText = longOptionText.concat(paramLabelText); return longOptionText; }
/** Returns a new {@code Text} instance that is a substring of this Text. Does not modify this instance! * @param start index in the plain text where to start the substring * @return a new Text instance that is a substring of this Text */ public Text substring(int start) { return substring(start, length); }
? copy(BreakIterator.getLineInstance(), value, textAt(row, col), indent) : copy(value, textAt(row, col), indent); value = value.substring(charsWritten); indent = 0; if (value.length > 0) { // value did not fit in column do { int charsWritten = copy(lineBreakIterator, value, textAt(row, col), indent); value = value.substring(charsWritten); indent = column.indent + indentWrappedLines; if (value.length > 0) { // value did not fit in column
Ansi ansi = Ansi.ON; Ansi.Text txt = ansi.new Text("@|bold 01234|@").concat("56").concat("@|underline 7890|@"); assertEquals(ansi.new Text("@|bold 01234|@56@|underline 7890|@"), txt.substring(0)); assertEquals(ansi.new Text("@|bold 1234|@56@|underline 7890|@"), txt.substring(1)); assertEquals(ansi.new Text("@|bold 234|@56@|underline 7890|@"), txt.substring(2)); assertEquals(ansi.new Text("@|bold 34|@56@|underline 7890|@"), txt.substring(3)); assertEquals(ansi.new Text("@|bold 4|@56@|underline 7890|@"), txt.substring(4)); assertEquals(ansi.new Text("56@|underline 7890|@"), txt.substring(5)); assertEquals(ansi.new Text("6@|underline 7890|@"), txt.substring(6)); assertEquals(ansi.new Text("@|underline 7890|@"), txt.substring(7)); assertEquals(ansi.new Text("@|underline 890|@"), txt.substring(8)); assertEquals(ansi.new Text("@|underline 90|@"), txt.substring(9)); assertEquals(ansi.new Text("@|underline 0|@"), txt.substring(10)); assertEquals(ansi.new Text(""), txt.substring(11)); assertEquals(ansi.new Text("@|bold 01234|@56@|underline 7890|@"), txt.substring(0, 11)); assertEquals(ansi.new Text("@|bold 01234|@56@|underline 789|@"), txt.substring(0, 10)); assertEquals(ansi.new Text("@|bold 01234|@56@|underline 78|@"), txt.substring(0, 9)); assertEquals(ansi.new Text("@|bold 01234|@56@|underline 7|@"), txt.substring(0, 8)); assertEquals(ansi.new Text("@|bold 01234|@56"), txt.substring(0, 7)); assertEquals(ansi.new Text("@|bold 01234|@5"), txt.substring(0, 6)); assertEquals(ansi.new Text("@|bold 01234|@"), txt.substring(0, 5)); assertEquals(ansi.new Text("@|bold 0123|@"), txt.substring(0, 4)); assertEquals(ansi.new Text("@|bold 012|@"), txt.substring(0, 3)); assertEquals(ansi.new Text("@|bold 01|@"), txt.substring(0, 2)); assertEquals(ansi.new Text("@|bold 0|@"), txt.substring(0, 1)); assertEquals(ansi.new Text(""), txt.substring(0, 0)); assertEquals(ansi.new Text("@|bold 1234|@56@|underline 789|@"), txt.substring(1, 10)); assertEquals(ansi.new Text("@|bold 234|@56@|underline 78|@"), txt.substring(2, 9)); assertEquals(ansi.new Text("@|bold 34|@56@|underline 7|@"), txt.substring(3, 8));
/** Returns a new {@code Text} instance that is a substring of this Text. Does not modify this instance! * @param start index in the plain text where to start the substring * @return a new Text instance that is a substring of this Text */ public Text substring(int start) { return substring(start, length); }