String (@NotNull String text, boolean allowDots, boolean allowSpaces) { StringBuilder result = new StringBuilder(); for (int i = 0; i < text.length(); i++) { char c = text.charAt(i); if (!isValidFileNameChar(c, Platform.CURRENT, true) || (!allowDots && c == '.') || (!allowSpaces && Character.isWhitespace(c))) { result.append('_'); } else { result.append(c); } } return result.toString(); }