/* LanguageTool, a natural language style checker 
 * Copyright (C) 2005 Daniel Naber (http://www.danielnaber.de)
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
 * USA
 */
package de.danielnaber.languagetool.rules.de;

import java.util.ArrayList;
import java.util.List;

import de.danielnaber.languagetool.AnalyzedSentence;
import de.danielnaber.languagetool.AnalyzedTokenReadings;
import de.danielnaber.languagetool.rules.RuleMatch;

/**
 * Prüft, dass in Bindestrich-Komposita kein Leerzeichen eingefügt wird (wie z.B. in 'Diäten- Erhöhung').
 *   
 * @author Daniel Naber
 */
public class DashRule extends GermanRule {

  public DashRule() {
  }
  
  public String getId() {
    return "DE_DASH";
  }

  public String getDescription() {
    return "Keine Leerzeichen in Bindestrich-Komposita (wie z.B. in 'Diäten- Erhöhung')";
  }

  public RuleMatch[] match(AnalyzedSentence text) {
    List<RuleMatch> ruleMatches = new ArrayList<RuleMatch>();
    AnalyzedTokenReadings[] tokens = text.getTokensWithoutWhitespace();
    int pos = 0;
    String prevToken = null;
    for (int i = 0; i < tokens.length; i++) {
      String token = tokens[i].getToken();
      if (token.trim().equals("")) {
        // ignore
        continue;
      } else {
        if (prevToken != null && !prevToken.equals("-") && prevToken.indexOf("--") == -1 && prevToken.endsWith("-")) {
          char firstChar = token.charAt(0);
          if (Character.isUpperCase(firstChar)) {
            String msg = "Möglicherweise fehlt ein 'und' oder es wurde nach dem Wort " +
                    "ein überflüssiges Leerzeichen eingefügt.";
            RuleMatch ruleMatch = new RuleMatch(this, tokens[i-1].getStartPos(),
                tokens[i-1].getStartPos()+prevToken.length(), msg);
            ruleMatches.add(ruleMatch);
          }
        }
      }
      prevToken = token;
      pos += token.length();
    }
    return toRuleMatchArray(ruleMatches);
  }

  public void reset() {
    // nothing
  }

}

@@ -1126,17 +1126,22 @@
 **%0A * Pr
-%C3%BC
+&uuml;
 ft, dass
@@ -1189,17 +1189,22 @@
 n eingef
-%C3%BC
+&uuml;
 gt wird 
@@ -1215,33 +1215,38 @@
  z.B. in 'Di
-%C3%A4
+&auml;
 ten- Erh
 %C3%B6hung').%0A * 
@@ -1229,25 +1229,30 @@
 uml;ten- Erh
-%C3%B6
+&ouml;
 hung').%0A *  
@@ -2457,16 +2457,18 @@
 th()
++1
 , msg);%0A
     
@@ -2463,16 +2463,87 @@
 , msg);%0A
+            ruleMatch.setSuggestedReplacement(tokens%5Bi-1%5D.getToken());%0A
         

set suggested fix; fix javadoc