Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

Add hyphenation remover #9

Merged
merged 1 commit into from
Feb 12, 2022

Conversation

meokz
Copy link
Contributor

@meokz meokz commented Feb 4, 2022

Hey, I implemented a hyphenation remover that removes unnecessary hyphenation from copied text from PDF. It is useful for preprocessing for translating English to other languages using Google Translate and DeepL. This is inspired by shaper (Ref: https://twitter.com/KeijiKobara/status/1391317599850430467?s=20&t=tb8xyWdcpLVKmAk99NNvMw)

Feel free to accept or decline this PR for reason that this is your personal project.

スクリーンショット 2022-02-04 18 09 03

@ObuchiYuki
Copy link
Collaborator

I also need to remove hyphenation when pasting into Deepl or Google Translate, and I feel the need for this tool. Therefore, I would like to incorporate this PR.
As for the UI implementation, it's done perfectly!

However, in the implementation below, doesn't it replace all " " in the original sentence?

private func getFormattedText(_ input: String) -> String {
    let lines = input
        .components(separatedBy: .newlines)
        .map { $0.replacingOccurrences(of: "- ", with: "") }
    let output = lines
        .joined(separator: " ")
        .replacingOccurrences(of: "  ", with: "\n")
    return output
}

If this is not a problem, please comment.

@meokz
Copy link
Contributor Author

meokz commented Feb 4, 2022

I think we don't need to worry about it. A single space in the original sentence will be preserved correctly.

Note that if there are two or more consecutive spaces in the original sentence, there is a mistake that will be replaced by a new line.

@ObuchiYuki
Copy link
Collaborator

@meokz Sorry for the late reply.
I see you said it's not a problem, so I'll merge it! Thanks for the new feature!

@ObuchiYuki ObuchiYuki merged commit e63426f into DevToys-app:main Feb 12, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants