-
Notifications
You must be signed in to change notification settings - Fork 501
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Allow usage of letters with diacritics or strokes in enum values and filenames. Closes #1530
- Loading branch information
1 parent
07ce058
commit b882d09
Showing
8 changed files
with
123 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
.../pinterest/ktlint/ruleset/standard/internal/RegExIgnoringDiacriticsAndStrokesOnLetters.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.pinterest.ktlint.ruleset.standard.internal | ||
|
||
/** | ||
* Transforms a string containing regular expression ranges like "A-Z" and "a-z" to a RegEx which checks whether a | ||
* unicode character has an uppercase versus a lowercase mapping to a letter. This function intents to keep the original | ||
* expression more readable | ||
*/ | ||
internal fun String.regExIgnoringDiacriticsAndStrokesOnLetters() = | ||
replace("A-Z", "\\p{Lu}") | ||
.replace("a-z", "\\p{Ll}") | ||
.toRegex() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
.../kotlin/com/pinterest/ktlint/ruleset/standard/internal/RemoveDiacriticsFromLettersTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.pinterest.ktlint.ruleset.standard.internal | ||
|
||
import org.assertj.core.api.Assertions.assertThat | ||
import org.junit.jupiter.params.ParameterizedTest | ||
import org.junit.jupiter.params.provider.ValueSource | ||
|
||
class RemoveDiacriticsFromLettersTest { | ||
@ParameterizedTest(name = "Original character: {0}, expected result: {1}") | ||
@ValueSource( | ||
strings = [ | ||
"àáâäæãåā", | ||
"çćč", | ||
"èéêëēėę", | ||
"îïíīįì", | ||
"ł", | ||
"ñń", | ||
"ôöòóœøōõ", | ||
"ßśš", | ||
"ûüùúū", | ||
"ÿ", | ||
"žźż", | ||
"ÀÁÂÄÆÃÅĀ", | ||
"ÇĆČ", | ||
"ÈÉÊËĒĖĘ", | ||
"ÎÏÍĪĮÌ", | ||
"Ł", | ||
"ÑŃ", | ||
"ÔÖÒÓŒØŌÕ", | ||
"ŚŠ", | ||
"ÛÜÙÚŪ", | ||
"Ÿ", | ||
"ŽŹŻ" | ||
] | ||
) | ||
fun `Given a letter with a diacritic then remove it`(original: String) { | ||
assertThat(original.matches("[A-Za-z]*".regExIgnoringDiacriticsAndStrokesOnLetters())).isTrue | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters