package org.codelibs.analysis.ja;

import java.io.Reader;
import java.lang.Character.UnicodeBlock;

public class ProlongedSoundMarkCharFilter extends BufferedCharFilter {

    private static final char U002D = '\u002d'; // HYPHEN-MINUS

    private static final char UFF0D = '\uff0d'; // FULLWIDTH HYPHEN-MINUS

    private static final char U2010 = '\u2010'; // HYPHEN

    private static final char U2011 = '\u2011'; // NON-BREAKING HYPHEN

    private static final char U2012 = '\u2012'; // FIGURE DASH

    private static final char U2013 = '\u2013'; // EN DASH

    private static final char U2014 = '\u2014'; // EM DASH

    private static final char U2015 = '\u2015'; // HORIZONTAL BAR

    private static final char U207B = '\u207b'; // SUPERSCRIPT MINUS

    private static final char U208B = '\u208b'; // SUBSCRIPT MINUS

    private static final char U30FC = '\u30fc'; // KATAKANA-HIRAGANA SOUND MARK

    public ProlongedSoundMarkCharFilter(final Reader in) {
        super(in);
    }

    @Override
    CharSequence processInput(final CharSequence input) {
        final StringBuilder buf = new StringBuilder(input.length());
        final int pos = 0;
        char prev = 0;
        while (pos < input.length()) {
            final char c = input.charAt(pos);
            switch (c) {
            case U002D:
            case UFF0D:
            case U2010:
            case U2011:
            case U2012:
            case U2013:
            case U2014:
            case U2015:
            case U207B:
            case U208B:
                if (prev != 0) {
                    final UnicodeBlock block = UnicodeBlock.of(prev);
                    if (block == UnicodeBlock.HIRAGANA
                            || block == UnicodeBlock.KATAKANA
                            || block == UnicodeBlock.KATAKANA_PHONETIC_EXTENSIONS) {
                        buf.append(U30FC);
                    } else {
                        buf.append(c);
                    }
                } else {
                    buf.append(c);
                }
                break;
            default:
                buf.append(c);
                break;
            }
            prev = c;
        }
        return buf;
    }

}

@@ -906,16 +906,53 @@
 D MARK%0A%0A
+    private final char replacement;%0A%0A
     publ
@@ -1014,17 +1014,172 @@
     
-super(in)
+this(in, U30FC);%0A    %7D%0A%0A    public ProlongedSoundMarkCharFilter(final Reader in, final char replacement) %7B%0A        super(in);%0A        this.replacement = replacement
 ;%0A  
@@ -1336,21 +1336,17 @@
     
-final int pos
+char prev
  = 0
@@ -1359,38 +1359,26 @@
     
-char prev = 0;%0A        while (
+for (int pos = 0; 
 pos 
@@ -1393,16 +1393,23 @@
 length()
+; pos++
 ) %7B%0A    
@@ -1715,16 +1715,40 @@
  U208B:%0A
+            case U30FC:%0A
         
@@ -2079,21 +2079,27 @@
 .append(
-U30FC
+replacement
 );%0A     

add replacement property