Skip to content

Commit e5dba78

Browse files
gribozavrMax Moiseev
authored and
Max Moiseev
committed
Improve comments in String.swift
1 parent 9ca2775 commit e5dba78

File tree

5 files changed

+24
-18
lines changed

5 files changed

+24
-18
lines changed

Diff for: stdlib/public/core/String.swift

+17-7
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212

1313
import SwiftShims
1414

15+
// FIXME: complexity documentation for most of methods on String is ought to be
16+
// qualified with "amortized" at least, as Characters are variable-length.
17+
1518
/// An arbitrary Unicode string value.
1619
///
1720
/// Unicode-Correct
@@ -567,7 +570,7 @@ public func < (lhs: String.Index, rhs: String.Index) -> Bool {
567570
}
568571

569572
extension String {
570-
/// Access the characters in `bounds`.
573+
/// Return the characters within the given `bounds`.
571574
///
572575
/// - Complexity: O(1) unless bridging from Objective-C requires an
573576
/// O(N) conversion.
@@ -654,7 +657,8 @@ extension Sequence where Iterator.Element == String {
654657
}
655658

656659
extension String {
657-
/// Replace the elements in `bounds` with `newElements`.
660+
/// Replace the characters within `bounds` with the elements of
661+
/// `replacement`.
658662
///
659663
/// Invalidates all indices with respect to `self`.
660664
///
@@ -670,7 +674,7 @@ extension String {
670674
}
671675
}
672676

673-
/// Replace the elements in `bounds` with `newElements`.
677+
/// Replace the text in `bounds` with `replacement`.
674678
///
675679
/// Invalidates all indices with respect to `self`.
676680
///
@@ -682,7 +686,7 @@ extension String {
682686
replaceSubrange(bounds, with: newElements.characters)
683687
}
684688

685-
/// Insert `newElement` at index `i`.
689+
/// Insert `newElement` at position `i`.
686690
///
687691
/// Invalidates all indices with respect to `self`.
688692
///
@@ -693,7 +697,7 @@ extension String {
693697
}
694698
}
695699

696-
/// Insert `newElements` at index `i`.
700+
/// Insert `newElements` at position `i`.
697701
///
698702
/// Invalidates all indices with respect to `self`.
699703
///
@@ -706,7 +710,7 @@ extension String {
706710
}
707711
}
708712

709-
/// Remove and return the element at index `i`.
713+
/// Remove and return the `Character` at position `i`.
710714
///
711715
/// Invalidates all indices with respect to `self`.
712716
///
@@ -728,7 +732,7 @@ extension String {
728732
}
729733
}
730734

731-
/// Remove all characters.
735+
/// Replace `self` with the empty string.
732736
///
733737
/// Invalidates all indices with respect to `self`.
734738
///
@@ -823,6 +827,9 @@ extension String {
823827
}
824828
}
825829

830+
/// Return `self` converted to lower case.
831+
///
832+
/// - Complexity: O(n)
826833
public var lowercaseString: String {
827834
if self._core.isASCII {
828835
let length = self._core.count
@@ -861,6 +868,9 @@ extension String {
861868
#endif
862869
}
863870

871+
/// Return `self` converted to upper case.
872+
///
873+
/// - Complexity: O(n)
864874
public var uppercaseString: String {
865875
if self._core.isASCII {
866876
let length = self._core.count

Diff for: stdlib/public/core/StringCharacterView.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ extension String.CharacterView : RangeReplaceableCollection {
266266
self.init("")
267267
}
268268

269-
/// Replace the elements in `bounds` with `newElements`.
269+
/// Replace the characters within `bounds` with `newElements`.
270270
///
271271
/// Invalidates all indices with respect to `self`.
272272
///

Diff for: stdlib/public/core/StringUTF16.swift

+4-6
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,7 @@ extension String {
9999
}
100100
#endif
101101

102-
/// Access the elements delimited by the given half-open range of
103-
/// indices.
102+
/// Get the contiguous subrange of elements enclosed by `bounds`.
104103
///
105104
/// - Complexity: O(1) unless bridging from Objective-C requires an
106105
/// O(N) conversion.
@@ -139,9 +138,9 @@ extension String {
139138
return "StringUTF16(\(self.description.debugDescription))"
140139
}
141140

142-
var _offset: Int
143-
var _length: Int
144-
let _core: _StringCore
141+
internal var _offset: Int
142+
internal var _length: Int
143+
internal let _core: _StringCore
145144
}
146145

147146
/// A UTF-16 encoding of `self`.
@@ -207,7 +206,6 @@ public func < (
207206
// We can do some things more efficiently, even if we don't promise to
208207
// by conforming to RandomAccessIndex.
209208

210-
/// Do not use this operator directly; call distance(start, end) instead.
211209
extension String.UTF16View.Index {
212210
@warn_unused_result
213211
public func distanceTo(end: String.UTF16View.Index)

Diff for: stdlib/public/core/StringUTF8.swift

+1-2
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,7 @@ extension String {
221221
return result
222222
}
223223

224-
/// Access the elements delimited by the given half-open range of
225-
/// indices.
224+
/// Access the contiguous subrange of elements enclosed by `bounds`.
226225
///
227226
/// - Complexity: O(1) unless bridging from Objective-C requires an
228227
/// O(N) conversion.

Diff for: stdlib/public/core/StringUnicodeScalarView.swift

+1-2
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,7 @@ extension String {
129129
}
130130
}
131131

132-
/// Access the elements delimited by the given half-open range of
133-
/// indices.
132+
/// Access the contiguous subrange of elements enclosed by `bounds`.
134133
///
135134
/// - Complexity: O(1) unless bridging from Objective-C requires an
136135
/// O(N) conversion.

0 commit comments

Comments
 (0)