http://www.cnblogs.com/dreamer-fish/p/3911953.html
C#实现:
https://www.oschina.net/code/snippet_172400_17195