copied from http://code.google.com/p/snakeyaml revision:2fc3f642a173