Improve general string performance

1) fix some globalization warnings
2) improve various char methods performance
3) make the code easier to read

Sorry for the big PR, but it wouldn't make much sense to separate anyway. Should be an easy one to review.