Splits the cache in multiple lines to fit in the {@link #wrapSize}.

@param str the str
350040
private void buildLines()
	{
		wrapSize.update();
		buildLines |= wrapSize.hasChanged();
		if (!buildLines)
			return;

		lines.clear();

		String str = cache.replace("\r?(?<=\n)", "\n");

		StringBuilder line = new StringBuilder();
		StringBuilder word = new StringBuilder();
		//FontRenderOptions fro = new FontRenderOptions();

		int wrapWidth = multiLine ? getWrapSize() : -1;
		float lineWidth = 0;
		float wordWidth = 0;
		float lineHeight = 0;

		StringWalker walker = new StringWalker(str, fontOptions);
		walker.skipChars(false);
		walker.applyStyles(true);
		while (walker.walk())
		{
			char c = walker.getChar();
			lineWidth += walker.width();
			wordWidth += walker.width();
			lineHeight = Math.max(lineHeight, walker.height());

			word.append(c);

			//we just ended a new word, add it to the current line
			if (Character.isWhitespace(c) || c == '-' || c == '.')
			{
				line.append(word);
				word.setLength(0);
				wordWidth = 0;
			}
			if (isMultiLine() && ((wrapWidth > 0 && lineWidth >= wrapWidth) || c == '\n'))
			{
				//the first word on the line is too large, split anyway
				if (line.length() == 0)
				{
					line.append(word);
					word.setLength(0);
					wordWidth = 0;
				}

				//remove current word from last line
				lineWidth -= wordWidth;

				//add the new line
				lines.add(new LineInfo(line.toString(), MathHelper.ceil(lineWidth), MathHelper.ceil(lineHeight), 0));
				line.setLength(0);

				lineWidth = wordWidth;
			}
		}

		line.append(word);
		lines.add(new LineInfo(line.toString(), MathHelper.ceil(lineWidth), MathHelper.ceil(lineHeight), 0));

		buildLines = false;
		updateSize();
	}
223345
@SuppressWarnings("PMD.NcssCount")
  static String expandEscapedChars(String str) {
    StringBuilder builder = new StringBuilder();
    for (int i = 0; i < str.length(); ++i) {
      char c = str.charAt(i);
      if (c == '\\') {
        ++i;
        if (i >= str.length()) {
          throw error("dangling escape", str, i);
        }
        c = str.charAt(i);
        switch (c) {
          case 't': builder.append('\t'); break;
          case 'n': builder.append('\n'); break;
          case 'r': builder.append('\r'); break;
          case 'f': builder.append('\f'); break;
          case 'a': builder.append('\u0007'); break;
          case 'e': builder.append('\u001B'); break;
          case '0':
            int numDigits = 0;
            for (int j = i + 1; j < Math.min(i + 4, str.length()); ++j) {
              c = str.charAt(j);
              if (c >= '0' && c <= '7') {
                ++numDigits;
              } else {
                break;
              }
            }
            if (numDigits < 1 || numDigits > 3) {
              throw error("invalid octal escape sequence", str, i);
            }
            c = parse(str.substring(i + 1, i + numDigits + 1), 8, "octal", str, i);
            builder.append(c);
            i += numDigits;
            break;
          case 'x':
            if (i + 3 > str.length()) {
              throw error("invalid hexadecimal escape sequence", str, i);
            }
            c = parse(str.substring(i + 1, i + 3), 16, "hexadecimal", str, i);
            builder.append(c);
            i += 2;
            break;
          case 'u':
            if (i + 5 > str.length()) {
              throw error("invalid unicode escape sequence", str, i);
            }
            c = parse(str.substring(i + 1, i + 5), 16, "unicode", str, i);
            builder.append(c);
            i += 4;
            break;
          default:
            builder.append('\\').append(c);
            break;
        }
      } else {
        builder.append(c);
      }
    }
    return builder.toString();
  }
1186118
public void append(String str, int off, int len) throws IOException {
	append(str.substring(off, off + len));
    }
1258405
public void addString(String str) {
        if (mSize == mStrings.length) {
            String[] old = mStrings;
            int oldSize = old.length;
            mStrings = new String[oldSize + (oldSize << 1)];
            System.arraycopy(old, 0, mStrings, 0, oldSize);
        }
        mStrings[mSize++] = str;
    }
478869
public static String regexpReplace(String str, String regex, String replacement) {
		if (regex.isEmpty()) {
			return str;
		}
		try {
			// we should use StringBuffer here because Matcher only accept it
			StringBuffer sb = new StringBuffer();
			Matcher m = REGEXP_PATTERN_CACHE.get(regex).matcher(str);
			while (m.find()) {
				m.appendReplacement(sb, replacement);
			}
			m.appendTail(sb);
			return sb.toString();
		} catch (Exception e) {
			LOG.error(
				String.format("Exception in regexpReplace('%s', '%s', '%s')", str, regex, replacement),
				e);
			// return null if exception in regex replace
			return null;
		}
	}
999399
public static String[] split(String str, char separator) {
    final int len;
    if (str == null 
        || ((len = str.length()) == 0)) {
      return null;
    }

    List<String> componentList = new ArrayList<String>();
    int startIndex = 0;

    for (int i = 0; i < len; i++) {
      if (str.charAt(i) == separator) {
        componentList.add(str.substring(startIndex, i));
        startIndex = i + 1;
      }
    }

    if (str.charAt(len - 1) != separator) {
      componentList.add(str.substring(startIndex, len));
    }

    return componentList.toArray(new String[componentList.size()]);
  }
799901
public static List<String> split(
                    final String str
                    )
    {
        String  s = str;
        if (s != null) {
            s = s.trim();
        }

        List<String>  list = new ArrayList<String>();
        if (s == null || s.length() == 0) {
            return list;
        }

        String[]  tokens = s.split( "[ \t\n\r\f]" );
        // NOTE: tokens[i] may be an empty string "".

        // excludes empty strings.
        int  n_tokens = tokens.length;
        for (int  i = 0; i < n_tokens; i++) {
            if (tokens[i].length() > 0) {
                list.add( tokens[i] );
            }
        }

        return list;
    }
1264013
public static List<String> splitTrim(String str, char separator, boolean ignoreEmpty){
		return split(str, separator, 0, true, ignoreEmpty);
	}
825093
public static List<String> splitString( String string, int limit ) {
        List<String> list = new ArrayList<String>();

        char[] chars = string.toCharArray();
        boolean endOfString = false;
        int start = 0;
        int end = start;
        while( start < chars.length - 1 ) {
            int charCount = 0;
            int lastSpace = 0;
            while( charCount < limit ) {
                if (chars[charCount + start] == ' ') {
                    lastSpace = charCount;
                }
                charCount++;
                if (charCount + start == string.length()) {
                    endOfString = true;
                    break;
                }
            }
            end = endOfString ? string.length() : (lastSpace > 0) ? lastSpace + start : charCount + start;
            list.add(string.substring(start, end));
            start = end + 1;
        }
        return list;
    }
455573
private void addString(String str, OutputStream os) throws IOException {
		if (this.cacheSize >= 0) { // add to disk
			byte[] strbytes = str.getBytes(EncryptedCachedDiskStringsTable.encoding);
			byte[] sizeOfStr = ByteBuffer.allocate(4).putInt(strbytes.length).array();
			this.stringPositionInFileList.add(this.tempFileSize);
			if (os != null) {
				os.write(sizeOfStr);
				os.write(strbytes);
			} else { // we can write to the random access file
				FileChannel fc = this.tempRAF.getChannel().position(this.tempFileSize);
				fc.write(ByteBuffer.wrap(sizeOfStr));
				fc.write(ByteBuffer.wrap(strbytes));
			}
			this.tempFileSize += sizeOfStr.length + strbytes.length;
		}
		if (this.cacheSize < 0) { // put it into cache
			this.cache.put(this.currentItem, str);
			this.currentItem++;
		} else if ((this.cacheSize > 0) && (this.currentItem < this.cacheSize)) { // put the first items already into
																					// cache
			this.cache.put(this.currentItem, str);
			this.currentItem++;
		}
	}
1050188
public static Long parseLong(final String str) {
        if (null != str) {
            try {
                return new Long(Long.parseLong(str.trim()));
            } catch (final Exception e) {
                // :IGNORE:
            }
        }
        return null;
    }
789823
public static long parseLong(final String str, final long def) {
        final Long ret = parseLong(str);
        if (ret == null) {
            return def;
        } else {
            return ret.longValue();
        }
    }
532807
public static String[] splitString(final String str, final char splitChar) {
    final int length = str.length();
    final StringBuilder bulder = new StringBuilder(Math.max(8, length));

    int counter = 1;
    for (int i = 0; i < length; i++) {
      if (str.charAt(i) == splitChar) {
        counter++;
      }
    }

    final String[] result = new String[counter];

    int position = 0;
    for (int i = 0; i < length; i++) {
      final char chr = str.charAt(i);
      if (chr == splitChar) {
        result[position++] = bulder.toString();
        bulder.setLength(0);
      } else {
        bulder.append(chr);
      }
    }
    if (position < result.length) {
      result[position] = bulder.toString();
    }

    return result;
  }
1132325
public void parse(String str) {
		if (buffer.length() > 0) {
			str = buffer.toString().concat(str);
			buffer = new StringBuilder();
		}
		Reader reader = new StringReader(str);
		try {
			try {
				parse(reader);
			} finally {
				reader.close();
			}
		} catch (IOException ex) {
			/* ignore */
		}
	}
1084485
public void append(String str, int off, int len) {
	int restLength = buffer.length - pos;
	if (len < restLength) {
	    str.getChars(off, off + len, buffer, pos);
	    pos += len;
	}
	else {
	    str.getChars(off, off + restLength, buffer, pos);
	    curr.next = new Entity(buffer);
	    curr = curr.next;
	    length += buffer.length;
	    buffer = new char[(buffer.length > len - restLength) ? buffer.length : len - restLength];

	    str.getChars(off + restLength, off + len, buffer, 0);
	    pos = len - restLength;

	}
    }
756539
public List<String> splitLimit(String str, String regex, int limit) {
		if (str == null || regex == null)
			return new ArrayList<String>();
		return Arrays.asList(str.split(regex, limit));
	}
686544
public static List<String> split(@Nullable final String str, final char separatorChar) {
		return split(str, separatorChar, 10);
	}