Example #1
0
  /**
   * Turns the entry to UPPERCASE, takes sequences of non-alphanumeric characters out of it
   * (replacing them with a single whitespace) and sees that the entry is trimmed off leading and
   * trailing whitespaces.
   */
  private String fit(String input, Mapper mapper) {
    input = input.toUpperCase();
    Matcher matcher = fitting.matcher(input);

    StringBuffer buffer = new StringBuffer();
    while (!matcher.hitEnd() && matcher.find()) {
      mapper.prepare(input, matcher.group(), " ");
      mapper.update(matcher.start());
      matcher.appendReplacement(buffer, " ");
    }

    matcher.appendTail(buffer);
    return buffer.toString();
  }
Example #2
0
  private String substitute(String input, Mapper mapper) {
    StringBuffer buffer = new StringBuffer();
    for (String find : correction.keySet()) {
      Pattern pattern = Pattern.compile(find, CASE_INSENSITIVE | UNICODE_CASE);
      Matcher matcher = pattern.matcher(input);
      String replace = correction.get(find);

      mapper.prepare(input, find, replace);
      while (!matcher.hitEnd() && matcher.find()) {
        mapper.update(matcher.start() + 1);
        matcher.appendReplacement(buffer, replace);
      }

      matcher.appendTail(buffer);
      input = buffer.toString();
      buffer.delete(0, buffer.length());
    }

    return input;
  }