package common;

import java.text.Normalizer;
import java.util.Objects;

/**
 * 
 * @author Marcos García Núñez (mgarcianun@uoc.edu)
 *
 */
public class Utils {
	public static String stripAccents(String input) {
		return input == null ? null : Normalizer.normalize(input, Normalizer.Form.NFD).replaceAll("\\p{InCombiningDiacriticalMarks}+", "");
	}

	public static String normalizeTerm(String input) {
		// return stripAccents(input).toLowerCase();
		return input.toLowerCase();
	}

	public static Throwable getExceptionRootCause(Throwable throwable) {
		Objects.requireNonNull(throwable);
		Throwable rootCause = throwable;
		while (rootCause.getCause() != null && rootCause.getCause() != rootCause) {
			rootCause = rootCause.getCause();
		}
		return rootCause;
	}
}
