Java ArrayList Remove removeExtraPunctuation(String line, int startChar, ArrayList indices)

Here you can find the source of removeExtraPunctuation(String line, int startChar, ArrayList indices)

Description

Removes extra punctuation from the passed text that are found in quotations or parentheses.

License

BSD License

Parameter

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

Return

a String which is the same line without the extra punctuation

Declaration

private static String removeExtraPunctuation(String line, int startChar, ArrayList<Integer> indices) 

Method Source Code


//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();
    }
}

Related

  1. removeByReference(ArrayList list, T object)
  2. removeDuplicates(ArrayList al)
  3. removeDuplicates(ArrayList a)
  4. removeDuplicateWithOrder(List arrayList)
  5. removeElementsFromIndexToEnd(ArrayList list, int index)
  6. removeIndex(ArrayList arr, ArrayList idNames)
  7. removeLastValues(final ArrayList v, final int remove)
  8. removeNulls(ArrayList list)
  9. removeRepeatedElems(ArrayList list)