MDL-39378 s(): fix bad hex regex
MDL-39378 Fix silly regex in s().

I have also made some other changes that give about a 10% speed-up
in this function. The significant changes are:
1. Simplify the if logic to remove unnecssary cases.
2. Dont pass default argument values to htmlspecialchars, just using the
   defaults is faster.
3. I can confirm that /i regex is faster than the equivalent regex without the i.

I also added more unit tests to test the edge cases.