Optimize CSimpleTextSubtitle::CreateSegments.

Make use of the fact the segments are sorted to use a search algorithm in O(log(N)).
Optimize CSimpleTextSubtitle::Add.

Also add comments.
External subtitle: Remove an useless call to CreateSegments.

Segments are created on the fly when inserting the entries.
CTextFile: Fix an out-of-bound access to the cache.

This could cause an infinite loop.
CTextFile: Fix an infinite loop for UTF8 with BOM files with invalid chars.

Also try to be more resilient when such file is encountered: show all characters that could be correctly decoded and replace invalid characters by '?'.