Here you can find the source of removeExtraPunctuation(String line, int startChar, ArrayList
Parameter | Description |
---|---|
line | the text to remove punctuation from |
startChar | where this line starts relative to an entire passage |
indices | an ArrayList of Integers which represent the indices of any characters which are removed by the method |
private static String removeExtraPunctuation(String line, int startChar, ArrayList<Integer> indices)
//package com.java2s; //License from project: BSD License import java.util.ArrayList; public class Main { /**// w ww .j a va2 s. com * Removes extra punctuation from the passed text that are found in quotations or parentheses. * Updates the passed ArrayList to include the indices of any removed characters in order. * * @param line the text to remove punctuation from * @param startChar where this line starts relative to an entire passage * @param indices an ArrayList of Integers which represent the indices of any characters which are removed by the method * @return a String which is the same line without the extra punctuation */ private static String removeExtraPunctuation(String line, int startChar, ArrayList<Integer> indices) { StringBuffer buffer = new StringBuffer(line); boolean inParentheses = false; for (int i = 0; i < buffer.length(); i++) { char c = buffer.charAt(i); if (c == ')') inParentheses = false; if (inParentheses || c == '[' || c == ']' || c == '/') indices.add(startChar + i); if (c == '(') inParentheses = true; if (c == '.' && i + 2 < buffer.length() && buffer.charAt(i + 1) == '.' && buffer.charAt(i + 2) == '.') { indices.add(startChar + i); indices.add(startChar + i + 1); indices.add(startChar + i + 2); i += 2; } } for (int j = 0; j < indices.size(); j++) buffer.deleteCharAt(indices.get(j) - j - startChar); return buffer.toString(); } }