// TODO :: improve speed by not calling substring but keeping track of start!
private static String addAfterLinesContainingEx(String origStr, String findThis, String addThat,
		String eolMarker, boolean notInsideTag) {
		if (origStr == null) {
			return null;
		}
		if (findThis == null) {
			return origStr;
		}
		if ((addThat == null) || "".equals(addThat)) {
			return origStr;
		}
		if ((eolMarker == null) || "".equals(eolMarker)) {
			return origStr;
		}
		if ("".equals(findThis)) {
			return replaceAll(origStr, "\n", "\n" + addThat) + "\n" + addThat;
		}
		StringBuilder result = new StringBuilder();
		int index = origStr.indexOf(findThis);
		while (index >= 0) {
			if (notInsideTag) {
				if ((index > 0) && origStr.charAt(index - 1) == '>') {
					index = origStr.indexOf(findThis, index + 1);
					continue;
				}
			}
			int eol = origStr.indexOf(eolMarker, index);
			if (eol < 0) {
				result.append(origStr);
				result.append(eolMarker);
				origStr = "";
			} else {
				result.append(origStr.substring(0, eol + eolMarker.length()));
				// TODO :: improve speed by not calling substring but keeping track of start!
				origStr = origStr.substring(eol + eolMarker.length());
			}
			result.append(addThat);
			index = origStr.indexOf(findThis);
		}
		result.append(origStr);
		return result.toString();
	}
} else {
result.append(origStr.substring(0, eol + eolMarker.length()));
// TODO :: improve speed by not calling substring but keeping track of start!
origStr = origStr.substring(eol + eolMarker.length());
}
continue;
}
}
int eol = origStr.indexOf(eolMarker, index);
if (eol < 0) {
result.append(origStr);
result.append(eolMarker);
origStr = "";
} else {
result.append(origStr.substring(0, eol + eolMarker.length()));
// TODO :: improve speed by not calling substring but keeping track of start!
origStr = origStr.substring(eol + eolMarker.length());
}
result.append(addThat);
index = origStr.indexOf(findThis);
}
result.append(origStr);
return result.toString();
}
}
if ("".equals(findThis)) {
return replaceAll(origStr, "\n", "\n" + addThat) + "\n" + addThat;
}
StringBuilder result = new StringBuilder();
int index = origStr.indexOf(findThis);
while (index >= 0) {
if (notInsideTag) {
if ((index > 0) && origStr.charAt(index - 1) == '>') {
index = origStr.indexOf(findThis, index + 1);
continue;
}
}
int eol = origStr.indexOf(eolMarker, index);
if (eol < 0) {
result.append(origStr);
result.append(eolMarker);
origStr = "";
} else {
result.append(origStr.substring(0, eol + eolMarker.length()));
// TODO :: improve speed by not calling substring but keeping track of start!
origStr = origStr.substring(eol + eolMarker.length());
}
result.append(addThat);
index = origStr.indexOf(findThis);
}
result.append(origStr);
return result.toString();
}