Skip to content

Commit

Permalink
emoji with other unicode chars
Browse files Browse the repository at this point in the history
  • Loading branch information
Joao Caixinha committed Oct 5, 2015
1 parent b5b6938 commit cd5268d
Showing 1 changed file with 24 additions and 29 deletions.
53 changes: 24 additions & 29 deletions Pod/Classes/OrtcClient/OrtcClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -1279,25 +1279,44 @@ - (void)opReceive:(NSString*) message {
[messagesBuffer setObject:msgSentDict forKey:messageId];
}


aMessage = [self escapeRecvChars:aMessage];

NSData *pos = [aMessage dataUsingEncoding:NSUTF8StringEncoding];
aMessage = [[NSString alloc] initWithData:pos encoding:NSNonLossyASCIIStringEncoding];

aMessage = [self checkForEmoji:aMessage];
channelSubscription.onMessage(self, aChannel, aMessage);
}
}
}
}
}


- (NSString*)checkForEmoji:(NSString*)str{
for (int i = 0; i < str.length; i++) {
unichar ascii = [str characterAtIndex:i];
if(ascii == '\\'){
i = i + 1;
int next = [str characterAtIndex:i];

if(next == 'u'){
NSString *emoji = [str substringWithRange:NSMakeRange(i - 1, 12)];
NSData *pos = [emoji dataUsingEncoding:NSUTF8StringEncoding];
emoji = [[NSString alloc] initWithData:pos encoding:NSNonLossyASCIIStringEncoding];

str = [str stringByReplacingCharactersInRange:NSMakeRange(i - 1, 12) withString:emoji];
}
}
}
return str;
}


- (NSString*)escapeRecvChars:(NSString*) str{
str = [self simulateJsonParse:str];
str = [self simulateJsonParse:str];
return str;
}
- (NSString*)simulateJsonParse:(NSString*) str{

- (NSString*)simulateJsonParse:(NSString*)str{
NSMutableString *ms = [NSMutableString string];
for(int i =0; i < [str length]; i++){
unichar ascii = [str characterAtIndex:i];
Expand Down Expand Up @@ -1334,34 +1353,10 @@ - (NSString*)simulateJsonParse:(NSString*) str{




return ms ;
}


- (NSString *) escapedUnicode:(NSString*)str
{
NSMutableString *uniString = [ [ NSMutableString alloc ] init ];
UniChar *uniBuffer = (UniChar *) malloc ( sizeof(UniChar) * [ str length ] );
CFRange stringRange = CFRangeMake ( 0, [ str length ] );

CFStringGetCharacters ( (CFStringRef)str, stringRange, uniBuffer );

for ( int i = 0; i < [ str length ]; i++ ) {
if ( uniBuffer[i] > 0x7e )
[ uniString appendFormat: @"\\u%04x", uniBuffer[i] ];
else
[ uniString appendFormat: @"%c", uniBuffer[i] ];
}

free ( uniBuffer );

NSString *retString = [ NSString stringWithString: uniString ];

return retString;
}


- (NSString*)generateId:(int) size
{
CFUUIDRef uuidRef = CFUUIDCreate(NULL);
Expand Down

0 comments on commit cd5268d

Please sign in to comment.