public static String wrapToCharacterCount(String text, int charCount) {
		StringBuilder buffer = new StringBuilder(text.length() * 2);
		StringBuilder lineBuffer = new StringBuilder(charCount + 1);
		StringTokenizer tokenizer = new StringTokenizer(text + NEWLINE, NEWLINE, true);

		while (tokenizer.hasMoreTokens()) {
			String token = tokenizer.nextToken();

			if (token.equals(NEWLINE)) {
				buffer.append(token);
			} else {
				StringTokenizer tokenizer2 = new StringTokenizer(token, " \t", true); //$NON-NLS-1$
				int length = 0;

				lineBuffer.setLength(0);
				while (tokenizer2.hasMoreTokens()) {
					String token2 = tokenizer2.nextToken();
					int tokenLength = token2.length();

					if (length == 0 && token2.equals(SPACE)) {
						continue;
					}
					if (length == 0 || length + tokenLength <= charCount) {
						lineBuffer.append(token2);
						length += tokenLength;
					} else {
						buffer.append(lineBuffer);
						buffer.append(NEWLINE);
						lineBuffer.setLength(0);
						if (!token2.equals(SPACE)) {
							lineBuffer.append(token2);
							length = tokenLength;
						} else {
							length = 0;
						}
					}
				}
				if (length > 0) {
					buffer.append(lineBuffer);
				}
			}
		}
		buffer.setLength(buffer.length() - 1);
		return buffer.toString();
	}