damus

nostr ios client
git clone git://jb55.com/damus
Log | Files | Refs | README | LICENSE

commit b131c74ee367a8c12fda70cce555eeeb22aeaf60
parent b9fed6e4eb0fb7e8d4119f073030e96e4dccc7e9
Author: William Casarin <jb55@jb55.com>
Date:   Wed,  5 Apr 2023 12:48:03 -0700

Add prefix and suffix string trimming functions

This is needed to fix extraneous whitespace issues in image posts

Diffstat:
Mdamus/Views/NoteContentView.swift | 11+++++++++++
MdamusTests/damusTests.swift | 7+++++++
2 files changed, 18 insertions(+), 0 deletions(-)

diff --git a/damus/Views/NoteContentView.swift b/damus/Views/NoteContentView.swift @@ -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) +} diff --git a/damusTests/damusTests.swift b/damusTests/damusTests.swift @@ -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