public static final String replaceTabsWithSpaces(String text,
			int tabSize) {

		String tabText = "";
		for (int i=0; i<tabSize; i++) {
			tabText += ' ';
		}

		// Common case: User's entering a single tab (pressed the tab key).
		if (text.length()==1) {
			return tabText;
		}

		// Otherwise, there may be more than one tab.  Manually search for
		// tabs for performance, as opposed to using String#replaceAll().
		// This method is called for each character inserted when "replace
		// tabs with spaces" is enabled, so we need to be quick.

		//return text.replaceAll("\t", tabText);
		if (repTabsSB==null) {
			repTabsSB = new StringBuffer();
		}
		repTabsSB.setLength(0);
		char[] array = text.toCharArray(); // Wouldn't be needed in 1.5!
		int oldPos = 0;
		int pos = 0;
		while ((pos=text.indexOf('\t', oldPos))>-1) {
			//repTabsSB.append(text, oldPos, pos); // Added in Java 1.5
			if (pos>oldPos) {
				repTabsSB.append(array, oldPos, pos-oldPos);
			}
			repTabsSB.append(tabText);
			oldPos = pos + 1;
		}
		if (oldPos<array.length) {
			repTabsSB.append(array, oldPos, array.length-oldPos);
		}

		return repTabsSB.toString();

	}