Add prefix and suffix string trimming functions
This is needed to fix extraneous whitespace issues in image posts
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
@@ -40,6 +40,13 @@ class damusTests: XCTestCase {
|
||||
XCTAssertEqual(bytes.count, 32)
|
||||
}
|
||||
|
||||
func testTrimmingFunctions() {
|
||||
let txt = " bobs "
|
||||
|
||||
XCTAssertEqual(trim_prefix(txt), "bobs ")
|
||||
XCTAssertEqual(trim_suffix(txt), " bobs")
|
||||
}
|
||||
|
||||
func testParseMentionWithMarkdown() {
|
||||
let md = """
|
||||
Testing markdown in damus
|
||||
|
||||
Reference in New Issue
Block a user