Merge in upstream changes from CodeIgniter development branch.

This resolves issue #163. I added a number of tests to confirm that the output of the function matches the output of the upstream function, but more tests would probably be a good idea in general.