CutBox.app

Coverage Report

Created: 2024-03-12 03:40

.../Source/Extensions/String+Utils.swift
Line
Count
Source (jump to first uncovered line)
1
//
2
//  String+Utils.swift
3
//  CutBox
4
//
5
//  Created by denis.st on 29/4/19.
6
//  Copyright © 2018-2023 ocodo. All rights reserved.
7
//
8
9
import Foundation
10
11
extension String {
12
83
    func truncate(limit: Int, trailing: String = "…") -> String {
13
83
        guard limit > 0 else {
14
1
            return ""
15
82
        }
16
82
        if self.count > limit {
17
1
            return String(self.prefix(limit - 1)) + trailing
18
81
        } else {
19
81
            return self
20
81
        }
21
0
    }
22
}