mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-24 07:05:35 +00:00
[WIP] Star refs
This commit is contained in:
@@ -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))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user