Parser: allow template constraints after base classes.

* Refactored some if-statements to be more compact.
Funcs: jump to common code in escapeNonPrintable().