All Downloads are FREE. Search and download functionalities are using the official Maven repository.

se.vandmo.textchecker.maven.fixers.RemoveTrailingWhitespaceOnNonBlankLines Maven / Gradle / Ivy

There is a newer version: 0.22.1
Show newest version
package se.vandmo.textchecker.maven.fixers;

import static se.vandmo.textchecker.maven.rules.NoTrailingWhitespaceOnNonBlankLines.ENDS_WITH_WHITESPACE;
import static se.vandmo.textchecker.maven.rules.NoTrailingWhitespaceOnNonBlankLines.isOk;

import java.util.regex.Matcher;

import se.vandmo.textchecker.maven.Content;
import se.vandmo.textchecker.maven.ContentType;
import se.vandmo.textchecker.maven.Fixer;


public final class RemoveTrailingWhitespaceOnNonBlankLines implements Fixer {

  @Override
  public void fix(Content content) {
    content.modifyLines((line) -> {
      return possiblyFixLine(line, content.type());
    });
  }

  private String possiblyFixLine(String line, ContentType contentType) {
    if (isOk(line, contentType)) {
      return line;
    }
    Matcher matcher = ENDS_WITH_WHITESPACE.matcher(line);
    if (!matcher.matches()) {
      return line;
    }
    return matcher.group("beforetrailing");
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy