[Fix] 制約の適用を調整した (#96)

* zenz-v1側は制約をコードポイントレベルで喋るので、grapheme clusterに非依存の処理に書き換えた

* EOSを考慮するように変更
This commit is contained in:
Miwa
2024-05-19 19:35:28 +09:00
committed by GitHub
parent dfef9631a9
commit c8ca5b54c0
4 changed files with 84 additions and 26 deletions

View File

@@ -86,6 +86,20 @@ public extension Collection {
}
public extension Collection where Self.Element: Equatable {
/// Returns a Bool value indicating whether the collection has the given prefix.
/// - Parameters:
/// - prefix: A collection to search for at the start of this collection.
/// - Returns: A Bool value indicating whether the collection has the given prefix.
@inlinable func hasPrefix(_ prefix: some Collection<Element>) -> Bool {
if self.count < prefix.count {
return false
}
for (u, v) in zip(self, prefix) where u != v {
return false
}
return true
}
/// Returns a Bool value indicating whether the collection has the given suffix.
/// - Parameters:
/// - suffix: A collection to search for at the end of this collection.