better structure for getStringBeforeCursor, also support multiple whitespaces