Extra context: API + CLI

Fixes #12
Synthesizes parts of: #75, #100, #116, #161 and #199.
Thanks @fcurella, @aventurella, @emonty, @schacki, @ryanolson!
With this and the following 3 functions, I'd prefer that they did *not* use a default encoding of UTF8. It's basically wrong, unless you're 100% sure of the context, and these functions are too general to have enough information to know that context. Either make the caller specify explicitly or use the system default encoding (which for this project is not right, as many files are defined as being UTF8 at the moment - at least until I get the encoding patch written!)