[WIP] Star refs

This commit is contained in:
Isaac
2024-11-28 16:13:06 +04:00
parent 17bd869ddd
commit be83150aba
59 changed files with 3764 additions and 717 deletions

View File

@@ -1,5 +1,6 @@
import Foundation
import PresentationStrings
import TelegramCore
public func compactNumericCountString(_ count: Int, decimalSeparator: String = ".") -> String {
if count >= 1000 * 1000 {
@@ -38,6 +39,28 @@ public func presentationStringsFormattedNumber(_ count: Int32, _ groupingSeparat
}
}
public func presentationStringsFormattedNumber(_ starsAmount: StarsAmount, _ groupingSeparator: String = "") -> String {
if starsAmount.nanos == 0 {
let count = Int32(starsAmount.value)
let string = "\(count)"
if groupingSeparator.isEmpty || abs(count) < 1000 {
return string
} else {
var groupedString: String = ""
for i in 0 ..< Int(ceil(Double(string.count) / 3.0)) {
let index = string.count - Int(i + 1) * 3
if !groupedString.isEmpty {
groupedString = groupingSeparator + groupedString
}
groupedString = String(string[string.index(string.startIndex, offsetBy: max(0, index)) ..< string.index(string.startIndex, offsetBy: index + 3)]) + groupedString
}
return groupedString
}
} else {
return starsAmount.stringValue
}
}
public func dayIntervalString(strings: PresentationStrings, days: Int32) -> String {
return strings.MessageTimer_Days(max(0, days))
}