9 package javolution.text;
11 import java.io.PrintStream;
112 private Text(
boolean isPrimitive) {
129 _head =
new Text(str.substring(0, half));
152 str.getChars(start, end, text.
_data, 0);
184 if ((offset < 0) || (
length < 0) || ((offset +
length) > chars.length))
185 throw new IndexOutOfBoundsException();
188 System.arraycopy(chars, offset, text.
_data, 0,
length);
335 public static Text valueOf(
double d,
int digits,
boolean scientific,
338 return tb.
append(d, digits, scientific, showZero).
toText();
375 int length = str.length();
423 && (head.
_data ==
null)) {
493 public Text delete(
int start,
int end) {
495 throw new IndexOutOfBoundsException();
508 java.lang.CharSequence replacement) {
510 return (i < 0) ? this :
526 return (i < 0) ? this :
552 public int indexOf(java.lang.CharSequence csq) {
567 public int indexOf(java.lang.CharSequence csq,
int fromIndex) {
570 final int csqLength = csq.length();
571 final int min = Math.max(0, fromIndex);
572 final int max =
_count - csqLength;
573 if (csqLength == 0) {
return (min > max) ? -1 : min; }
576 final char c = csq.charAt(0);
577 for (
int i =
indexOf(c, min); (i >= 0) && (i <= max); i =
indexOf(c,
579 boolean match =
true;
580 for (
int j = 1; j < csqLength; j++) {
581 if (this.
charAt(i + j) != csq.charAt(j)) {
586 if (match) {
return i; }
613 public int lastIndexOf(java.lang.CharSequence csq,
int fromIndex) {
616 final int csqLength = csq.length();
618 final int max = Math.min(fromIndex,
_count - csqLength);
619 if (csqLength == 0) {
return (min > max) ? -1 : max; }
622 final char c = csq.charAt(0);
624 boolean match =
true;
625 for (
int j = 1; j < csqLength; j++) {
626 if (this.
charAt(i + j) != csq.charAt(j)) {
631 if (match) {
return i; }
657 public boolean endsWith(java.lang.CharSequence suffix) {
669 public boolean startsWith(java.lang.CharSequence prefix,
int index) {
670 final int prefixLength = prefix.length();
671 if ((index >= 0) && (index <= (this.
length() - prefixLength))) {
672 for (
int i = 0, j = index; i < prefixLength;) {
673 if (prefix.charAt(i++) !=
this.charAt(j++)) {
return false; }
692 while ((first <= last) && (
charAt(first) <=
' ')) {
695 while ((last >= first) && (
charAt(last) <=
' ')) {
698 return subtext(first, last + 1);
709 return txt ==
null ? this : txt;
721 if (csq.length() !=
_count)
723 for (
int i = 0; i <
_count;) {
724 if (this.
charAt(i) != csq.charAt(i++))
739 if (this._count != csq.length())
741 for (
int i = 0; i <
_count;) {
743 char u2 = csq.charAt(i++);
745 u1 = Character.toUpperCase(u1);
746 u2 = Character.toUpperCase(u2);
748 && (Character.toLowerCase(u1) != Character
772 if (!(obj instanceof
Text))
775 if (this._count != that.
_count)
777 for (
int i = 0; i <
_count;) {
793 for (
int i = 0; i <
length;) {
831 out.print(
"LENGTH: " +
length());
832 out.print(
", MAX DEPTH: " +
getDepth());
834 out.print(
", NBR OF LEAVES: " + leaves);
835 out.print(
", AVG LEAVE LENGTH: " + (
length + (leaves >> 1))
867 for (
int i = 0; i <
_count;) {
868 text.
_data[i] = Character.toLowerCase(
_data[i++]);
883 for (
int i = 0; i <
_count;) {
884 text.
_data[i] = Character.toUpperCase(
_data[i++]);
899 throw new IndexOutOfBoundsException();
936 if (fromIndex < cesure) {
941 final int tailIndex =
_tail.
indexOf(c, fromIndex - cesure);
942 return (tailIndex >= 0) ? tailIndex + cesure : -1;
966 if (fromIndex >= cesure) {
969 return tailIndex + cesure;
987 if ((start < 0) || (start > end) || (end >
_count))
988 throw new IndexOutOfBoundsException();
989 if ((start == 0) && (end ==
_count))
1001 if (start >= cesure)
1003 if ((start == 0) && (end ==
_count))
1022 public void getChars(
int start,
int end,
char dest[],
int destPos) {
1023 if (
_data !=
null) {
1024 if ((start < 0) || (end >
_count) || (start > end))
1025 throw new IndexOutOfBoundsException();
1026 System.arraycopy(
_data, start, dest, destPos, end - start);
1029 if (end <= cesure) {
1031 }
else if (start >= cesure) {
1032 _tail.
getChars(start - cesure, end - cesure, dest, destPos);
1035 _tail.
getChars(0, end - cesure, dest, destPos + cesure - start);
1046 if (
_data !=
null) {
1049 char[] data =
new char[
_count];
1051 return new String(data, 0,
_count);
1057 if (
_data !=
null) {
1080 throw new IndexOutOfBoundsException();
1083 for (
int i = 0; i <
length;) {
1084 text.
_data[i++] = c;
1088 final int middle = (
length >> 1);
1112 for (; start <
length; start++) {
1128 while ((first <= last) && (
charAt(first) <=
' ')) {
1131 return subtext(first, last + 1);
1144 while ((last >= first) && (
charAt(last) <=
' ')) {
1147 return subtext(first, last + 1);
1177 final int padSize = (len <=
length()) ? 0 : len -
length();
1208 final int padSize = (len <=
length()) ? 0 : len -
length();
1248 final int stop = start +
length;
1249 for (
int i = start; i < stop; i++) {
1292 for (
int i = start +
length; --i >= start;) {