if(lineLength + word.length() >= maxLineLength) buf.append('\n'); else if(space) buf.append(' ');
	private String doFormat(String text, int maxLineLength)	{		StringBuffer buf = new StringBuffer();		StringBuffer word = new StringBuffer();		int lineLength = 0;		boolean newline = true;		boolean newlineIgnore = false;		boolean space = true;		char[] chars = text.toCharArray();		for(int i = 0; i < chars.length; i++)		{			char c = chars[i];			lineLength++;			switch(c)			{			case '\n':				buf.append(word);				word.setLength(0);				boolean oldSpace = space;				space = true;				if(i == 0)				{					buf.append('\n');					newline = false;					newlineIgnore = true;					break;				}				if(newlineIgnore)				{					lineLength--;					break;				}				if(newline || i == chars.length - 2)				{					// already seen a newline.					// start a new paragraph					buf.append("\n\n");					newline = false;					newlineIgnore = true;					lineLength = 0;					break;				}				if(lineLength >= maxLineLength ||					i == chars.length - 1)				{					buf.append('\n');					newline = false;					newlineIgnore = false;					lineLength = 0;					break;				}				newline = true;				newlineIgnore = false;				if(!oldSpace)					buf.append(' ');				break;			case ' ':				if(space)				{					lineLength--;					break;				}				buf.append(word);				word.setLength(0);				buf.append(' ');				space = true;				break;			default:				newline = newlineIgnore = space = false;				word.append(c);				// do word wrap				if(lineLength >= maxLineLength)				{					buf.append('\n');					lineLength = word.length();				}				break;			}		}		buf.append(word);		return buf.toString();	}