stdlib: update comments and parameter names for startsWith() algorithm to

clearly reflect semantics

rdar://17567069


Swift SVN r19681
This commit is contained in:
Dmitri Hrybenko
2014-07-08 09:54:10 +00:00
parent 9f4c417095
commit 8fb09ef13a

View File

@@ -475,25 +475,24 @@ public func split<Seq: Sliceable, R:LogicValue>(
return result return result
} }
/// Return true iff the elements of `e1` are equal to the initial /// Return true iff the the initial elements of `s` are equal to `prefix`.
/// elements of `e2`.
public func startsWith< public func startsWith<
S0: Sequence, S1: Sequence S0: Sequence, S1: Sequence
where where
S0.GeneratorType.Element == S1.GeneratorType.Element, S0.GeneratorType.Element == S1.GeneratorType.Element,
S0.GeneratorType.Element : Equatable S0.GeneratorType.Element : Equatable
>(s0: S0, s1: S1) -> Bool >(s: S0, prefix: S1) -> Bool
{ {
var g1 = s1.generate() var prefixGenerator = prefix.generate()
for e0 in s0 { for e0 in s {
var e1 = g1.next() var e1 = prefixGenerator.next()
if !e1 { return true } if !e1 { return true }
if e0 != e1! { if e0 != e1! {
return false return false
} }
} }
return g1.next() ? false : true return prefixGenerator.next() ? false : true
} }
public struct EnumerateGenerator<Base: Generator> : Generator, Sequence { public struct EnumerateGenerator<Base: Generator> : Generator, Sequence {