Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem (and solution) handling 32bit unicode entities #116

Open
kshepherd2013 opened this issue Nov 19, 2015 · 0 comments
Open

Problem (and solution) handling 32bit unicode entities #116

kshepherd2013 opened this issue Nov 19, 2015 · 0 comments

Comments

@kshepherd2013
Copy link

If you try this, it does not substitute the entities:
NSString * example = @"Title 🚓🚌🚒🚖";
NSString * result = [example stringByDecodingHTMLEntities];

Here is the fix (GTMNSString+HTML.m from line 481):
NSScanner *scanner = [NSScanner scannerWithString:hexSequence];
unsigned long long value;
if ([scanner scanHexLongLong:&value] && [scanner scanLocation] == length - 4) {
if (value < USHRT_MAX) {
unichar uchar = value;
NSString *charString = [NSString stringWithCharacters:&uchar length:1];
[finalString replaceCharactersInRange:escapeRange withString:charString];
} else if ( (value & 0xFF000000) == 0 ){
value -= 0x10000;
unichar highSurrogate = value >> 10; // leave the top 10 bits
highSurrogate += 0xD800;
unichar lowSurrogate = value & 0x3FF; // leave the low 10 bits
lowSurrogate += 0xDC00;
NSString *charString = [NSString stringWithCharacters:(unichar[]){highSurrogate, lowSurrogate} length:2];
[finalString replaceCharactersInRange:escapeRange withString:charString];
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant