/** Returns a copy of this {@code Text} instance with the specified text concatenated to the end. Does not modify this instance! * @param other the text to concatenate to the end of this Text * @return a new Text instance * @since 3.0 */ public Text concat(Text other) { Text result = (Text) clone(); result.plain = new StringBuilder(plain.toString().substring(from, from + length)); result.from = 0; result.sections = new ArrayList<StyledSection>(); for (StyledSection section : sections) { result.sections.add(section.withStartIndex(section.startIndex - from)); } result.plain.append(other.plain.toString().substring(other.from, other.from + other.length)); for (StyledSection section : other.sections) { int index = result.length + section.startIndex - other.from; result.sections.add(section.withStartIndex(index)); } result.length = result.plain.length(); return result; }
/** Returns a copy of this {@code Text} instance with the specified text concatenated to the end. Does not modify this instance! * @param other the text to concatenate to the end of this Text * @return a new Text instance * @since 3.0 */ public Text concat(Text other) { Text result = (Text) clone(); result.plain = new StringBuilder(plain.toString().substring(from, from + length)); result.from = 0; result.sections = new ArrayList<StyledSection>(); for (StyledSection section : sections) { result.sections.add(section.withStartIndex(section.startIndex - from)); } result.plain.append(other.plain.toString().substring(other.from, other.from + other.length)); for (StyledSection section : other.sections) { int index = result.length + section.startIndex - other.from; result.sections.add(section.withStartIndex(index)); } result.length = result.plain.length(); return result; }
/** 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 * @param end index in the plain text where to end the substring * @return a new Text instance that is a substring of this Text */ public Text substring(int start, int end) { Text result = (Text) clone(); result.from = from + start; result.length = end - start; return result; } /** @deprecated use {@link #concat(String)} instead */
/** 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 * @param end index in the plain text where to end the substring * @return a new Text instance that is a substring of this Text */ public Text substring(int start, int end) { Text result = (Text) clone(); result.from = from + start; result.length = end - start; return result; } /** @deprecated use {@link #concat(String)} instead */