normalizeHebrewQuote method

String normalizeHebrewQuote (String str)

Replace the double and single quote directly after a Hebrew character in str with GERESH and GERSHAYIM. This is most likely the user's intention.

Implementation

static String normalizeHebrewQuote(String str) {
  StringBuffer buf = new StringBuffer();
  if (str.length > 0) {
    buf.write(str.substring(0, 1));
  }
  // Start at 1 because we're looking for the patterns [\u0591-\u05f2])" or
  // [\u0591-\u05f2]'.
  for (int i = 1; i < str.length; i++) {
    if (str.substring(i, i + 1) == '"' &&
        new RegExp('[\u0591-\u05f2]').hasMatch(str.substring(i - 1, i))) {
      buf.write('\u05f4');
    } else if (str.substring(i, i + 1) == "'" &&
        new RegExp('[\u0591-\u05f2]').hasMatch(str.substring(i - 1, i))) {
      buf.write('\u05f3');
    } else {
      buf.write(str.substring(i, i + 1));
    }
  }
  return buf.toString();
}