Created
May 9, 2012 15:39
-
-
Save fumokmm/2645657 to your computer and use it in GitHub Desktop.
javaとかScalaで全角を半角に変換する方法をGroovyでもやってみた
This file contains hidden or 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
| @Grab('com.ibm.icu:icu4j:4.8.1.1') | |
| import com.ibm.icu.text.Transliterator | |
| def transliterator = Transliterator.getInstance('Fullwidth-Halfwidth') | |
| def testData = [ | |
| [ input: '這いよれ! ニャル子さん 4' , | |
| expect: '這いよれ! ニャル子さん 4' ], | |
| [ input: 'ABC' , | |
| expect: 'ABC' ], | |
| [ input: 'あ い う え お', | |
| expect: 'あ い う え お' ], | |
| ] | |
| testData.each { | |
| assert transliterator.transliterate(it.input) == it.expect | |
| } |
This file contains hidden or 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
| // http://mvnrepository.com/artifact/org.spockframework/spock-core | |
| // cf. http://npnl.hatenablog.jp/entry/2012/05/10/004748 | |
| // cf. http://d.hatena.ne.jp/fumokmm/20110421/1303404232 | |
| @Grab('org.spockframework:spock-core:0.6-groovy-1.8') | |
| @Grab('com.ibm.icu:icu4j:4.8.1.1') | |
| import spock.lang.* | |
| import com.ibm.icu.text.Transliterator | |
| class ICU4JTest extends Specification { | |
| def transliterator = Transliterator.getInstance('Fullwidth-Halfwidth') | |
| def '全角を半角にする'() { | |
| expect: transliterator.transliterate(input) == expect | |
| where: | |
| input | expect | |
| '這いよれ! ニャル子さん 4' | '這いよれ! ニャル子さん 4' | |
| 'ABC' | 'ABC' | |
| 'あ い う え お' | 'あ い う え お' | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment