Improved implementation for locale string parsing