Skip to content

Commit 2db6610

Browse files
authored
Merge pull request #3055 from iCharlesHu/attributed-string
2 parents 59346dd + b697c70 commit 2db6610

19 files changed

+7778
-0
lines changed

CoreFoundation/Base.subproj/SwiftRuntime/TargetConditionals.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,12 @@
138138
#define TARGET_OS_MAC TARGET_OS_DARWIN
139139
#define TARGET_OS_OSX TARGET_OS_DARWIN
140140

141+
// iOS, watchOS, and tvOS are not supported
142+
#define TARGET_OS_IPHONE 0
143+
#define TARGET_OS_IOS 0
144+
#define TARGET_OS_WATCH 0
145+
#define TARGET_OS_TV 0
146+
141147
#if __x86_64__
142148
#define TARGET_CPU_PPC 0
143149
#define TARGET_CPU_PPC64 0

Foundation.xcodeproj/project.pbxproj

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,18 @@
8686
3EA9D6701EF0532D00B362D6 /* TestJSONEncoder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3EA9D66F1EF0532D00B362D6 /* TestJSONEncoder.swift */; };
8787
3EDCE50C1EF04D8100C2EC04 /* Codable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3EDCE5051EF04D8100C2EC04 /* Codable.swift */; };
8888
3EDCE5101EF04D8100C2EC04 /* JSONEncoder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3EDCE5091EF04D8100C2EC04 /* JSONEncoder.swift */; };
89+
4704393226BDFF34000D213E /* TestAttributedStringPerformance.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4704392E26BDFF33000D213E /* TestAttributedStringPerformance.swift */; };
90+
4704393326BDFF34000D213E /* TestAttributedStringCOW.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4704392F26BDFF33000D213E /* TestAttributedStringCOW.swift */; };
91+
4704393426BDFF34000D213E /* TestAttributedString.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4704393026BDFF33000D213E /* TestAttributedString.swift */; };
92+
4704393526BDFF34000D213E /* TestAttributedStringSupport.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4704393126BDFF34000D213E /* TestAttributedStringSupport.swift */; };
93+
474E124D26BCD6D00016C28A /* AttributedString+Locking.swift in Sources */ = {isa = PBXBuildFile; fileRef = 474E124C26BCD6D00016C28A /* AttributedString+Locking.swift */; };
94+
476E415226BDAA150043E21E /* Morphology.swift in Sources */ = {isa = PBXBuildFile; fileRef = 476E415126BDAA150043E21E /* Morphology.swift */; };
95+
4778104C26BC9F810071E8A1 /* FoundationAttributes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4778104526BC9F810071E8A1 /* FoundationAttributes.swift */; };
96+
4778104E26BC9F810071E8A1 /* AttributedStringRunCoalescing.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4778104726BC9F810071E8A1 /* AttributedStringRunCoalescing.swift */; };
97+
4778104F26BC9F810071E8A1 /* AttributedStringAttribute.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4778104826BC9F810071E8A1 /* AttributedStringAttribute.swift */; };
98+
4778105026BC9F810071E8A1 /* AttributedString.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4778104926BC9F810071E8A1 /* AttributedString.swift */; };
99+
4778105126BC9F810071E8A1 /* Conversion.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4778104A26BC9F810071E8A1 /* Conversion.swift */; };
100+
4778105226BC9F810071E8A1 /* AttributedStringCodable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4778104B26BC9F810071E8A1 /* AttributedStringCodable.swift */; };
89101
49D55FA125E84FE5007BD3B3 /* JSONSerialization+Parser.swift in Sources */ = {isa = PBXBuildFile; fileRef = 49D55FA025E84FE5007BD3B3 /* JSONSerialization+Parser.swift */; };
90102
528776141BF2629700CB0090 /* FoundationErrors.swift in Sources */ = {isa = PBXBuildFile; fileRef = 522C253A1BF16E1600804FC6 /* FoundationErrors.swift */; };
91103
528776191BF27D9500CB0090 /* Test.plist in Resources */ = {isa = PBXBuildFile; fileRef = 528776181BF27D9500CB0090 /* Test.plist */; };
@@ -807,6 +819,18 @@
807819
3EDCE5051EF04D8100C2EC04 /* Codable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Codable.swift; sourceTree = "<group>"; };
808820
3EDCE5091EF04D8100C2EC04 /* JSONEncoder.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JSONEncoder.swift; sourceTree = "<group>"; };
809821
400E22641C1A4E58007C5933 /* TestProcessInfo.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestProcessInfo.swift; sourceTree = "<group>"; };
822+
4704392E26BDFF33000D213E /* TestAttributedStringPerformance.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestAttributedStringPerformance.swift; sourceTree = "<group>"; };
823+
4704392F26BDFF33000D213E /* TestAttributedStringCOW.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestAttributedStringCOW.swift; sourceTree = "<group>"; };
824+
4704393026BDFF33000D213E /* TestAttributedString.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestAttributedString.swift; sourceTree = "<group>"; };
825+
4704393126BDFF34000D213E /* TestAttributedStringSupport.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestAttributedStringSupport.swift; sourceTree = "<group>"; };
826+
474E124C26BCD6D00016C28A /* AttributedString+Locking.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "AttributedString+Locking.swift"; sourceTree = "<group>"; };
827+
476E415126BDAA150043E21E /* Morphology.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Morphology.swift; sourceTree = "<group>"; };
828+
4778104526BC9F810071E8A1 /* FoundationAttributes.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FoundationAttributes.swift; sourceTree = "<group>"; };
829+
4778104726BC9F810071E8A1 /* AttributedStringRunCoalescing.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AttributedStringRunCoalescing.swift; sourceTree = "<group>"; };
830+
4778104826BC9F810071E8A1 /* AttributedStringAttribute.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AttributedStringAttribute.swift; sourceTree = "<group>"; };
831+
4778104926BC9F810071E8A1 /* AttributedString.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AttributedString.swift; sourceTree = "<group>"; };
832+
4778104A26BC9F810071E8A1 /* Conversion.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Conversion.swift; sourceTree = "<group>"; };
833+
4778104B26BC9F810071E8A1 /* AttributedStringCodable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AttributedStringCodable.swift; sourceTree = "<group>"; };
810834
49D55FA025E84FE5007BD3B3 /* JSONSerialization+Parser.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "JSONSerialization+Parser.swift"; sourceTree = "<group>"; };
811835
4AE109261C17CCBF007367B5 /* TestIndexPath.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestIndexPath.swift; sourceTree = "<group>"; };
812836
4DC1D07F1C12EEEF00B5948A /* TestPipe.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestPipe.swift; sourceTree = "<group>"; };
@@ -1385,6 +1409,20 @@
13851409
/* End PBXFrameworksBuildPhase section */
13861410

