Skip to content

[Character] Permit tagged emoji Character literals #20599

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 15, 2018
Merged
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
11 changes: 0 additions & 11 deletions include/swift/Basic/Unicode.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,6 @@ extern const uint16_t ExtendedGraphemeClusterNoBoundaryRulesMatrix[];
/// point.
GraphemeClusterBreakProperty getGraphemeClusterBreakProperty(uint32_t C);

/// Returns true if there is always an extended grapheme cluster boundary
/// after a code point with a given property value. Use only for optimization,
/// to skip calculating Grapheme_Cluster_Break property for the second code
/// point.
static inline bool
isExtendedGraphemeClusterBoundaryAfter(GraphemeClusterBreakProperty GCB1) {
auto RuleRow =
ExtendedGraphemeClusterNoBoundaryRulesMatrix[static_cast<unsigned>(GCB1)];
return RuleRow == 0;
}

/// Determine if there is an extended grapheme cluster boundary between code
/// points with given Grapheme_Cluster_Break property values.
static inline bool
Expand Down
20 changes: 16 additions & 4 deletions lib/Basic/Unicode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,22 @@ using namespace swift;
// break between them. That is, whether we're overriding the behavior of the
// hard coded Unicode 8 rules surrounding ZWJ and emoji modifiers.
static inline bool graphemeBreakOverride(llvm::UTF32 lhs, llvm::UTF32 rhs) {
return lhs == 0x200D || (rhs >= 0x1F3FB && rhs <= 0x1F3FF);
// Assume ZWJ sequences produce new emoji
if (lhs == 0x200D) {
return true;
}

// Permit continuing regional indicators
if (rhs >= 0x1F3FB && rhs <= 0x1F3FF) {
return true;
}

// Permit emoji tag sequences
if (rhs >= 0xE0020 && rhs <= 0xE007F) {
return true;
}

return false;
}

StringRef swift::unicode::extractFirstExtendedGraphemeCluster(StringRef S) {
Expand All @@ -52,9 +67,6 @@ StringRef swift::unicode::extractFirstExtendedGraphemeCluster(StringRef S) {

GraphemeClusterBreakProperty GCBForC0 = getGraphemeClusterBreakProperty(C[0]);
while (true) {
if (isExtendedGraphemeClusterBoundaryAfter(GCBForC0))
return S.slice(0, SourceNext - SourceStart);

size_t C1Offset = SourceNext - SourceStart;
ConvertUTF8toUTF32(&SourceNext, SourceStart + S.size(), &TargetStart, C + 2,
llvm::lenientConversion);
Expand Down
1 change: 1 addition & 0 deletions test/Parse/enum.swift
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ enum RawTypeWithCharacterValues_Correct : Character {
case First = "😅" // ok
case Second = "👩‍👩‍👧‍👦" // ok
case Third = "👋🏽" // ok
case Fourth = "\u{1F3F4}\u{E0067}\u{E0062}\u{E0065}\u{E006E}\u{E0067}\u{E007F}" // ok
}

enum RawTypeWithCharacterValues_Error1 : Character { // expected-error {{'RawTypeWithCharacterValues_Error1' declares raw type 'Character', but does not conform to RawRepresentable and conformance could not be synthesized}}
Expand Down