Commit Graph

94 Commits

Author SHA1 Message Date
Guillaume Lessard 6e140559b8 [stdlib] rephrase some doc-comment notes with active voice 2026-05-12 13:56:51 -07:00
Guillaume Lessard eb8cea792c [stdlib] apply code fences to doc-comment code examples 2026-05-12 13:11:31 -07:00
Guillaume Lessard e4db90b222 [stdlib] improve doc-comments for span and bytes properties 2026-05-07 10:29:01 -07:00
Doug Gregor e4512739a8 Fix indentation 2026-04-17 16:04:07 -07:00
Doug Gregor 453277eb74 Mark the various with* functions as @safe
Functions like withUnsafeBufferPointer are, by themselves, safe to
call. It's only the operations on the unsafe pointers passed into the
closure that are the safety issue.

This was the intent spelled out in SE-0458 but was not fully realized
in the library.

Fixes rdar://174519372.
2026-04-16 22:37:54 -07:00
Clinton Nkwocha 2385488c84 Generalize String functions for typed throws (#87495)
Generalizes `String`:
- `init(unsafeUninitializedCapacity:initializingUTF8With:)`
- `withCString(_:)`
- `withCString(encodedAs:_:)`
- `withUTF8(_:)`
- `_withNFCCodeUnits(_:)`

and `Substring`:
  - `withCString(_:)`
  - `withCString(encodedAs:_:)`
  - `withUTF8(_:)`

for typed throws.
2026-03-10 11:27:06 +00:00
Guillaume Lessard a2c52c5e89 [stdlib] support typed throws in filter closures 2026-02-09 13:12:59 -08:00
Karoy Lorentey e5787c661d [stdlib] String, Substring: Use new _StringGuts helper 2025-12-08 17:32:20 -08:00
Karoy Lorentey 4cde919950 [stdlib] Update availability of String view additions 2025-12-08 17:32:20 -08:00
WindowsMEMZ 14e37a15ec Make isIdentical opaque for clients 2025-12-08 17:32:19 -08:00
WindowsMEMZ be5ec1aed4 Add isTriviallyIdentical for unicode views 2025-12-08 17:32:19 -08:00
Karoy Lorentey c8202c6f9a Apply suggestions from code review 2025-12-08 17:32:19 -08:00
Karoy Lorentey b7e32db453 [stdlib] Update availability of isTriviallyIdentical methods 2025-12-08 17:32:19 -08:00
Rick van Voorden abae2f6547 [stdlib] string identical
Co-Authored-By: Karoy Lorentey <klorentey@apple.com>
2025-12-08 17:32:19 -08:00
Guillaume Lessard dd833569e0 [stdlib] rename Span.extracting functions 2025-07-09 17:25:27 -07:00
Guillaume Lessard 791dd4cb0a [stdlib] name your constants better
- computed properties have an ABI impact; a function is fine here
2025-06-25 22:01:28 -07:00
Guillaume Lessard 4a13c916d7 [stdlib] name your constants 2025-06-24 17:19:48 -07:00
Guillaume Lessard e8f0d52fe2 [gardening] labels for conditional compilation markers 2025-06-24 17:10:37 -07:00
Guillaume Lessard 3aad241019 [stdlib] address 32-bit watchOS ABI issue 2025-06-23 18:31:16 -07:00
Guillaume Lessard 9e8019a0fe [stdlib] make annotation adjustments 2025-06-06 08:21:48 -07:00
Guillaume Lessard 524b717944 [stdlib] work around autoclosure issues
- The move-only checker has issues with the existence of autoclosures.
- These `borrowing` accessors are within the purview of the move-only checker.
2025-04-14 10:48:42 -07:00
Guillaume Lessard 2d50c6cce9 Revert "[temporary] disable small-string support"
This reverts commit ea44ff9fc9.
2025-04-14 10:48:42 -07:00
Allan Shortlidge 14e0eed88f stdlib: Address unreachable code warnings. 2025-04-03 10:19:46 -07:00
Allan Shortlidge d32310fb76 stdlib: Address new #StrictMemorySafety warnings. 2025-04-03 10:18:39 -07:00
Guillaume Lessard f3a01663ac [stdlib] document limitations for Substring’s span 2025-04-02 17:53:13 -07:00
Guillaume Lessard bde7a1871c [stdlib] harden bounds checking in Substring’s span 2025-04-02 17:53:12 -07:00
Guillaume Lessard ea44ff9fc9 [temporary] disable small-string support 2025-04-02 17:53:12 -07:00
Guillaume Lessard 6059be4bca [stdlib] simplify spans of bridged substrings 2025-03-31 12:05:50 -07:00
Guillaume Lessard 85a9be6a1b [stdlib] spans over bridged Substring instances 2025-03-31 12:05:50 -07:00
Guillaume Lessard a061425aae [stdlib] add storage property to Substring.UTF8View 2025-03-31 12:05:50 -07:00
Guillaume Lessard dfb2e2f12e [stdlib] annotate uses of Range.init(_uncheckedBounds:) 2025-03-05 18:52:11 -08:00
Doug Gregor 22eecacc35 Adopt unsafe annotations throughout the standard library 2025-02-26 14:28:01 -08:00
Guillaume Lessard 8912098c01 [doc] adjust to reflect the current implementation. 2023-07-12 14:13:19 -07:00
Valeriy Van 95d25d3ba5 Minor comment typo fix 2022-11-15 10:40:43 +02:00
Karoy Lorentey cb2194c024 [stdlib] Fix ABI and portability issues 2022-04-13 19:15:30 -07:00
Karoy Lorentey b33fefb71c [stdlib] String: be more consistent about when markEncoding is called 2022-04-13 18:38:41 -07:00
Karoy Lorentey 67adcabefc Apply notes from code review 2022-04-10 00:14:43 -07:00
Karoy Lorentey 3c9968945e [stdlib] String: Implement happy paths for index validation 2022-04-10 00:14:43 -07:00
Karoy Lorentey d24ae9dfcd [stdlib] Remove Substring._endIsCharacterAligned
Now that the cached character stride in indices always mean the
stride in the full string, we can stop looking at whether a substring
has a character-aligned end index.
2022-04-09 21:33:53 -07:00
Karoy Lorentey 83df814c63 [stdlib] _StringObject.isKnownUTF16 → isForeignUTF8
This fixes a compatibility issue with potential future UTF-8 encoded
foreign String forms, as well as simplifying the code a bit — we no
longer need to do an availability check on inlinable fast paths.

The isForeignUTF8 bit is never set by any past or current stdlib
version, but it allows us to introduce UTF-8 encoded foreign forms
without breaking inlinable index encoding validation introduced in
Swift 5.7.
2022-04-09 21:33:53 -07:00
Karoy Lorentey 73312fedd4 [stdlib] Grapheme breaking: Refactor to simplify logic
- Split forward and backward direction into separate code paths.
  This makes the code more readable and paves the way for future
  improvements. (E.g., switching to a linear-time algorithm for
  breaking backwards.)
- `Substring.index(after:)` now uses the same grapheme breaking paths
  as `String.index(after:)`.
- The cached stride value in string indices is now well-defined even
  on indices that aren’t character-aligned.
2022-04-05 20:47:42 -07:00
Karoy Lorentey e0bd5f7a79 [stdlib] Fix Substring.UnicodeScalarView.replaceSubrange 2022-04-05 20:47:42 -07:00
Karoy Lorentey 2e9fd9eb6b [stdlib] Substring.UnicodeScalarView: Add _invariantCheck 2022-04-05 20:47:42 -07:00
Karoy Lorentey f7c674ed55 [stdlib] Slice._bounds, Range<String.Index>._encodedOffsetRange: New helpers 2022-04-05 20:47:42 -07:00
Karoy Lorentey ff58d54565 [stdlib][NFC] Substring adjustments 2022-03-29 20:10:40 -07:00
Karoy Lorentey c9adf7aaea [stdlib] Substring: Review view creation/conversion code 2022-03-29 20:10:40 -07:00
Karoy Lorentey b7c54ac41c [stdlib] Substring.init: Stop checking things twice 2022-03-29 20:00:08 -07:00
Karoy Lorentey 9714f97ad8 [stdlib] Substring: round indices down to nearest character in indexing operations
Distances between indices aren’t well-defined without this.
2022-03-29 20:00:08 -07:00
Karoy Lorentey 4eab8355ca [stdlib] String: prefer passing ranges to start+end argument pairs 2022-03-29 20:00:08 -07:00
Karoy Lorentey 4ad8b26ab3 [stdlib] String.UTF16View: Review/fix index validation
Also, in UTF-16 slices, forward collection methods to the base view
instead of `Slice`, to make behavior a bit easier to understand.

(There is no need to force readers to page in `Slice`
implementations _in addition to_ whatever the base view is doing.)
2022-03-29 20:00:08 -07:00