Merge pull request #138 from Microsoft/feature/unicode-fixes
Unicode fixes
This commit is contained in:
Коммит
94835eda92
|
@ -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);
|
||||
|
|
Загрузка…
Ссылка в новой задаче