Skip to content

Commit

Permalink
Remove unnecessary scan, improve docs
Browse files Browse the repository at this point in the history
  • Loading branch information
p4checo committed Apr 5, 2021
1 parent 0f7a36a commit df87dac
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
9 changes: 3 additions & 6 deletions Sources/Extensions/Foundation/String.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,6 @@ extension String {
// exit early if we're already at the end
guard !scanner.isAtEnd else { break }

// skip characters if needed
if let charactersToBeSkipped = charactersToBeSkipped {
scanner.scanCharacters(from: charactersToBeSkipped, into: nil)
}

// find and replace matching character if needed
replacementMap
.first { match, _ in scanner.scanString(String(match), into: nil) }
Expand All @@ -123,6 +118,8 @@ extension String {
/// corresponding non line breaking variants when existent. Otherwise, word joiner characters are attached to them
/// to make them non line breaking.
///
/// - Important: Any existing newline characters are preserved.
///
/// The character mapping is:
/// - space (" ") -> non breaking space (`U+2028`)
/// - hyphen ("-") -> non breaking hyphen (`U+00A0`)
Expand All @@ -141,7 +138,7 @@ extension String {
.emDash: String([.wordJoiner, .emDash, .wordJoiner]),
.enDash: String([.wordJoiner, .enDash, .wordJoiner]),
"?": "?" + .wordJoiner,
"}": "}" + .wordJoiner,
"}": "}" + .wordJoiner
],
skippingCharactersIn: nil
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ class StringTestCase: XCTestCase {

let original =
"""
\nThe quick-brown\u{85}\(String.emDash)fox\n\(String.enDash)jumps?\u{2028}\u{2029}over{the}lazy dog\n
\nThe quick-brown\u{85}\(String.emDash)fox\n\(String.enDash)jumps?\u{2028}\u{2029}over{the}lazy dog\n\
\u{A}.\u{B},\u{C};\u{D}
"""

Expand All @@ -166,7 +166,7 @@ class StringTestCase: XCTestCase {
\(String([.wordJoiner, .emDash, .wordJoiner]))fox\n\
\(String([.wordJoiner, .enDash, .wordJoiner]))jumps\
?\(String.wordJoiner)\u{2028}\u{2029}over\
{the}\(String.wordJoiner)lazy\(String.nonBreakingSpace)dog\n
{the}\(String.wordJoiner)lazy\(String.nonBreakingSpace)dog\n\
\u{A}.\u{B},\u{C};\u{D}
"""

Expand Down

0 comments on commit df87dac

Please sign in to comment.