Add prefix and suffix string trimming functions

This is needed to fix extraneous whitespace issues in image posts
This commit is contained in:
William Casarin
2023-04-05 12:48:03 -07:00
parent b9fed6e4eb
commit b131c74ee3
2 changed files with 18 additions and 0 deletions

View File

@@ -346,3 +346,14 @@ struct TruncatedText: View {
return AttributedString(truncatedAttributedString) + "..."
}
}
// trim suffix whitespace and newlines
func trim_suffix(_ str: String) -> String {
return str.replacingOccurrences(of: "\\s+$", with: "", options: .regularExpression)
}
// trim prefix whitespace and newlines
func trim_prefix(_ str: String) -> String {
return str.replacingOccurrences(of: "^\\s+", with: "", options: .regularExpression)
}