Improved detecting whether the pointer is in a string or not