Java Code Examples for cn.hutool.core.util.ReUtil#replaceAll()

The following examples show how to use cn.hutool.core.util.ReUtil#replaceAll() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JsonBeautyListener.java    From MooTool with MIT License 5 votes vote down vote up
private static void find() {
    JsonBeautyForm jsonBeautyForm = JsonBeautyForm.getInstance();

    String content = jsonBeautyForm.getTextArea().getText();
    String findKeyWord = jsonBeautyForm.getFindTextField().getText();
    boolean isMatchCase = jsonBeautyForm.getFindMatchCaseCheckBox().isSelected();
    boolean isWords = jsonBeautyForm.getFindWordsCheckBox().isSelected();
    boolean useRegex = jsonBeautyForm.getFindUseRegexCheckBox().isSelected();

    int count;
    String regex = findKeyWord;

    if (!useRegex) {
        regex = ReUtil.escape(regex);
    }
    if (isWords) {
        regex = "\\b" + regex + "\\b";
    }
    if (!isMatchCase) {
        regex = "(?i)" + regex;
    }

    count = ReUtil.findAll(regex, content, 0).size();
    content = ReUtil.replaceAll(content, regex, "<span>$0</span>");

    FindResultForm.getInstance().getFindResultCount().setText(String.valueOf(count));
    FindResultForm.getInstance().setHtmlText(content);
    FindResultFrame.showResultWindow();
}
 
Example 2
Source File: JsonBeautyListener.java    From MooTool with MIT License 5 votes vote down vote up
private static void replace() {
    JsonBeautyForm jsonBeautyForm = JsonBeautyForm.getInstance();
    String target = jsonBeautyForm.getFindTextField().getText();
    String replacement = jsonBeautyForm.getReplaceTextField().getText();
    String content = jsonBeautyForm.getTextArea().getText();
    boolean isMatchCase = jsonBeautyForm.getFindMatchCaseCheckBox().isSelected();
    boolean isWords = jsonBeautyForm.getFindWordsCheckBox().isSelected();
    boolean useRegex = jsonBeautyForm.getFindUseRegexCheckBox().isSelected();

    String regex = target;

    if (!useRegex) {
        regex = ReUtil.escape(regex);
    }
    if (isWords) {
        regex = "\\b" + regex + "\\b";
    }
    if (!isMatchCase) {
        regex = "(?i)" + regex;
    }

    content = ReUtil.replaceAll(content, regex, replacement);

    jsonBeautyForm.getTextArea().setText(content);
    jsonBeautyForm.getTextArea().setCaretPosition(0);
    jsonBeautyForm.getScrollPane().getVerticalScrollBar().setValue(0);
    jsonBeautyForm.getScrollPane().getHorizontalScrollBar().setValue(0);
}
 
Example 3
Source File: QuickNoteListener.java    From MooTool with MIT License 5 votes vote down vote up
private static void find() {
    QuickNoteForm quickNoteForm = QuickNoteForm.getInstance();

    String content = quickNoteForm.getTextArea().getText();
    String findKeyWord = quickNoteForm.getFindTextField().getText();
    boolean isMatchCase = quickNoteForm.getFindMatchCaseCheckBox().isSelected();
    boolean isWords = quickNoteForm.getFindWordsCheckBox().isSelected();
    boolean useRegex = quickNoteForm.getFindUseRegexCheckBox().isSelected();

    int count;
    String regex = findKeyWord;

    if (!useRegex) {
        regex = ReUtil.escape(regex);
    }
    if (isWords) {
        regex = "\\b" + regex + "\\b";
    }
    if (!isMatchCase) {
        regex = "(?i)" + regex;
    }

    count = ReUtil.findAll(regex, content, 0).size();
    content = ReUtil.replaceAll(content, regex, "<span>$0</span>");

    FindResultForm.getInstance().getFindResultCount().setText(String.valueOf(count));
    FindResultForm.getInstance().setHtmlText(content);
    FindResultFrame.showResultWindow();
}
 
Example 4
Source File: QuickNoteListener.java    From MooTool with MIT License 5 votes vote down vote up
private static void replace() {
    QuickNoteForm quickNoteForm = QuickNoteForm.getInstance();
    String target = quickNoteForm.getFindTextField().getText();
    String replacement = quickNoteForm.getReplaceTextField().getText();
    String content = quickNoteForm.getTextArea().getText();
    boolean isMatchCase = quickNoteForm.getFindMatchCaseCheckBox().isSelected();
    boolean isWords = quickNoteForm.getFindWordsCheckBox().isSelected();
    boolean useRegex = quickNoteForm.getFindUseRegexCheckBox().isSelected();

    String regex = target;

    if (!useRegex) {
        regex = ReUtil.escape(regex);
    }
    if (isWords) {
        regex = "\\b" + regex + "\\b";
    }
    if (!isMatchCase) {
        regex = "(?i)" + regex;
    }

    content = ReUtil.replaceAll(content, regex, replacement);

    quickNoteForm.getTextArea().setText(content);
    quickNoteForm.getTextArea().setCaretPosition(0);
    quickNoteForm.getScrollPane().getVerticalScrollBar().setValue(0);
    quickNoteForm.getScrollPane().getHorizontalScrollBar().setValue(0);
}