[file encoding] improved code & modified for text_diff