This only works if you're not dealing with Unicode, where the number of bytes, the number of characters, and the width of those characters can all vary.
I think the feature predates that and Unicode, though. But even then, it fails if you underline text the way it was done at the time, either by using backspace and underline characters or by using termcap (https://en.wikipedia.org/wiki/Termcap)