public static TransformedString normaliseString(String s){
  String remaining=s;
  StringBuilder builder=new StringBuilder();
  String previousChar="";
  Map<Integer,Integer> indexMap=new HashMap<>();
  Integer index=0;
  while (!remaining.isEmpty()) {
    indexMap.put(builder.length(),index);
    index++;
    String character=remaining.substring(0,1);
    remaining=remaining.substring(1);
    if (!(character.matches("\\h") && previousChar.matches("\\h"))) {
      if (character.matches("\\h")) {
        character=" ";
      }
      builder.append(character);
    }
    previousChar=character;
  }
  indexMap.put(builder.length(),index);
  return new TransformedString(s,builder.toString(),indexMap);
}

public static TransformedString normaliseString ( String s ) { String remaining = s ; StringBuilder builder = new StringBuilder ( ) ; String previousChar = "" ; Map < Integer , Integer > indexMap = new HashMap < > ( ) ; Integer index = 0 ; while ( ! remaining . isEmpty ( ) ) { indexMap . put ( builder . length ( ) , index ) ; index ++ ; String character = remaining . substring ( 0 , 1 ) ; remaining = remaining . substring ( 1 ) ; if ( ! ( character . matches ( "\\h" ) && previousChar . matches ( "\\h" ) ) ) { if ( character . matches ( "\\h" ) ) { character = " " ; } builder . append ( character ) ; } previousChar = character ; } indexMap . put ( builder . length ( ) , index ) ; return new TransformedString ( s , builder . toString ( ) , indexMap ) ; }
replace repeated horizontal whitespace characters with a single space character , and return a transformedstring that maps between the original and normalised string
