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

io.magentys.cinnamon.webdriver.elements.StringNormaliser Maven / Gradle / Ivy

There is a newer version: 0.2.0
Show newest version
package io.magentys.cinnamon.webdriver.elements;

public final class StringNormaliser {

    // Suppresses default constructor, ensuring non-instantiability.
    private StringNormaliser() {
    }

    /**
     * Normalises text as follows:
     * 

*

    *
  • trims leading and trailing whitespace
  • *
  • replaces any kind of hyphen or dash character with a dash from a default character set
  • *
  • replaces all carriage return characters with a single space
  • *
  • replaces all new line characters with a single space
  • *
  • replaces all multiple whitespace with a single space
  • *
  • removes all non-ASCII characters
  • *
* * @param text the text to be normalised * @return Normalised text */ public static String normalise(String text) { return text.trim().replaceAll("\\p{Pd}", "-").replaceAll("\\r", " ").replaceAll("\\n", " ").replaceAll("\\s+", " ") .replaceAll("[^\\x20-\\x7e]", ""); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy