Skip to content

Introduce AttributedString #3055

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 2 commits into from
Aug 23, 2021
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
6 changes: 6 additions & 0 deletions CoreFoundation/Base.subproj/SwiftRuntime/TargetConditionals.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,12 @@
#define TARGET_OS_MAC TARGET_OS_DARWIN
#define TARGET_OS_OSX TARGET_OS_DARWIN

// iOS, watchOS, and tvOS are not supported
#define TARGET_OS_IPHONE 0
#define TARGET_OS_IOS 0
#define TARGET_OS_WATCH 0
#define TARGET_OS_TV 0

#if __x86_64__
#define TARGET_CPU_PPC 0
#define TARGET_CPU_PPC64 0
Expand Down
56 changes: 56 additions & 0 deletions Foundation.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,18 @@
3EA9D6701EF0532D00B362D6 /* TestJSONEncoder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3EA9D66F1EF0532D00B362D6 /* TestJSONEncoder.swift */; };
3EDCE50C1EF04D8100C2EC04 /* Codable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3EDCE5051EF04D8100C2EC04 /* Codable.swift */; };
3EDCE5101EF04D8100C2EC04 /* JSONEncoder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3EDCE5091EF04D8100C2EC04 /* JSONEncoder.swift */; };
4704393226BDFF34000D213E /* TestAttributedStringPerformance.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4704392E26BDFF33000D213E /* TestAttributedStringPerformance.swift */; };
4704393326BDFF34000D213E /* TestAttributedStringCOW.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4704392F26BDFF33000D213E /* TestAttributedStringCOW.swift */; };
4704393426BDFF34000D213E /* TestAttributedString.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4704393026BDFF33000D213E /* TestAttributedString.swift */; };
4704393526BDFF34000D213E /* TestAttributedStringSupport.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4704393126BDFF34000D213E /* TestAttributedStringSupport.swift */; };
474E124D26BCD6D00016C28A /* AttributedString+Locking.swift in Sources */ = {isa = PBXBuildFile; fileRef = 474E124C26BCD6D00016C28A /* AttributedString+Locking.swift */; };
476E415226BDAA150043E21E /* Morphology.swift in Sources */ = {isa = PBXBuildFile; fileRef = 476E415126BDAA150043E21E /* Morphology.swift */; };
4778104C26BC9F810071E8A1 /* FoundationAttributes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4778104526BC9F810071E8A1 /* FoundationAttributes.swift */; };
4778104E26BC9F810071E8A1 /* AttributedStringRunCoalescing.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4778104726BC9F810071E8A1 /* AttributedStringRunCoalescing.swift */; };
4778104F26BC9F810071E8A1 /* AttributedStringAttribute.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4778104826BC9F810071E8A1 /* AttributedStringAttribute.swift */; };
4778105026BC9F810071E8A1 /* AttributedString.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4778104926BC9F810071E8A1 /* AttributedString.swift */; };
4778105126BC9F810071E8A1 /* Conversion.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4778104A26BC9F810071E8A1 /* Conversion.swift */; };
4778105226BC9F810071E8A1 /* AttributedStringCodable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4778104B26BC9F810071E8A1 /* AttributedStringCodable.swift */; };
49D55FA125E84FE5007BD3B3 /* JSONSerialization+Parser.swift in Sources */ = {isa = PBXBuildFile; fileRef = 49D55FA025E84FE5007BD3B3 /* JSONSerialization+Parser.swift */; };
528776141BF2629700CB0090 /* FoundationErrors.swift in Sources */ = {isa = PBXBuildFile; fileRef = 522C253A1BF16E1600804FC6 /* FoundationErrors.swift */; };
528776191BF27D9500CB0090 /* Test.plist in Resources */ = {isa = PBXBuildFile; fileRef = 528776181BF27D9500CB0090 /* Test.plist */; };
Expand Down Expand Up @@ -807,6 +819,18 @@
3EDCE5051EF04D8100C2EC04 /* Codable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Codable.swift; sourceTree = "<group>"; };
3EDCE5091EF04D8100C2EC04 /* JSONEncoder.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JSONEncoder.swift; sourceTree = "<group>"; };
400E22641C1A4E58007C5933 /* TestProcessInfo.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestProcessInfo.swift; sourceTree = "<group>"; };
4704392E26BDFF33000D213E /* TestAttributedStringPerformance.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestAttributedStringPerformance.swift; sourceTree = "<group>"; };
4704392F26BDFF33000D213E /* TestAttributedStringCOW.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestAttributedStringCOW.swift; sourceTree = "<group>"; };
4704393026BDFF33000D213E /* TestAttributedString.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestAttributedString.swift; sourceTree = "<group>"; };
4704393126BDFF34000D213E /* TestAttributedStringSupport.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestAttributedStringSupport.swift; sourceTree = "<group>"; };
474E124C26BCD6D00016C28A /* AttributedString+Locking.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "AttributedString+Locking.swift"; sourceTree = "<group>"; };
476E415126BDAA150043E21E /* Morphology.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Morphology.swift; sourceTree = "<group>"; };
4778104526BC9F810071E8A1 /* FoundationAttributes.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FoundationAttributes.swift; sourceTree = "<group>"; };
4778104726BC9F810071E8A1 /* AttributedStringRunCoalescing.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AttributedStringRunCoalescing.swift; sourceTree = "<group>"; };
4778104826BC9F810071E8A1 /* AttributedStringAttribute.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AttributedStringAttribute.swift; sourceTree = "<group>"; };
4778104926BC9F810071E8A1 /* AttributedString.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AttributedString.swift; sourceTree = "<group>"; };
4778104A26BC9F810071E8A1 /* Conversion.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Conversion.swift; sourceTree = "<group>"; };
4778104B26BC9F810071E8A1 /* AttributedStringCodable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AttributedStringCodable.swift; sourceTree = "<group>"; };
49D55FA025E84FE5007BD3B3 /* JSONSerialization+Parser.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "JSONSerialization+Parser.swift"; sourceTree = "<group>"; };
4AE109261C17CCBF007367B5 /* TestIndexPath.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestIndexPath.swift; sourceTree = "<group>"; };
4DC1D07F1C12EEEF00B5948A /* TestPipe.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestPipe.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1385,6 +1409,20 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
4778103D26BC9E320071E8A1 /* AttributedString */ = {
isa = PBXGroup;
children = (
4778104926BC9F810071E8A1 /* AttributedString.swift */,
4778104826BC9F810071E8A1 /* AttributedStringAttribute.swift */,
4778104B26BC9F810071E8A1 /* AttributedStringCodable.swift */,
4778104726BC9F810071E8A1 /* AttributedStringRunCoalescing.swift */,
4778104A26BC9F810071E8A1 /* Conversion.swift */,
4778104526BC9F810071E8A1 /* FoundationAttributes.swift */,
474E124C26BCD6D00016C28A /* AttributedString+Locking.swift */,
);
path = AttributedString;
sourceTree = "<group>";
};
5B5D88531BBC938800234F36 = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -1797,6 +1835,10 @@
isa = PBXGroup;
children = (
C93559281C12C49F009FD6A9 /* TestAffineTransform.swift */,
4704393026BDFF33000D213E /* TestAttributedString.swift */,
4704392F26BDFF33000D213E /* TestAttributedStringCOW.swift */,
4704392E26BDFF33000D213E /* TestAttributedStringPerformance.swift */,
4704393126BDFF34000D213E /* TestAttributedStringSupport.swift */,
659FB6DD2405E5E200F5F63F /* TestBridging.swift */,
6E203B8C1C1303BB003B2576 /* TestBundle.swift */,
A5A34B551C18C85D00FD972B /* TestByteCountFormatter.swift */,
Expand Down Expand Up @@ -2049,6 +2091,7 @@
B98303F325F21389001F959E /* CMakeLists.txt */,
F023072523F0B4890023DBEC /* Headers */,
F023072423F0B4140023DBEC /* Resources */,
4778103D26BC9E320071E8A1 /* AttributedString */,
EADE0B4D1BD09E0800C49C64 /* AffineTransform.swift */,
5BD31D231D5CECC400563814 /* Array.swift */,
5B23AB861CE62D17000DB898 /* Boxing.swift */,
Expand Down Expand Up @@ -2189,6 +2232,7 @@
B96C110925BA215800985A32 /* URLResourceKey.swift */,
EADE0B871BD15DFF00C49C64 /* UserDefaults.swift */,
6EB768271D18C12C00D4B719 /* UUID.swift */,
476E415126BDAA150043E21E /* Morphology.swift */,
);
path = Foundation;
sourceTree = "<group>";
Expand Down Expand Up @@ -2861,6 +2905,7 @@
EADE0BBF1BD15E0000C49C64 /* NSURLError.swift in Sources */,
EADE0BAF1BD15E0000C49C64 /* PersonNameComponentsFormatter.swift in Sources */,
EADE0B941BD15DFF00C49C64 /* NSCompoundPredicate.swift in Sources */,
4778105026BC9F810071E8A1 /* AttributedString.swift in Sources */,
528776141BF2629700CB0090 /* FoundationErrors.swift in Sources */,
5B23AB8D1CE63228000DB898 /* URL.swift in Sources */,
EADE0BA91BD15E0000C49C64 /* NSNull.swift in Sources */,
Expand All @@ -2881,6 +2926,7 @@
49D55FA125E84FE5007BD3B3 /* JSONSerialization+Parser.swift in Sources */,
5BC1B9A821F275B000524D8C /* Collections+DataProtocol.swift in Sources */,
5BF7AEBE1BCD51F9008F214A /* NSTimeZone.swift in Sources */,
4778105226BC9F810071E8A1 /* AttributedStringCodable.swift in Sources */,
EADE0B951BD15DFF00C49C64 /* DateComponentsFormatter.swift in Sources */,
5BC1B9AE21F275E900524D8C /* Pointers+DataProtocol.swift in Sources */,
B96C10F625BA1EFD00985A32 /* NSURLComponents.swift in Sources */,
Expand Down Expand Up @@ -2954,6 +3000,7 @@
5BF7AEAF1BCD51F9008F214A /* Host.swift in Sources */,
EADE0B4E1BD09E0800C49C64 /* AffineTransform.swift in Sources */,
5BDC3FCE1BCF17D300ED97BB /* NSCFDictionary.swift in Sources */,
476E415226BDAA150043E21E /* Morphology.swift in Sources */,
EADE0BA81BD15E0000C49C64 /* NotificationQueue.swift in Sources */,
EA418C261D57257D005EAD0D /* NSKeyedArchiverHelpers.swift in Sources */,
EADE0B981BD15DFF00C49C64 /* NSDecimalNumber.swift in Sources */,
Expand All @@ -2963,6 +3010,7 @@
D3BCEBA01C2F6DDB00295652 /* NSKeyedCoderOldStyleArray.swift in Sources */,
5B8BA1621D0B773A00938C27 /* IndexSet.swift in Sources */,
EADE0BA71BD15E0000C49C64 /* NSNotification.swift in Sources */,
4778104E26BC9F810071E8A1 /* AttributedStringRunCoalescing.swift in Sources */,
B96C110A25BA215800985A32 /* URLResourceKey.swift in Sources */,
5BF7AEB41BCD51F9008F214A /* NSObject.swift in Sources */,
EADE0B521BD09F2F00C49C64 /* ByteCountFormatter.swift in Sources */,
Expand All @@ -2976,8 +3024,11 @@
5BECBA3A1D1CAE9A00B39B1F /* NSMeasurement.swift in Sources */,
5BF7AEB21BCD51F9008F214A /* NSNumber.swift in Sources */,
1513A8432044893F00539722 /* FileManager+XDG.swift in Sources */,
4778105126BC9F810071E8A1 /* Conversion.swift in Sources */,
91B668A52252B3E7001487A1 /* FileManager+Win32.swift in Sources */,
4778104F26BC9F810071E8A1 /* AttributedStringAttribute.swift in Sources */,
5BCD03821D3EE35C00E3FF9B /* TimeZone.swift in Sources */,
4778104C26BC9F810071E8A1 /* FoundationAttributes.swift in Sources */,
B96C112525BA2CE700985A32 /* URLQueryItem.swift in Sources */,
5BC1B9AC21F275D500524D8C /* NSData+DataProtocol.swift in Sources */,
5B4092121D1B30B40022B067 /* ExtraStringAPIs.swift in Sources */,
Expand All @@ -2989,6 +3040,7 @@
B98303EA25F2131D001F959E /* JSONDecoder.swift in Sources */,
5BDC3FCC1BCF177E00ED97BB /* NSCFString.swift in Sources */,
EADE0BAC1BD15E0000C49C64 /* NSOrderedSet.swift in Sources */,
474E124D26BCD6D00016C28A /* AttributedString+Locking.swift in Sources */,
5BC1B9A421F2757F00524D8C /* ContiguousBytes.swift in Sources */,
EADE0B971BD15DFF00C49C64 /* Decimal.swift in Sources */,
5B78185B1D6CB5D2004A01F2 /* CGFloat.swift in Sources */,
Expand Down Expand Up @@ -3101,6 +3153,7 @@
5FE52C951D147D1C00F7D270 /* TestNSTextCheckingResult.swift in Sources */,
5B13B3451C582D4C00651CE2 /* TestNSString.swift in Sources */,
1520469B1D8AEABE00D02E36 /* HTTPServer.swift in Sources */,
4704393326BDFF34000D213E /* TestAttributedStringCOW.swift in Sources */,
B90C57BC1EEEEA5A005208AE /* TestThread.swift in Sources */,
B90C57BB1EEEEA5A005208AE /* TestFileManager.swift in Sources */,
A058C2021E529CF100B07AA1 /* TestMassFormatter.swift in Sources */,
Expand Down Expand Up @@ -3144,6 +3197,7 @@
5B13B34E1C582D4C00651CE2 /* TestXMLDocument.swift in Sources */,
5B13B32B1C582D4C00651CE2 /* TestNSData.swift in Sources */,
5B13B34C1C582D4C00651CE2 /* TestURLResponse.swift in Sources */,
4704393526BDFF34000D213E /* TestAttributedStringSupport.swift in Sources */,
AA9E0E0D21FA6E0700963F4C /* TestPropertyListEncoder.swift in Sources */,
0383A1751D2E558A0052E5D1 /* TestStream.swift in Sources */,
5B13B3481C582D4C00651CE2 /* TestTimer.swift in Sources */,
Expand Down Expand Up @@ -3179,6 +3233,7 @@
5B13B3371C582D4C00651CE2 /* TestNotificationCenter.swift in Sources */,
5B13B3251C582D4700651CE2 /* main.swift in Sources */,
5B1FD9E31D6D17B80080E83C /* TestURLSession.swift in Sources */,
4704393226BDFF34000D213E /* TestAttributedStringPerformance.swift in Sources */,
3EA9D6701EF0532D00B362D6 /* TestJSONEncoder.swift in Sources */,
D512D17C1CD883F00032E6A5 /* TestFileHandle.swift in Sources */,
D4FE895B1D703D1100DA7986 /* TestURLRequest.swift in Sources */,
Expand All @@ -3189,6 +3244,7 @@
155B77AC22E63D2D00D901DE /* TestURLCredentialStorage.swift in Sources */,
B951B5EC1F4E2A2000D8B332 /* TestNSLock.swift in Sources */,
5B13B33A1C582D4C00651CE2 /* TestNSNumber.swift in Sources */,
4704393426BDFF34000D213E /* TestAttributedString.swift in Sources */,
5B13B3521C582D4C00651CE2 /* TestNSValue.swift in Sources */,
7D0DE86F211883F500540061 /* Utilities.swift in Sources */,
5B13B3311C582D4C00651CE2 /* TestIndexPath.swift in Sources */,
Expand Down
53 changes: 53 additions & 0 deletions Sources/Foundation/AttributedString/AttributedString+Locking.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2021 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//

#if canImport(Darwin)
import Darwin

@available(macOS 10.12, iOS 10.0, tvOS 10.0, watchOS 3.0, *)
extension UnsafeMutablePointer where Pointee == os_unfair_lock_s {
internal init() {
let l = UnsafeMutablePointer.allocate(capacity: 1)
l.initialize(to: os_unfair_lock())
self = l
}

internal func cleanupLock() {
deinitialize(count: 1)
deallocate()
}

internal func lock() {
os_unfair_lock_lock(self)
}

internal func tryLock() -> Bool {
let result = os_unfair_lock_trylock(self)
return result
}

internal func unlock() {
os_unfair_lock_unlock(self)
}
}

@available(macOS 10.12, iOS 10.0, tvOS 10.0, watchOS 3.0, *)
typealias Lock = os_unfair_lock_t

#else
internal typealias Lock = NSLock

extension NSLock {
// Stub to match the API of os_unfair_lock_t
func cleanupLock() { /* NOOP */ }
}
#endif
Loading