Resources: correct string encoding conversion #128
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The UTF8 to UTF16 conversion was error-prone as it truncated the top-bit and used the wrong value for the character count for the string creation. This uses Foundation to perform the string conversion and counts the new character length.
The string conversion of the character to UTF16 also houses another failure point by not ensuring that we do not require a surrogate pair for the character encoding. However, leave that issue in place but remove the use of the
withWideChars
conversion. In the process we avoid an allocation of aString
by directly using the UTF16 view and stripping the first integral value (potentially half of a surrogate pair).