package experimentdatabase;

import java.util.regex.Pattern;

class Helpers {

	private static final Pattern INVALID_COLUMN_CHARACTERS = Pattern.compile("['`\"\\.]");//Pattern.compile("[^a-zA-Z0-9_]");

	/**
	 * Removes possibly insecure characters from a given name, such that '`"\. and filters the data object name for
	 * restricted names (currently "id", "parent" or "sqlite_*"). If a restricted name is given, then it becomes
	 * prefixed by _ (underscore).
	 * 
	 * @param name
	 * @return
	 */
	public static String fixDataObjectName(String name) {
		name = INVALID_COLUMN_CHARACTERS.matcher(name).replaceAll("_");

		if ("id".equalsIgnoreCase(name) || "parent".equalsIgnoreCase(name) || name.toLowerCase().startsWith("sqlite_"))
			name = "_" + name;

		return name.intern();
	}
}
