Sort returned entities
This commit is contained in:
parent
bb61b15265
commit
45f56f01e3
@ -14,18 +14,19 @@ protocol TwitterEntity {
|
||||
}
|
||||
|
||||
extension TwitterEntity {
|
||||
var startIndex: Int? {
|
||||
if indices?.count ?? 0 > 0 {
|
||||
return indices?[0]
|
||||
|
||||
var startIndex: Int {
|
||||
if let indices = indices, indices.count > 0 {
|
||||
return indices[0]
|
||||
}
|
||||
return nil
|
||||
return 0
|
||||
}
|
||||
|
||||
var endIndex: Int? {
|
||||
if indices?.count ?? 0 > 1 {
|
||||
return indices?[1]
|
||||
var endIndex: Int {
|
||||
if let indices = indices, indices.count > 1 {
|
||||
return indices[1]
|
||||
}
|
||||
return nil
|
||||
return 0
|
||||
}
|
||||
|
||||
}
|
||||
@ -58,7 +59,7 @@ struct TwitterEntities: Codable {
|
||||
if let symbols = symbols {
|
||||
entities.append(contentsOf: symbols)
|
||||
}
|
||||
return entities
|
||||
return entities.sorted(by: { $0.startIndex < $1.startIndex })
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -18,6 +18,13 @@ struct TwitterHashtag: Codable, TwitterEntity {
|
||||
case indices = "indices"
|
||||
}
|
||||
|
||||
var startIndex: Int {
|
||||
if let indices = indices, indices.count > 0 {
|
||||
return indices[0] - 1
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func renderAsHTML() -> String {
|
||||
return ""
|
||||
}
|
||||
|
@ -18,6 +18,13 @@ struct TwitterSymbol: Codable, TwitterEntity {
|
||||
case indices = "indices"
|
||||
}
|
||||
|
||||
var startIndex: Int {
|
||||
if let indices = indices, indices.count > 0 {
|
||||
return indices[0] - 1
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func renderAsHTML() -> String {
|
||||
return ""
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user