Merge pull request #138 from Microsoft/feature/unicode-fixes

Unicode fixes
This commit is contained in:
Lukas Spieß 2016-06-24 23:56:28 +02:00 коммит произвёл GitHub
Родитель b24fa99162 00b7583371
Коммит 94835eda92
2 изменённых файлов: 21 добавлений и 1 удалений

Просмотреть файл

@ -148,7 +148,7 @@ void msai_appendStringToSafeJsonStream(NSString *string, char **jsonString) {
char *new_string = NULL;
// Concatenate old string with new JSON string and add a comma.
asprintf(&new_string, "%s%.*s\n", *jsonString, (int)MIN(string.length, (NSUInteger)INT_MAX), string.UTF8String);
asprintf(&new_string, "%s%.*s\n", *jsonString, (int)MIN([string lengthOfBytesUsingEncoding:NSUTF8StringEncoding], (NSUInteger)INT_MAX), string.UTF8String);
free(*jsonString);
*jsonString = new_string;
}

Просмотреть файл

@ -138,6 +138,26 @@
XCTAssertEqual(strcmp(MSAISafeJsonEventsString,"{\"Key1\":\"Value1\"}\n"), 0);
}
- (void)testAppendStringToSafeJsonStreamWithSpecialCharacters {
XCTAssertTrue(MSAISafeJsonEventsString == NULL);
msai_appendStringToSafeJsonStream(@"Turín", &MSAISafeJsonEventsString);
XCTAssertEqual(strlen(MSAISafeJsonEventsString), 7U);
XCTAssertEqual([[NSString alloc] initWithUTF8String:MSAISafeJsonEventsString].length, 6U);
XCTAssertEqual(strcmp(MSAISafeJsonEventsString, "Turín\n"), 0);
// Test emoji
MSAISafeJsonEventsString = NULL;
msai_appendStringToSafeJsonStream(@"🙂", &MSAISafeJsonEventsString);
XCTAssertEqual(strlen(MSAISafeJsonEventsString), 5U);
XCTAssertEqual([[NSString alloc] initWithUTF8String:MSAISafeJsonEventsString].length, 3U);
XCTAssertEqual(strcmp(MSAISafeJsonEventsString, "🙂\n"), 0);
}
- (void)testResetSafeJsonStream {
msai_resetSafeJsonStream(&MSAISafeJsonEventsString);
XCTAssertEqual(strcmp(MSAISafeJsonEventsString,""), 0);