mirror of
https://github.com/github/semantic.git
synced 2024-12-29 18:06:14 +03:00
fits
is a method.
This commit is contained in:
parent
9928fdaa77
commit
1829404979
@ -13,6 +13,16 @@ public enum Doc: CustomStringConvertible, Equatable {
|
||||
return "\n" + String(count: n, repeatedValue: " " as Character) + doc.description
|
||||
}
|
||||
}
|
||||
|
||||
public func fits(width: Int) -> Bool {
|
||||
guard width >= 0 else { return false }
|
||||
switch self {
|
||||
case .Empty, .Line:
|
||||
return true
|
||||
case let .Text(s, x):
|
||||
return x.fits(width - Int(s.characters.count))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public enum DOC {
|
||||
@ -107,21 +117,11 @@ func be(w: Int, _ k: Int, _ z: Stream<(Int, DOC)>) -> Doc {
|
||||
}
|
||||
|
||||
func better(w: Int, _ k: Int, _ x: Doc, _ y: Doc) -> Doc {
|
||||
return fits(w - k, x)
|
||||
return x.fits(w - k)
|
||||
? x
|
||||
: y
|
||||
}
|
||||
|
||||
func fits(w: Int, _ x: Doc) -> Bool {
|
||||
guard w >= 0 else { return false }
|
||||
switch x {
|
||||
case .Empty, .Line:
|
||||
return true
|
||||
case let .Text(s, x):
|
||||
return fits(w - Int(s.characters.count), x)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public protocol CustomDocConvertible: CustomStringConvertible {
|
||||
var doc: DOC { get }
|
||||
|
Loading…
Reference in New Issue
Block a user