Skip to content

Commit c47f0cc

Browse files
authored
Merge pull request #8508 from woocommerce/feat/8378-sc-profiler-country-code-updates
Store creation M3: store country profiler question - country code updates
2 parents fe3f198 + 7551746 commit c47f0cc

File tree

4 files changed

+291
-248
lines changed

4 files changed

+291
-248
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import Foundation
2+
3+
extension SiteAddress.CountryCode {
4+
/// Returns the flag emoji based on the country code if available.
5+
/// Reference: https://stackoverflow.com/a/30403199/9185596
6+
var flagEmoji: String? {
7+
// From en.wikipedia.org/wiki/Regional_Indicator_Symbol, the flags start at code point 0x1F1E6.
8+
// The offset for "A" is 65. 0x1F1E6 - 65 = 127397.
9+
let base: UInt32 = 127397
10+
var flagEmoji = ""
11+
for scalar in rawValue.uppercased().unicodeScalars {
12+
guard let flagEmojiScalar = UnicodeScalar(base + scalar.value) else {
13+
return nil
14+
}
15+
flagEmoji.unicodeScalars.append(flagEmojiScalar)
16+
}
17+
return flagEmoji
18+
}
19+
}

0 commit comments

Comments
 (0)