forked from Devskiller/jfairy
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improved email romanization by introducing CharConverter
- Loading branch information
1 parent
418486d
commit 22556b2
Showing
8 changed files
with
75 additions
and
2 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
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
9 changes: 9 additions & 0 deletions
9
src/main/java/io/codearte/jfairy/producer/util/CharConverter.java
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,9 @@ | ||
package io.codearte.jfairy.producer.util; | ||
|
||
/** | ||
* @author Jakub Kubrynski | ||
*/ | ||
public interface CharConverter { | ||
|
||
String romanize(String value); | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/io/codearte/jfairy/producer/util/locale/NonOpCharConverter.java
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,14 @@ | ||
package io.codearte.jfairy.producer.util.locale; | ||
|
||
import io.codearte.jfairy.producer.util.CharConverter; | ||
|
||
/** | ||
* @author Jakub Kubrynski | ||
*/ | ||
public class NonOpCharConverter implements CharConverter { | ||
|
||
@Override | ||
public String romanize(String value) { | ||
return value; | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/io/codearte/jfairy/producer/util/locale/PlCharConverter.java
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,18 @@ | ||
package io.codearte.jfairy.producer.util.locale; | ||
|
||
import io.codearte.jfairy.producer.util.CharConverter; | ||
import org.apache.commons.lang3.StringUtils; | ||
|
||
/** | ||
* @author Jakub Kubrynski | ||
*/ | ||
public class PlCharConverter implements CharConverter { | ||
|
||
private static final String[] POLISH_CHARS = {"ą", "ć", "ę", "ł", "ń", "ś", "ó", "ź", "ż"}; | ||
private static final String[] LATIN_CHARS = {"a", "c", "e", "l", "n", "s", "o", "z", "z"}; | ||
|
||
@Override | ||
public String romanize(String value) { | ||
return StringUtils.replaceEachRepeatedly(value, POLISH_CHARS, LATIN_CHARS); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/test/groovy/io/codearte/jfairy/producer/util/locale/PlCharConverterSpec.groovy
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,20 @@ | ||
package io.codearte.jfairy.producer.util.locale | ||
|
||
import spock.lang.Specification | ||
|
||
/** | ||
* @author Jakub Kubrynski | ||
*/ | ||
class PlCharConverterSpec extends Specification { | ||
|
||
PlCharConverter charConverter = new PlCharConverter() | ||
|
||
def "should romanize polish text"() { | ||
given: | ||
String input = "Zażółć gęślą jaźń" | ||
when: | ||
def output = charConverter.romanize(input) | ||
then: | ||
output == "Zazolc gesla jazn" | ||
} | ||
} |