Core implementation for text decoding.