/** * Escape comment text for HTML. If nice is set, also turn `` into “ and '' into ”. */ private static String emphasize(@NotNull String text, boolean nice) { text = XmlStringUtil.escapeString(text); StringBuilder textWithLinks = null; Matcher matcher = URLUtil.URL_PATTERN.matcher(text); while (matcher.find()) { if (textWithLinks == null) { textWithLinks = new StringBuilder(); } textWithLinks.append(text.substring(0, matcher.start())) .append("<a href=\"").append(matcher.group()).append("\">").append(matcher.group()).append("</a>"); } if (textWithLinks != null) { text = textWithLinks.toString(); } return nice ? StringUtil.replace(text, new String[]{"``", "''"}, new String[]{"“", "”"}) : text; }
public String expandMacros(String text) { final Map<String, String> macroMap = getMacroMap(); final Set<String> set = macroMap.keySet(); for (final String from : set) { final String to = macroMap.get(from); text = StringUtil.replace(text, from, to, true); } return text; }
private void doTest(@NotNull String text) { List<Integer> offsets = allOccurrences(StringUtil.replace(text, "<caret>", ""), USAGE); String replace = StringUtil.replace(text, USAGE, ""); myFixture.configureByText("a.go", replace); PsiElement atCaret = myFixture.getElementAtCaret(); List<Integer> actual = ContainerUtil.map(myFixture.findUsages(atCaret), UsageInfo::getNavigationOffset); assertSameElements(actual, offsets); }
entry = StringUtil.replace(entry, "\r", ""); if (!StringUtil.isEmpty(entry)) { entry += Constants.NEWLINE;
private static String convertToJavaPattern(String wildcardPattern) { wildcardPattern = StringUtil.replace(wildcardPattern, ".", "\\."); wildcardPattern = StringUtil.replace(wildcardPattern, "*?", ".+"); wildcardPattern = StringUtil.replace(wildcardPattern, "?*", ".+"); wildcardPattern = StringUtil.replace(wildcardPattern, "*", ".*"); wildcardPattern = StringUtil.replace(wildcardPattern, "?", "."); return wildcardPattern; } }
private static String substituteMacrosWithRegexps(String expression) { int filePathIndex = expression.indexOf(FILE_PATH_MACROS); int lineIndex = expression.indexOf(LINE_MACROS); int columnIndex = expression.indexOf(COLUMN_MACROS); if (filePathIndex == -1) { throw new InvalidExpressionException("Expression must contain " + FILE_PATH_MACROS + " macros."); } expression = StringUtil.replace(expression, FILE_PATH_MACROS, FILE_PATH_REGEXP); if (lineIndex != -1) { expression = StringUtil.replace(expression, LINE_MACROS, NUMBER_REGEXP); } if (columnIndex != -1) { expression = StringUtil.replace(expression, COLUMN_MACROS, NUMBER_REGEXP); } return expression; }
@NotNull @Contract(pure = true) public static String replace(@NotNull String text, @NotNull String[] from, @NotNull String[] to) { return replace(text, Arrays.asList(from), Arrays.asList(to)); }
@Contract(value = "null -> null; !null -> !null",pure = true) public static String unescapeXml(@Nullable final String text) { if (text == null) return null; return replace(text, REPLACES_REFS, REPLACES_DISP); }
@Contract(value = "null -> null; !null -> !null",pure = true) public static String escapeXml(@Nullable final String text) { if (text == null) return null; return replace(text, REPLACES_DISP, REPLACES_REFS); }
@Contract(value = "null -> null; !null -> !null", pure = true) public static String escapeMnemonics(@Nullable String text) { if (text == null) return null; return replace(text, MN_CHARS, MN_QUOTED); }
static void formatLink(@NotNull StringBuilder builder, @NotNull String fragment, @NotNull SimpleTextAttributes attributes, @NotNull String url) { if (!fragment.isEmpty()) { builder.append("<a href=\"").append(StringUtil.replace(url, "\"", "%22")).append("\""); formatStyle(builder, attributes); builder.append('>').append(convertFragment(fragment)).append("</a>"); } }
/** * @return list of images in {@code name[:tag]} format */ List<String> listImages() throws ExecutionException { ProcessOutput output = runCommand(IMAGE, LIST_IMAGE, IN_FORMAT, "{{.Repository}}:{{.Tag}}"); return output.getStdoutLines().stream() .map(it -> StringUtil.replace(it, ":<none>", "")) .filter(it -> !StringUtil.equals(it, "<none>")) .sorted().collect(Collectors.toList()); }
@NotNull @Contract(pure = true) public static String replaceIgnoreCase(@NonNls @NotNull String text, @NonNls @NotNull String oldS, @NonNls @NotNull String newS) { return replace(text, oldS, newS, true); }
@NotNull @Contract(pure = true) public static String replace(@NonNls @NotNull String text, @NonNls @NotNull String oldS, @NonNls @NotNull String newS) { return replace(text, oldS, newS, false); }
expression = StringUtil.replace(expression, FILE_PATH_MACROS, FILE_PATH_REGEXP); expression = StringUtil.replace(expression, LINE_MACROS, NUMBER_REGEXP); map.put(new Integer(lineIndex), LINE_STR); expression = StringUtil.replace(expression, COLUMN_MACROS, NUMBER_REGEXP); map.put(new Integer(columnIndex), COLUMN_STR);
private String escape(String text) { return StringUtil.replace(StringUtil.escapeChars(text, '"'), "\n", "\\n"); }
content = StringUtil.replace(content, "\r", ""); // for MACs
protected void testFoldingRegions(@NotNull String verificationFileName, boolean doCheckCollapseStatus, LanguageFileType fileType) { String expectedContent; try { expectedContent = FileUtil.loadFile(new File(getTestDataPath() + "/" + verificationFileName + ".code")); } catch (IOException e) { throw new RuntimeException(e); } Assert.assertNotNull(expectedContent); expectedContent = StringUtil.replace(expectedContent, "\r", ""); final String cleanContent = expectedContent.replaceAll(START_FOLD, "").replaceAll(END_FOLD, ""); myFixture.configureByText(fileType, cleanContent); final String actual = ((CodeInsightTestFixtureImpl)myFixture).getFoldingDescription(doCheckCollapseStatus); Assert.assertEquals(expectedContent, actual); }