public static String replaceInvalidChars(String str, boolean replaceWithUnderscore) {
		if (str == null) {
			return null;
		}
		int len = str.length();
		StringBuilder buf = new StringBuilder(len);
		for (int i = 0; i < len; ++i) {
			char c = str.charAt(i);
			if (isInvalidChar(c)) {
				if (replaceWithUnderscore) {
					buf.append(UNDERSCORE);
				}
			}
			else {
				buf.append(c);
			}
		}
		return buf.toString();
	}
Removes from the given string any invalid characters or replaces
them with underscores.

For example:
given "a:b*c", the return value would be "a_b_c"

@param str the string to have invalid chars converted to underscores or removed.
@param replaceWithUnderscore - true means replace the invalid
chars with underscore. if false, then just drop the invalid chars
@return modified string
Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/symbol/SymbolUtilities.java