You could put these functions in a separate file to avoid duplicate definitions.

With some refactoring (for example a function to iterate char code arrys and char code range arrays) you can reuse even more.