Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Source/CFString.c
Original file line number Diff line number Diff line change
Expand Up @@ -948,7 +948,7 @@ Boolean
CFStringGetSurrogatePairForLongCharacter (UTF32Char character,
UniChar * surrogates)
{
if (character > 0x10000)
if (character < 0x10000)
return false;

surrogates[0] = U16_LEAD (character);
Expand Down
24 changes: 24 additions & 0 deletions Tests/CFString/surrogate.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include "CoreFoundation/CFString.h"
#include "../CFTesting.h"

/* CFStringGetSurrogatePairForLongCharacter for supplementary-plane and BMP characters. */

int main (void)
{
UniChar pair[2];

PASS_CF(CFStringGetSurrogatePairForLongCharacter(0x1F600, pair) == true,
"Supplementary character U+1F600 yields a surrogate pair.");
PASS_CF(pair[0] == 0xD83D && pair[1] == 0xDE00,
"Surrogate pair for U+1F600 is D83D DE00.");
PASS_CF(CFStringGetLongCharacterForSurrogatePair(pair[0], pair[1]) == 0x1F600,
"Surrogate pair round-trips back to U+1F600.");

PASS_CF(CFStringGetSurrogatePairForLongCharacter(0x10000, pair) == true,
"The first supplementary character U+10000 yields a pair.");

PASS_CF(CFStringGetSurrogatePairForLongCharacter(0x0041, pair) == false,
"A BMP character (U+0041) yields no surrogate pair.");

return 0;
}
Loading