/** Replace one occurrence of the search string with the replacement string. */
  private static int replaceOne(
      View view,
      JEditBuffer buffer,
      SearchMatcher.Match occur,
      int offset,
      CharSequence found,
      boolean smartCaseReplace)
      throws Exception {
    String subst = replaceOne(view, buffer, occur, found);
    if (smartCaseReplace && ignoreCase) {
      int strCase = TextUtilities.getStringCase(found);
      if (strCase == TextUtilities.LOWER_CASE) subst = subst.toLowerCase();
      else if (strCase == TextUtilities.UPPER_CASE) subst = subst.toUpperCase();
      else if (strCase == TextUtilities.TITLE_CASE) subst = TextUtilities.toTitleCase(subst);
    }

    if (subst != null) {
      int start = offset + occur.start;
      int end = offset + occur.end;

      if (end - start > 0) buffer.remove(start, end - start);
      buffer.insert(start, subst);
      return subst.length();
    } else return -1;
  } // }}}
 public CloseBracketIndentRule(char closeBracket, boolean aligned) {
   super(TextUtilities.getComplementaryBracket(closeBracket, null), closeBracket);
   this.aligned = aligned;
 }
 /**
  * Returns if the replacement string will assume the same case as each specific occurrence of the
  * search string.
  *
  * @since jEdit 4.2pre10
  */
 public static boolean getSmartCaseReplace() {
   return (replace != null && TextUtilities.getStringCase(replace) == TextUtilities.LOWER_CASE);
 } // }}}
 private static String completeWord(String line, int offset, String noWordSep) {
   // '+ 1' so that findWordEnd() doesn't pick up the space at the start
   int wordEnd = TextUtilities.findWordEnd(line, offset + 1, noWordSep);
   return line.substring(offset, wordEnd);
 }