Replace charval with a much neater implementation.

Got rid of the huge switch statement, now use a char array and look up the
index of the given character.