Skip to content

Commit

Permalink
Merge pull request #5 from JoaoCaixinha/master
Browse files Browse the repository at this point in the history
emoji with other unicode chars
  • Loading branch information
realtime-framework committed Oct 5, 2015
2 parents 25ea183 + cd5268d commit 3ff4116
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
41 changes: 37 additions & 4 deletions Pod/Classes/OrtcClient/OrtcClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -1278,29 +1278,56 @@ - (void)opReceive:(NSString*) message {
[msgSentDict setObject:[NSNumber numberWithBool:YES] forKey:@"isMsgSent"];
[messagesBuffer setObject:msgSentDict forKey:messageId];
}

aMessage = [self escapeRecvChars:aMessage];

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];

if(ascii > 128){ //unicode
[ms appendFormat:@"%@", [NSString stringWithCharacters:&ascii length:1]];
} else { //ascii
}else { //ascii
if(ascii == '\\'){
i = i + 1;
int next = [str characterAtIndex:i];

if(next == '\\'){
[ms appendString:@"\\"];
} else if(next == 'n'){
Expand All @@ -1315,15 +1342,21 @@ - (NSString*)simulateJsonParse:(NSString*) str{
[ms appendString:@"\r"];
} else if(next == 't'){
[ms appendString:@"\t"];
}
} else if(next == 'u'){
[ms appendString:@"\\u"];
}
} else {
[ms appendFormat:@"%c", ascii];
}
}
}
return ms;



return ms ;
}


- (NSString*)generateId:(int) size
{
CFUUIDRef uuidRef = CFUUIDCreate(NULL);
Expand Down
1 change: 0 additions & 1 deletion Pod/Classes/OrtcClient/RealtimePushAppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
// Created by iOSdev on 9/20/13.
// Copyright (c) 2013 Realtime.co All rights reserved.
//

#import <UIKit/UIKit.h>
#define NOTIFICATIONS_KEY @"Local_Storage_Notifications"

Expand Down

0 comments on commit 3ff4116

Please sign in to comment.