package _VisualDVM.Passes.All;
import Common.Utils.Utils_;
import _VisualDVM.Passes.Sapfor.Transformation;
import _VisualDVM.ProjectData.Files.DBProjectFile;
import org.apache.commons.io.FileUtils;

import java.io.File;
import java.nio.file.Paths;
public class EraseBadSymbols extends Transformation {
    @Override
    protected void body() throws Exception {
        for (DBProjectFile file : target.db.files.Data.values()) {
            String file_text = FileUtils.readFileToString(file.file);
            StringBuilder res_text = new StringBuilder();
            for (char c : file_text.toCharArray()) {
                if (Utils_.isEnglishLetter(c) || Character.isDigit(c) || Utils_.isSign(c)) {
                    res_text.append(c);
                } else if (Utils_.isRussianLetter(c))
                    res_text.append(Utils_.Translit(c));
                else res_text.append(' ');
            }
            File dst = Paths.get(target.last_version.Home.getAbsolutePath(), Utils_.isWindows() ? file.name : file.name.replace('\\', '/')).toFile();
            FileUtils.write(dst, res_text.toString());
        }
    }
}
