initial commit
This commit is contained in:
25
IrisCompanion/iris/Utils/DataTrimming.swift
Normal file
25
IrisCompanion/iris/Utils/DataTrimming.swift
Normal file
@@ -0,0 +1,25 @@
|
||||
//
|
||||
// DataTrimming.swift
|
||||
// iris
|
||||
//
|
||||
// Created by Codex.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
extension Data {
|
||||
func trimmedTrailingWhitespace() -> Data {
|
||||
guard !isEmpty else { return self }
|
||||
var endIndex = count
|
||||
while endIndex > 0 {
|
||||
let b = self[endIndex - 1]
|
||||
if b == 0x0A || b == 0x0D || b == 0x20 || b == 0x09 {
|
||||
endIndex -= 1
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
return prefix(endIndex)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user