package com.iqser.red.service.persistence.management.v1.processor.service.manualredactions;

import java.util.regex.Pattern;

import lombok.experimental.UtilityClass;

@UtilityClass
public class StringCleaningUtility {

    public static final Pattern hyphenLineBreaks = Pattern.compile("[-~‐‒⁻−﹣゠⁓‑\\u00AD][\\r\\n]+");
    public static final Pattern linebreaks = Pattern.compile("[\\r\\n]+");
    public static final Pattern doubleWhitespaces = Pattern.compile("\\s{2,}");


    public String cleanString(String value) {

        String noHyphenLinebreaks = removeHyphenLinebreaks(value);
        String noLinebreaks = removeLinebreaks(noHyphenLinebreaks);
        return removeMultipleWhitespaces(noLinebreaks);
    }


    private String removeHyphenLinebreaks(String value) {

        return hyphenLineBreaks.matcher(value).replaceAll("");
    }


    private String removeMultipleWhitespaces(String value) {

        return doubleWhitespaces.matcher(value).replaceAll(" ");
    }


    private String removeLinebreaks(String value) {

        return linebreaks.matcher(value).replaceAll(" ");
    }

}