13871411
/* Begin PBXGroup section */
1412+
4778103D26BC9E320071E8A1 /* AttributedString */ = {
1413+
isa = PBXGroup;
1414+
children = (
1415+
4778104926BC9F810071E8A1 /* AttributedString.swift */,
1416+
4778104826BC9F810071E8A1 /* AttributedStringAttribute.swift */,
1417+
4778104B26BC9F810071E8A1 /* AttributedStringCodable.swift */,
1418+
4778104726BC9F810071E8A1 /* AttributedStringRunCoalescing.swift */,
1419+
4778104A26BC9F810071E8A1 /* Conversion.swift */,
1420+
4778104526BC9F810071E8A1 /* FoundationAttributes.swift */,
1421+
474E124C26BCD6D00016C28A /* AttributedString+Locking.swift */,
1422+
);
1423+
path = AttributedString;
1424+
sourceTree = "<group>";
1425+
};
13881426
5B5D88531BBC938800234F36 = {
13891427
isa = PBXGroup;
13901428
children = (
@@ -1797,6 +1835,10 @@
17971835
isa = PBXGroup;
17981836
children = (
17991837
C93559281C12C49F009FD6A9 /* TestAffineTransform.swift */,
1838+
4704393026BDFF33000D213E /* TestAttributedString.swift */,
1839+
4704392F26BDFF33000D213E /* TestAttributedStringCOW.swift */,
1840+
4704392E26BDFF33000D213E /* TestAttributedStringPerformance.swift */,
1841+
4704393126BDFF34000D213E /* TestAttributedStringSupport.swift */,
18001842
659FB6DD2405E5E200F5F63F /* TestBridging.swift */,
18011843
6E203B8C1C1303BB003B2576 /* TestBundle.swift */,
18021844
A5A34B551C18C85D00FD972B /* TestByteCountFormatter.swift */,
@@ -2049,6 +2091,7 @@
20492091
B98303F325F21389001F959E /* CMakeLists.txt */,
20502092
F023072523F0B4890023DBEC /* Headers */,
20512093
F023072423F0B4140023DBEC /* Resources */,
2094+
4778103D26BC9E320071E8A1 /* AttributedString */,
20522095
EADE0B4D1BD09E0800C49C64 /* AffineTransform.swift */,
20532096
5BD31D231D5CECC400563814 /* Array.swift */,
20542097
5B23AB861CE62D17000DB898 /* Boxing.swift */,
@@ -2189,6 +2232,7 @@
21892232
B96C110925BA215800985A32 /* URLResourceKey.swift */,
21902233
EADE0B871BD15DFF00C49C64 /* UserDefaults.swift */,
21912234
6EB768271D18C12C00D4B719 /* UUID.swift */,
2235+
476E415126BDAA150043E21E /* Morphology.swift */,
21922236
);
21932237
path = Foundation;
21942238
sourceTree = "<group>";
@@ -2861,6 +2905,7 @@
28612905
EADE0BBF1BD15E0000C49C64 /* NSURLError.swift in Sources */,
28622906
EADE0BAF1BD15E0000C49C64 /* PersonNameComponentsFormatter.swift in Sources */,
28632907
EADE0B941BD15DFF00C49C64 /* NSCompoundPredicate.swift in Sources */,
2908+
4778105026BC9F810071E8A1 /* AttributedString.swift in Sources */,
28642909
528776141BF2629700CB0090 /* FoundationErrors.swift in Sources */,
28652910
5B23AB8D1CE63228000DB898 /* URL.swift in Sources */,
28662911
EADE0BA91BD15E0000C49C64 /* NSNull.swift in Sources */,
@@ -2881,6 +2926,7 @@
28812926
49D55FA125E84FE5007BD3B3 /* JSONSerialization+Parser.swift in Sources */,
28822927
5BC1B9A821F275B000524D8C /* Collections+DataProtocol.swift in Sources */,
28832928
5BF7AEBE1BCD51F9008F214A /* NSTimeZone.swift in Sources */,
2929+
4778105226BC9F810071E8A1 /* AttributedStringCodable.swift in Sources */,
28842930
EADE0B951BD15DFF00C49C64 /* DateComponentsFormatter.swift in Sources */,
28852931
5BC1B9AE21F275E900524D8C /* Pointers+DataProtocol.swift in Sources */,
28862932
B96C10F625BA1EFD00985A32 /* NSURLComponents.swift in Sources */,
@@ -2954,6 +3000,7 @@
29543000
5BF7AEAF1BCD51F9008F214A /* Host.swift in Sources */,
29553001
EADE0B4E1BD09E0800C49C64 /* AffineTransform.swift in Sources */,
29563002
5BDC3FCE1BCF17D300ED97BB /* NSCFDictionary.swift in Sources */,
3003+
476E415226BDAA150043E21E /* Morphology.swift in Sources */,
29573004
EADE0BA81BD15E0000C49C64 /* NotificationQueue.swift in Sources */,
29583005
EA418C261D57257D005EAD0D /* NSKeyedArchiverHelpers.swift in Sources */,
29593006
EADE0B981BD15DFF00C49C64 /* NSDecimalNumber.swift in Sources */,
@@ -2963,6 +3010,7 @@
29633010
D3BCEBA01C2F6DDB00295652 /* NSKeyedCoderOldStyleArray.swift in Sources */,
29643011
5B8BA1621D0B773A00938C27 /* IndexSet.swift in Sources */,
29653012
EADE0BA71BD15E0000C49C64 /* NSNotification.swift in Sources */,
3013+
4778104E26BC9F810071E8A1 /* AttributedStringRunCoalescing.swift in Sources */,
29663014
B96C110A25BA215800985A32 /* URLResourceKey.swift in Sources */,
29673015
5BF7AEB41BCD51F9008F214A /* NSObject.swift in Sources */,
29683016
EADE0B521BD09F2F00C49C64 /* ByteCountFormatter.swift in Sources */,
@@ -2976,8 +3024,11 @@
29763024
5BECBA3A1D1CAE9A00B39B1F /* NSMeasurement.swift in Sources */,
29773025
5BF7AEB21BCD51F9008F214A /* NSNumber.swift in Sources */,
29783026
1513A8432044893F00539722 /* FileManager+XDG.swift in Sources */,
3027+
4778105126BC9F810071E8A1 /* Conversion.swift in Sources */,
29793028
91B668A52252B3E7001487A1 /* FileManager+Win32.swift in Sources */,
3029+
4778104F26BC9F810071E8A1 /* AttributedStringAttribute.swift in Sources */,
29803030
5BCD03821D3EE35C00E3FF9B /* TimeZone.swift in Sources */,
3031+
4778104C26BC9F810071E8A1 /* FoundationAttributes.swift in Sources */,
29813032
B96C112525BA2CE700985A32 /* URLQueryItem.swift in Sources */,
29823033
5BC1B9AC21F275D500524D8C /* NSData+DataProtocol.swift in Sources */,
29833034
5B4092121D1B30B40022B067 /* ExtraStringAPIs.swift in Sources */,
@@ -2989,6 +3040,7 @@
29893040
B98303EA25F2131D001F959E /* JSONDecoder.swift in Sources */,
29903041
5BDC3FCC1BCF177E00ED97BB /* NSCFString.swift in Sources */,
29913042
EADE0BAC1BD15E0000C49C64 /* NSOrderedSet.swift in Sources */,
3043+
474E124D26BCD6D00016C28A /* AttributedString+Locking.swift in Sources */,
29923044
5BC1B9A421F2757F00524D8C /* ContiguousBytes.swift in Sources */,
29933045
EADE0B971BD15DFF00C49C64 /* Decimal.swift in Sources */,
29943046
5B78185B1D6CB5D2004A01F2 /* CGFloat.swift in Sources */,
@@ -3101,6 +3153,7 @@
31013153
5FE52C951D147D1C00F7D270 /* TestNSTextCheckingResult.swift in Sources */,
31023154
5B13B3451C582D4C00651CE2 /* TestNSString.swift in Sources */,
31033155
1520469B1D8AEABE00D02E36 /* HTTPServer.swift in Sources */,
3156+
4704393326BDFF34000D213E /* TestAttributedStringCOW.swift in Sources */,
31043157
B90C57BC1EEEEA5A005208AE /* TestThread.swift in Sources */,
31053158
B90C57BB1EEEEA5A005208AE /* TestFileManager.swift in Sources */,
31063159
A058C2021E529CF100B07AA1 /* TestMassFormatter.swift in Sources */,
@@ -3144,6 +3197,7 @@
31443197
5B13B34E1C582D4C00651CE2 /* TestXMLDocument.swift in Sources */,
31453198
5B13B32B1C582D4C00651CE2 /* TestNSData.swift in Sources */,
31463199
5B13B34C1C582D4C00651CE2 /* TestURLResponse.swift in Sources */,
3200+
4704393526BDFF34000D213E /* TestAttributedStringSupport.swift in Sources */,
31473201
AA9E0E0D21FA6E0700963F4C /* TestPropertyListEncoder.swift in Sources */,
31483202
0383A1751D2E558A0052E5D1 /* TestStream.swift in Sources */,
31493203
5B13B3481C582D4C00651CE2 /* TestTimer.swift in Sources */,
@@ -3179,6 +3233,7 @@
31793233
5B13B3371C582D4C00651CE2 /* TestNotificationCenter.swift in Sources */,
31803234
5B13B3251C582D4700651CE2 /* main.swift in Sources */,
31813235
5B1FD9E31D6D17B80080E83C /* TestURLSession.swift in Sources */,
3236+
4704393226BDFF34000D213E /* TestAttributedStringPerformance.swift in Sources */,
31823237
3EA9D6701EF0532D00B362D6 /* TestJSONEncoder.swift in Sources */,
31833238
D512D17C1CD883F00032E6A5 /* TestFileHandle.swift in Sources */,
31843239
D4FE895B1D703D1100DA7986 /* TestURLRequest.swift in Sources */,
@@ -3189,6 +3244,7 @@
31893244
155B77AC22E63D2D00D901DE /* TestURLCredentialStorage.swift in Sources */,
31903245
B951B5EC1F4E2A2000D8B332 /* TestNSLock.swift in Sources */,
31913246
5B13B33A1C582D4C00651CE2 /* TestNSNumber.swift in Sources */,
3247+
4704393426BDFF34000D213E /* TestAttributedString.swift in Sources */,
31923248
5B13B3521C582D4C00651CE2 /* TestNSValue.swift in Sources */,
31933249
7D0DE86F211883F500540061 /* Utilities.swift in Sources */,
31943250
5B13B3311C582D4C00651CE2 /* TestIndexPath.swift in Sources */,
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2021 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#if canImport(Darwin)
14+
import Darwin
15+
16+
@available(macOS 10.12, iOS 10.0, tvOS 10.0, watchOS 3.0, *)
17+
extension UnsafeMutablePointer where Pointee == os_unfair_lock_s {
18+
internal init() {
19+
let l = UnsafeMutablePointer.allocate(capacity: 1)
20+
l.initialize(to: os_unfair_lock())
21+
self = l
22+
}
23+
24+
internal func cleanupLock() {
25+
deinitialize(count: 1)
26+
deallocate()
27+
}
28+
29+
internal func lock() {
30+
os_unfair_lock_lock(self)
31+
}
32+
33+
internal func tryLock() -> Bool {
34+
let result = os_unfair_lock_trylock(self)
35+
return result
36+
}
37+
38+
internal func unlock() {
39+
os_unfair_lock_unlock(self)
40+
}
41+
}
42+
43+
@available(macOS 10.12, iOS 10.0, tvOS 10.0, watchOS 3.0, *)
44+
typealias Lock = os_unfair_lock_t
45+
46+
#else
47+
internal typealias Lock = NSLock
48+
49+
extension NSLock {
50+
// Stub to match the API of os_unfair_lock_t
51+
func cleanupLock() { /* NOOP */ }
52+
}
53+
#endif

0 commit comments

Comments
 (0)