@jakzal I got an advice from one of my mentors, to extract detecting charset process into another method and write a test to cover that new method. 
I want to do so if it is possible here. What do you think (as a member of the Core team)?