├── wanakana-core ├── build.gradle └── src │ └── main │ └── java │ └── com │ └── wanakanajava │ └── WanaKanaJava.java ├── settings.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── example └── src │ └── main │ ├── res │ ├── drawable-hdpi │ │ └── ic_launcher.png │ ├── drawable-mdpi │ │ └── ic_launcher.png │ ├── drawable-xhdpi │ │ └── ic_launcher.png │ ├── drawable-xxhdpi │ │ └── ic_launcher.png │ ├── values │ │ ├── strings.xml │ │ ├── styles.xml │ │ └── dimens.xml │ └── layout │ │ ├── activity_main.xml │ │ └── fragment_main.xml │ ├── AndroidManifest.xml │ └── java │ └── com │ └── wanakanajava │ └── MainActivity.java ├── wanakana-android ├── src │ └── main │ │ ├── AndroidManifest.xml │ │ └── java │ │ └── com │ │ └── wanakanajava │ │ └── WanaKanaJavaText.java └── build.gradle ├── .gitignore ├── LICENSE ├── README.md ├── gradlew.bat └── gradlew /wanakana-core/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'java' 2 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include 'wanakana-core' 2 | include 'wanakana-android' 3 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MasterKale/WanaKanaJava/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /example/src/main/res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MasterKale/WanaKanaJava/HEAD/example/src/main/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/src/main/res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MasterKale/WanaKanaJava/HEAD/example/src/main/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/src/main/res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MasterKale/WanaKanaJava/HEAD/example/src/main/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/src/main/res/drawable-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MasterKale/WanaKanaJava/HEAD/example/src/main/res/drawable-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /wanakana-android/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /example/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | WanaKanaJava 5 | WanaKanaJava IME Test 6 | 7 | 8 | -------------------------------------------------------------------------------- /example/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /example/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 6 | 7 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Mon Sep 14 16:24:47 JST 2015 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.6-bin.zip 7 | -------------------------------------------------------------------------------- /example/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 8 | -------------------------------------------------------------------------------- /wanakana-android/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'android-library' 2 | 3 | android { 4 | 5 | compileSdkVersion 15 6 | buildToolsVersion "23.0.1" 7 | 8 | defaultConfig { 9 | minSdkVersion 14 10 | targetSdkVersion 15 11 | versionCode 1 12 | versionName "1.0" 13 | } 14 | } 15 | 16 | dependencies { 17 | compile project(':wanakana-core') 18 | } 19 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # Files for the Dalvik VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # Generated files 12 | bin/ 13 | gen/ 14 | 15 | # Gradle files 16 | .gradle/ 17 | build/ 18 | 19 | # Local configuration file (sdk path, etc) 20 | local.properties 21 | 22 | # Proguard folder generated by Eclipse 23 | proguard/ 24 | 25 | # Log Files 26 | *.log 27 | 28 | # Android Studio Navigation editor temp files 29 | .navigation/ 30 | 31 | # Android Studio captures folder 32 | captures/ 33 | -------------------------------------------------------------------------------- /example/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 10 | 11 | 16 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /example/src/main/res/layout/fragment_main.xml: -------------------------------------------------------------------------------- 1 | 10 | 11 | 16 | 17 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2013 Matthew Miller 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /example/src/main/java/com/wanakanajava/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.wanakanajava; 2 | 3 | import android.app.Activity; 4 | import android.app.Fragment; 5 | import android.os.Bundle; 6 | import android.view.LayoutInflater; 7 | import android.view.View; 8 | import android.view.ViewGroup; 9 | import android.widget.EditText; 10 | 11 | public class MainActivity extends Activity 12 | { 13 | 14 | @Override 15 | protected void onCreate(Bundle savedInstanceState) 16 | { 17 | super.onCreate(savedInstanceState); 18 | setContentView(R.layout.activity_main); 19 | 20 | if (savedInstanceState == null) 21 | { 22 | getFragmentManager().beginTransaction() 23 | .add(R.id.container, new PlaceholderFragment()) 24 | .commit(); 25 | } 26 | 27 | } 28 | 29 | /** 30 | * A placeholder fragment containing a simple view. 31 | */ 32 | public static class PlaceholderFragment extends Fragment 33 | { 34 | @Override 35 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) 36 | { 37 | View rootView = inflater.inflate(R.layout.fragment_main, container, false); 38 | EditText et = (EditText) rootView.findViewById(R.id.editText); 39 | 40 | WanaKanaJavaText wkj = new WanaKanaJavaText(et, false); 41 | wkj.bind(); 42 | 43 | return rootView; 44 | } 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /wanakana-android/src/main/java/com/wanakanajava/WanaKanaJavaText.java: -------------------------------------------------------------------------------- 1 | package com.wanakanajava; 2 | 3 | import android.text.Editable; 4 | import android.text.TextWatcher; 5 | import android.widget.EditText; 6 | 7 | /** 8 | * A Java version of the Javascript WanaKana romaji-to-kana converter library (https://github.com/WaniKani/WanaKana) 9 | * Version 1.1.1 10 | */ 11 | public class WanaKanaJavaText 12 | { 13 | static final String TAG = "WanaKanaJava"; 14 | 15 | EditText gInputWindow; 16 | 17 | WanaKanaJava wanaKana; 18 | 19 | public WanaKanaJavaText(EditText et, Boolean useObsoleteKana) 20 | { 21 | this(et, new WanaKanaJava(useObsoleteKana)); 22 | } 23 | 24 | public WanaKanaJavaText(EditText et, WanaKanaJava wanaKana) 25 | { 26 | gInputWindow = et; 27 | this.wanaKana = wanaKana; 28 | } 29 | 30 | TextWatcher tw = new TextWatcher() 31 | { 32 | @Override 33 | public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {} 34 | 35 | @Override 36 | public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {} 37 | 38 | @Override 39 | public void afterTextChanged(Editable romaji) 40 | { 41 | unbind(); 42 | // Convert the text 43 | String sKana = wanaKana.toKana(romaji.toString()); 44 | gInputWindow.setText(sKana); 45 | gInputWindow.setSelection(gInputWindow.getText().length()); 46 | bind(); 47 | } 48 | }; 49 | 50 | // Bind a listener to the EditText so we know to start converting text entered into it 51 | public void bind() 52 | { 53 | if(gInputWindow != null) 54 | { 55 | gInputWindow.addTextChangedListener(tw); 56 | } 57 | } 58 | 59 | // Stop listening to text input on the EditText 60 | public void unbind() 61 | { 62 | if(gInputWindow != null) 63 | { 64 | gInputWindow.removeTextChangedListener(tw); 65 | } 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | WanaKanaJava 2 | ============ 3 | 4 | I converted WanaKana (https://github.com/wanikani/wanakana) to Java for use in Android projects. I targeted SDK 14 and up, but this'll probably work with prior versions of Android as well. 5 | 6 | Usage 7 | ============ 8 | Here's how to instantiate the class: 9 | ```java 10 | // Pass in an EditText and a boolean to indicate whether or not you want to use obsolete kana such as ゐ and ゑ 11 | EditText et = (EditText) findViewById(R.id.editText); 12 | WanaKanaJava wkj = new WanaKanaJava(et, false); 13 | ``` 14 | 15 | The methods described on WanaKana's documentation (https://github.com/WaniKani/WanaKana/blob/master/README.md#documentation) should all work in the same manner. I took some slight liberties on bind() and unbind(), though - you don't need to pass anything along when you call them: 16 | ```java 17 | // Binds a TextWatcher to the EditText so any text input is converted 18 | WanaKanaJava.bind(); 19 | 20 | // Unbinds the TextWatcher from the EditText 21 | WanaKanaJava.unbind(); 22 | 23 | // Returns false if string contains mixed characters, otherwise true if Hiragana. 24 | WanaKanaJava.isHiragana(String); 25 | 26 | // Returns false if string contains characters outside of the kana family, otherwise true if Hiragana and/or Katakana. 27 | WanaKanaJava.isKana(String); 28 | 29 | //Returns false if string contains mixed characters, otherwise true if Katakana. 30 | WanaKanaJava.isKatakana(String); 31 | 32 | // Convert Katakana or Romaji to Hiragana. 33 | WanaKanaJava.toHiragana(String); 34 | 35 | // Convert Romaji to Kana. Lowcase entries output Hiragana, while upcase entries output Katakana. 36 | WanaKanaJava.toKana(String); 37 | 38 | // Convert Hiragana or Romaji to Katakana. 39 | WanaKanaJava.toKatakana(String); 40 | 41 | // Convert Kana to Romaji. 42 | WanaKanaJava.toRomaji(String); 43 | ``` 44 | 45 | Screenshot 46 | ========== 47 | I included a sample app so you can see a practical implementation of WanaKanaJava. Here's a screenshot of that app 48 | in action on a Nexus 7 running 4.3: 49 | ![Imgur](http://i.imgur.com/LvTuVqY.png) 50 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # For Cygwin, ensure paths are in UNIX format before anything is touched. 46 | if $cygwin ; then 47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 48 | fi 49 | 50 | # Attempt to set APP_HOME 51 | # Resolve links: $0 may be a link 52 | PRG="$0" 53 | # Need this for relative symlinks. 54 | while [ -h "$PRG" ] ; do 55 | ls=`ls -ld "$PRG"` 56 | link=`expr "$ls" : '.*-> \(.*\)$'` 57 | if expr "$link" : '/.*' > /dev/null; then 58 | PRG="$link" 59 | else 60 | PRG=`dirname "$PRG"`"/$link" 61 | fi 62 | done 63 | SAVED="`pwd`" 64 | cd "`dirname \"$PRG\"`/" >&- 65 | APP_HOME="`pwd -P`" 66 | cd "$SAVED" >&- 67 | 68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 69 | 70 | # Determine the Java command to use to start the JVM. 71 | if [ -n "$JAVA_HOME" ] ; then 72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 73 | # IBM's JDK on AIX uses strange locations for the executables 74 | JAVACMD="$JAVA_HOME/jre/sh/java" 75 | else 76 | JAVACMD="$JAVA_HOME/bin/java" 77 | fi 78 | if [ ! -x "$JAVACMD" ] ; then 79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 80 | 81 | Please set the JAVA_HOME variable in your environment to match the 82 | location of your Java installation." 83 | fi 84 | else 85 | JAVACMD="java" 86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 87 | 88 | Please set the JAVA_HOME variable in your environment to match the 89 | location of your Java installation." 90 | fi 91 | 92 | # Increase the maximum file descriptors if we can. 93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 94 | MAX_FD_LIMIT=`ulimit -H -n` 95 | if [ $? -eq 0 ] ; then 96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 97 | MAX_FD="$MAX_FD_LIMIT" 98 | fi 99 | ulimit -n $MAX_FD 100 | if [ $? -ne 0 ] ; then 101 | warn "Could not set maximum file descriptor limit: $MAX_FD" 102 | fi 103 | else 104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 105 | fi 106 | fi 107 | 108 | # For Darwin, add options to specify how the application appears in the dock 109 | if $darwin; then 110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 111 | fi 112 | 113 | # For Cygwin, switch paths to Windows format before running java 114 | if $cygwin ; then 115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 158 | function splitJvmOpts() { 159 | JVM_OPTS=("$@") 160 | } 161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 163 | 164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 165 | -------------------------------------------------------------------------------- /wanakana-core/src/main/java/com/wanakanajava/WanaKanaJava.java: -------------------------------------------------------------------------------- 1 | package com.wanakanajava; 2 | 3 | import java.util.HashMap; 4 | import java.util.regex.Matcher; 5 | import java.util.regex.Pattern; 6 | 7 | /** 8 | * A Java version of the Javascript WanaKana romaji-to-kana converter library (https://github.com/WaniKani/WanaKana) 9 | * Version 1.1.1 10 | */ 11 | public class WanaKanaJava 12 | { 13 | 14 | //static final int LOWERCASE_START = 0x61; 15 | //static final int LOWERCASE_END = 0x7A; 16 | static final int UPPERCASE_START = 0x41; 17 | static final int UPPERCASE_END = 0x5A; 18 | static final int HIRAGANA_START = 0x3041; 19 | static final int HIRAGANA_END = 0x3096; 20 | static final int KATAKANA_START = 0x30A1; 21 | static final int KATAKANA_END = 0x30FA; 22 | 23 | HashMap mOptions = new HashMap(); 24 | static final String OPTION_USE_OBSOLETE_KANA = "useObsoleteKana"; 25 | static final String OPTION_IME_MODE = "IMEMode"; 26 | 27 | HashMap mRtoJ = new HashMap(); 28 | HashMap mJtoR = new HashMap(); 29 | 30 | private interface Command 31 | { 32 | public boolean run(String str); 33 | } 34 | 35 | public WanaKanaJava(Boolean useObsoleteKana) 36 | { 37 | 38 | mOptions.put(OPTION_USE_OBSOLETE_KANA, useObsoleteKana); 39 | mOptions.put(OPTION_IME_MODE, false); 40 | 41 | prepareRtoJ(); 42 | prepareJtoR(); 43 | } 44 | 45 | // Pass every character of a string through a function and return TRUE if every character passes the function's check 46 | private boolean _allTrue(String checkStr, Command func) 47 | { 48 | for (int _i = 0; _i < checkStr.length(); _i++) 49 | { 50 | if (!func.run(String.valueOf(checkStr.charAt(_i)))) 51 | { 52 | return false; 53 | } 54 | } 55 | return true; 56 | } 57 | 58 | // Check if a character is within a Unicode range 59 | private boolean _isCharInRange(char chr, int start, int end) 60 | { 61 | int code = (int) chr; 62 | return (start <= code && code <= end); 63 | } 64 | 65 | private boolean _isCharVowel(char chr, boolean includeY) 66 | { 67 | Pattern regexp = includeY ? Pattern.compile("[aeiouy]") : Pattern.compile("[aeiou]"); 68 | Matcher matcher = regexp.matcher(String.valueOf(chr)); 69 | 70 | return matcher.find(); 71 | } 72 | 73 | private boolean _isCharConsonant(char chr, boolean includeY) 74 | { 75 | Pattern regexp = includeY ? Pattern.compile("[bcdfghjklmnpqrstvwxyz]") : Pattern.compile("[bcdfghjklmnpqrstvwxz]"); 76 | Matcher matcher = regexp.matcher(String.valueOf(chr)); 77 | 78 | return matcher.find(); 79 | } 80 | 81 | private boolean _isCharKatakana(char chr) 82 | { 83 | return _isCharInRange(chr, KATAKANA_START, KATAKANA_END); 84 | } 85 | 86 | private boolean _isCharHiragana(char chr) 87 | { 88 | return _isCharInRange(chr, HIRAGANA_START, HIRAGANA_END); 89 | } 90 | 91 | private boolean _isCharKana(char chr) 92 | { 93 | return _isCharHiragana(chr) || _isCharKatakana(chr); 94 | } 95 | 96 | private String _katakanaToHiragana(String kata) 97 | { 98 | int code; 99 | String hira = ""; 100 | 101 | for (int _i = 0; _i < kata.length(); _i++) 102 | { 103 | char kataChar = kata.charAt(_i); 104 | 105 | if (_isCharKatakana(kataChar)) 106 | { 107 | code = (int) kataChar; 108 | code += HIRAGANA_START - KATAKANA_START; 109 | hira += String.valueOf(Character.toChars(code)); 110 | } 111 | else 112 | { 113 | hira += kataChar; 114 | } 115 | } 116 | 117 | return hira; 118 | } 119 | 120 | private String _hiraganaToKatakana(String hira) 121 | { 122 | int code; 123 | String kata = ""; 124 | 125 | for (int _i = 0; _i < hira.length(); _i++) 126 | { 127 | char hiraChar = hira.charAt(_i); 128 | 129 | if (_isCharHiragana(hiraChar)) 130 | { 131 | code = (int) hiraChar; 132 | code += KATAKANA_START - HIRAGANA_START; 133 | kata += String.valueOf(Character.toChars(code)); 134 | } 135 | else 136 | { 137 | kata += hiraChar; 138 | } 139 | } 140 | 141 | return kata; 142 | } 143 | 144 | public String _hiraganaToRomaji(String hira) 145 | { 146 | if(isRomaji(hira)) 147 | { 148 | return hira; 149 | } 150 | 151 | String chunk = ""; 152 | int chunkSize; 153 | int cursor = 0; 154 | int len = hira.length(); 155 | int maxChunk = 2; 156 | boolean nextCharIsDoubleConsonant = false; 157 | String roma = ""; 158 | String romaChar = null; 159 | 160 | while (cursor < len) 161 | { 162 | chunkSize = Math.min(maxChunk, len - cursor); 163 | while (chunkSize > 0) 164 | { 165 | chunk = hira.substring(cursor, (cursor+chunkSize)); 166 | 167 | if (isKatakana(chunk)) 168 | { 169 | chunk = _katakanaToHiragana(chunk); 170 | } 171 | 172 | if (String.valueOf(chunk.charAt(0)).equals("っ") && chunkSize == 1 && cursor < (len - 1)) 173 | { 174 | nextCharIsDoubleConsonant = true; 175 | romaChar = ""; 176 | break; 177 | } 178 | 179 | romaChar = mJtoR.get(chunk); 180 | 181 | if ((romaChar != null) && nextCharIsDoubleConsonant) 182 | { 183 | romaChar = romaChar.charAt(0) + romaChar; 184 | nextCharIsDoubleConsonant = false; 185 | } 186 | 187 | if (romaChar != null) 188 | { 189 | break; 190 | } 191 | 192 | chunkSize--; 193 | } 194 | if (romaChar == null) 195 | { 196 | romaChar = chunk; 197 | } 198 | 199 | roma += romaChar; 200 | cursor += chunkSize > 0 ? chunkSize : 1; 201 | } 202 | return roma; 203 | } 204 | 205 | private String _romajiToHiragana(String roma) 206 | { 207 | return _romajiToKana(roma, true); 208 | } 209 | 210 | private String _romajiToKana(String roma, Boolean ignoreCase) 211 | { 212 | String chunk = ""; 213 | String chunkLC = ""; 214 | int chunkSize; 215 | int position = 0; 216 | int len = roma.length(); 217 | int maxChunk = 3; 218 | String kana = ""; 219 | String kanaChar = ""; 220 | 221 | if (ignoreCase == null) 222 | { 223 | ignoreCase = false; 224 | } 225 | 226 | while (position < len) 227 | { 228 | chunkSize = Math.min(maxChunk, len - position); 229 | 230 | while (chunkSize > 0) 231 | { 232 | chunk = roma.substring(position, (position+chunkSize)); 233 | chunkLC = chunk.toLowerCase(); 234 | 235 | if ((chunkLC.equals("lts") || chunkLC.equals("xts")) && (len - position) >= 4) 236 | { 237 | chunkSize++; 238 | // The second parameter in substring() is an end point, not a length! 239 | chunk = roma.substring(position, (position+chunkSize)); 240 | chunkLC = chunk.toLowerCase(); 241 | } 242 | 243 | if (String.valueOf(chunkLC.charAt(0)).equals("n")) 244 | { 245 | // Convert n' to ん 246 | if(mOptions.get(OPTION_IME_MODE) && chunk.length() == 2 && String.valueOf(chunkLC.charAt(1)).equals("'")) 247 | { 248 | chunkSize = 2; 249 | chunk = "nn"; 250 | chunkLC = chunk.toLowerCase(); 251 | } 252 | // If the user types "nto", automatically convert "n" to "ん" first 253 | // "y" is excluded from the list of consonants so we can still get にゃ, にゅ, and にょ 254 | if(chunk.length() > 2 && _isCharConsonant(chunkLC.charAt(1), false) && _isCharVowel(chunkLC.charAt(2), true)) 255 | { 256 | chunkSize = 1; 257 | // I removed the "n"->"ん" mapping because the IME wouldn't let me type "na" for "な" without returning "んあ", 258 | // so the chunk needs to be manually set to a value that will map to "ん" 259 | chunk = "nn"; 260 | chunkLC = chunk.toLowerCase(); 261 | } 262 | } 263 | 264 | // Prepare to return a small-つ because we're looking at double-consonants. 265 | if (chunk.length() > 1 && !String.valueOf(chunkLC.charAt(0)).equals("n") && _isCharConsonant(chunkLC.charAt(0), true) && chunk.charAt(0) == chunk.charAt(1)) 266 | { 267 | chunkSize = 1; 268 | // Return a small katakana ツ when typing in uppercase 269 | if(_isCharInRange(chunk.charAt(0), UPPERCASE_START, UPPERCASE_END)) 270 | { 271 | chunkLC = chunk = "ッ"; 272 | } 273 | else 274 | { 275 | chunkLC = chunk = "っ"; 276 | } 277 | } 278 | 279 | kanaChar = mRtoJ.get(chunkLC); 280 | 281 | if (kanaChar != null) 282 | { 283 | break; 284 | } 285 | 286 | chunkSize--; 287 | } 288 | 289 | if (kanaChar == null) 290 | { 291 | chunk = _convertPunctuation(String.valueOf(chunk.charAt(0))); 292 | kanaChar = chunk; 293 | } 294 | 295 | if (mOptions.get(OPTION_USE_OBSOLETE_KANA)) 296 | { 297 | if (chunkLC.equals("wi")) 298 | { 299 | kanaChar = "ゐ"; 300 | } 301 | if (chunkLC.equals("we")) 302 | { 303 | kanaChar = "ゑ"; 304 | } 305 | } 306 | 307 | if (roma.length() > (position + 1) && mOptions.get(OPTION_IME_MODE) && String.valueOf(chunkLC.charAt(0)).equals("n")) 308 | { 309 | if ((String.valueOf(roma.charAt(position + 1)).toLowerCase().equals("y") && position == (len - 2)) || position == (len - 1)) 310 | { 311 | kanaChar = String.valueOf(chunk.charAt(0)); 312 | } 313 | } 314 | if (!ignoreCase) 315 | { 316 | if (_isCharInRange(chunk.charAt(0), UPPERCASE_START, UPPERCASE_END)) 317 | { 318 | kanaChar = _hiraganaToKatakana(kanaChar); 319 | } 320 | } 321 | 322 | kana += kanaChar; 323 | 324 | position += chunkSize > 0 ? chunkSize : 1; 325 | } 326 | 327 | return kana; 328 | } 329 | 330 | private String _convertPunctuation(String input) 331 | { 332 | if (input.equals(String.valueOf((' ')))) 333 | { 334 | return String.valueOf(' '); 335 | } 336 | 337 | if (input.equals(String.valueOf('-'))) 338 | { 339 | return String.valueOf('ー'); 340 | } 341 | 342 | return input; 343 | } 344 | 345 | /** 346 | * Returns true if input is entirely hiragana. 347 | */ 348 | 349 | public boolean isHiragana(String input) 350 | { 351 | return _allTrue(input, new Command() 352 | { 353 | @Override 354 | public boolean run(String str) 355 | { 356 | return _isCharHiragana(str.charAt(0)); 357 | } 358 | }); 359 | } 360 | 361 | public boolean isKatakana(String input) 362 | { 363 | return _allTrue(input, new Command() 364 | { 365 | @Override 366 | public boolean run(String str) 367 | { 368 | return _isCharKatakana(str.charAt(0)); 369 | } 370 | }); 371 | } 372 | 373 | public boolean isKana(String input) 374 | { 375 | return _allTrue(input, new Command() 376 | { 377 | @Override 378 | public boolean run(String str) 379 | { 380 | return (isHiragana(str)) || (isKatakana(str)); 381 | } 382 | }); 383 | } 384 | 385 | public boolean isRomaji(String input) 386 | { 387 | return _allTrue(input, new Command() 388 | { 389 | @Override 390 | public boolean run(String str) 391 | { 392 | return (!isHiragana(str)) && (!isKatakana(str)); 393 | } 394 | }); 395 | } 396 | 397 | public String toHiragana(String input) 398 | { 399 | if (isRomaji(input)) 400 | { 401 | return _romajiToHiragana(input); 402 | } 403 | 404 | if (isKatakana(input)) 405 | { 406 | return _katakanaToHiragana(input); 407 | } 408 | 409 | return input; 410 | } 411 | 412 | public String toKatakana(String input) 413 | { 414 | if (isHiragana(input)) 415 | { 416 | return _hiraganaToKatakana(input); 417 | } 418 | 419 | if (isRomaji(input)) 420 | { 421 | return _hiraganaToKatakana(_romajiToHiragana(input)); 422 | } 423 | 424 | return input; 425 | } 426 | 427 | public String toKana(String input) 428 | { 429 | return _romajiToKana(input, false); 430 | } 431 | 432 | public String toRomaji(String input) 433 | { 434 | return _hiraganaToRomaji(input); 435 | } 436 | 437 | private void prepareRtoJ() 438 | { 439 | mRtoJ.put("a", "あ"); 440 | mRtoJ.put("i", "い"); 441 | mRtoJ.put("u", "う"); 442 | mRtoJ.put("e", "え"); 443 | mRtoJ.put("o", "お"); 444 | mRtoJ.put("yi", "い"); 445 | mRtoJ.put("wu", "う"); 446 | mRtoJ.put("whu", "う"); 447 | mRtoJ.put("xa", "ぁ"); 448 | mRtoJ.put("xi", "ぃ"); 449 | mRtoJ.put("xu", "ぅ"); 450 | mRtoJ.put("xe", "ぇ"); 451 | mRtoJ.put("xo", "ぉ"); 452 | mRtoJ.put("xyi", "ぃ"); 453 | mRtoJ.put("xye", "ぇ"); 454 | mRtoJ.put("ye", "いぇ"); 455 | mRtoJ.put("wha", "うぁ"); 456 | mRtoJ.put("whi", "うぃ"); 457 | mRtoJ.put("whe", "うぇ"); 458 | mRtoJ.put("who", "うぉ"); 459 | mRtoJ.put("wi", "うぃ"); 460 | mRtoJ.put("we", "うぇ"); 461 | mRtoJ.put("va", "ゔぁ"); 462 | mRtoJ.put("vi", "ゔぃ"); 463 | mRtoJ.put("vu", "ゔ"); 464 | mRtoJ.put("ve", "ゔぇ"); 465 | mRtoJ.put("vo", "ゔぉ"); 466 | mRtoJ.put("vya", "ゔゃ"); 467 | mRtoJ.put("vyi", "ゔぃ"); 468 | mRtoJ.put("vyu", "ゔゅ"); 469 | mRtoJ.put("vye", "ゔぇ"); 470 | mRtoJ.put("vyo", "ゔょ"); 471 | mRtoJ.put("ka", "か"); 472 | mRtoJ.put("ki", "き"); 473 | mRtoJ.put("ku", "く"); 474 | mRtoJ.put("ke", "け"); 475 | mRtoJ.put("ko", "こ"); 476 | mRtoJ.put("lka", "ヵ"); 477 | mRtoJ.put("lke", "ヶ"); 478 | mRtoJ.put("xka", "ヵ"); 479 | mRtoJ.put("xke", "ヶ"); 480 | mRtoJ.put("kya", "きゃ"); 481 | mRtoJ.put("kyi", "きぃ"); 482 | mRtoJ.put("kyu", "きゅ"); 483 | mRtoJ.put("kye", "きぇ"); 484 | mRtoJ.put("kyo", "きょ"); 485 | mRtoJ.put("qya", "くゃ"); 486 | mRtoJ.put("qyu", "くゅ"); 487 | mRtoJ.put("qyo", "くょ"); 488 | mRtoJ.put("qwa", "くぁ"); 489 | mRtoJ.put("qwi", "くぃ"); 490 | mRtoJ.put("qwu", "くぅ"); 491 | mRtoJ.put("qwe", "くぇ"); 492 | mRtoJ.put("qwo", "くぉ"); 493 | mRtoJ.put("qa", "くぁ"); 494 | mRtoJ.put("qi", "くぃ"); 495 | mRtoJ.put("qe", "くぇ"); 496 | mRtoJ.put("qo", "くぉ"); 497 | mRtoJ.put("kwa", "くぁ"); 498 | mRtoJ.put("qyi", "くぃ"); 499 | mRtoJ.put("qye", "くぇ"); 500 | mRtoJ.put("ga", "が"); 501 | mRtoJ.put("gi", "ぎ"); 502 | mRtoJ.put("gu", "ぐ"); 503 | mRtoJ.put("ge", "げ"); 504 | mRtoJ.put("go", "ご"); 505 | mRtoJ.put("gya", "ぎゃ"); 506 | mRtoJ.put("gyi", "ぎぃ"); 507 | mRtoJ.put("gyu", "ぎゅ"); 508 | mRtoJ.put("gye", "ぎぇ"); 509 | mRtoJ.put("gyo", "ぎょ"); 510 | mRtoJ.put("gwa", "ぐぁ"); 511 | mRtoJ.put("gwi", "ぐぃ"); 512 | mRtoJ.put("gwu", "ぐぅ"); 513 | mRtoJ.put("gwe", "ぐぇ"); 514 | mRtoJ.put("gwo", "ぐぉ"); 515 | mRtoJ.put("sa", "さ"); 516 | mRtoJ.put("si", "し"); 517 | mRtoJ.put("shi", "し"); 518 | mRtoJ.put("su", "す"); 519 | mRtoJ.put("se", "せ"); 520 | mRtoJ.put("so", "そ"); 521 | mRtoJ.put("za", "ざ"); 522 | mRtoJ.put("zi", "じ"); 523 | mRtoJ.put("zu", "ず"); 524 | mRtoJ.put("ze", "ぜ"); 525 | mRtoJ.put("zo", "ぞ"); 526 | mRtoJ.put("ji", "じ"); 527 | mRtoJ.put("sya", "しゃ"); 528 | mRtoJ.put("syi", "しぃ"); 529 | mRtoJ.put("syu", "しゅ"); 530 | mRtoJ.put("sye", "しぇ"); 531 | mRtoJ.put("syo", "しょ"); 532 | mRtoJ.put("sha", "しゃ"); 533 | mRtoJ.put("shu", "しゅ"); 534 | mRtoJ.put("she", "しぇ"); 535 | mRtoJ.put("sho", "しょ"); 536 | mRtoJ.put("swa", "すぁ"); 537 | mRtoJ.put("swi", "すぃ"); 538 | mRtoJ.put("swu", "すぅ"); 539 | mRtoJ.put("swe", "すぇ"); 540 | mRtoJ.put("swo", "すぉ"); 541 | mRtoJ.put("zya", "じゃ"); 542 | mRtoJ.put("zyi", "じぃ"); 543 | mRtoJ.put("zyu", "じゅ"); 544 | mRtoJ.put("zye", "じぇ"); 545 | mRtoJ.put("zyo", "じょ"); 546 | mRtoJ.put("ja", "じゃ"); 547 | mRtoJ.put("ju", "じゅ"); 548 | mRtoJ.put("je", "じぇ"); 549 | mRtoJ.put("jo", "じょ"); 550 | mRtoJ.put("jya", "じゃ"); 551 | mRtoJ.put("jyi", "じぃ"); 552 | mRtoJ.put("jyu", "じゅ"); 553 | mRtoJ.put("jye", "じぇ"); 554 | mRtoJ.put("jyo", "じょ"); 555 | mRtoJ.put("ta", "た"); 556 | mRtoJ.put("ti", "ち"); 557 | mRtoJ.put("tu", "つ"); 558 | mRtoJ.put("te", "て"); 559 | mRtoJ.put("to", "と"); 560 | mRtoJ.put("chi", "ち"); 561 | mRtoJ.put("tsu", "つ"); 562 | mRtoJ.put("ltu", "っ"); 563 | mRtoJ.put("xtu", "っ"); 564 | mRtoJ.put("tya", "ちゃ"); 565 | mRtoJ.put("tyi", "ちぃ"); 566 | mRtoJ.put("tyu", "ちゅ"); 567 | mRtoJ.put("tye", "ちぇ"); 568 | mRtoJ.put("tyo", "ちょ"); 569 | mRtoJ.put("cha", "ちゃ"); 570 | mRtoJ.put("chu", "ちゅ"); 571 | mRtoJ.put("che", "ちぇ"); 572 | mRtoJ.put("cho", "ちょ"); 573 | mRtoJ.put("cya", "ちゃ"); 574 | mRtoJ.put("cyi", "ちぃ"); 575 | mRtoJ.put("cyu", "ちゅ"); 576 | mRtoJ.put("cye", "ちぇ"); 577 | mRtoJ.put("cyo", "ちょ"); 578 | mRtoJ.put("tsa", "つぁ"); 579 | mRtoJ.put("tsi", "つぃ"); 580 | mRtoJ.put("tse", "つぇ"); 581 | mRtoJ.put("tso", "つぉ"); 582 | mRtoJ.put("tha", "てゃ"); 583 | mRtoJ.put("thi", "てぃ"); 584 | mRtoJ.put("thu", "てゅ"); 585 | mRtoJ.put("the", "てぇ"); 586 | mRtoJ.put("tho", "てょ"); 587 | mRtoJ.put("twa", "とぁ"); 588 | mRtoJ.put("twi", "とぃ"); 589 | mRtoJ.put("twu", "とぅ"); 590 | mRtoJ.put("twe", "とぇ"); 591 | mRtoJ.put("two", "とぉ"); 592 | mRtoJ.put("da", "だ"); 593 | mRtoJ.put("di", "ぢ"); 594 | mRtoJ.put("du", "づ"); 595 | mRtoJ.put("de", "で"); 596 | mRtoJ.put("do", "ど"); 597 | mRtoJ.put("dya", "ぢゃ"); 598 | mRtoJ.put("dyi", "ぢぃ"); 599 | mRtoJ.put("dyu", "ぢゅ"); 600 | mRtoJ.put("dye", "ぢぇ"); 601 | mRtoJ.put("dyo", "ぢょ"); 602 | mRtoJ.put("dha", "でゃ"); 603 | mRtoJ.put("dhi", "でぃ"); 604 | mRtoJ.put("dhu", "でゅ"); 605 | mRtoJ.put("dhe", "でぇ"); 606 | mRtoJ.put("dho", "でょ"); 607 | mRtoJ.put("dwa", "どぁ"); 608 | mRtoJ.put("dwi", "どぃ"); 609 | mRtoJ.put("dwu", "どぅ"); 610 | mRtoJ.put("dwe", "どぇ"); 611 | mRtoJ.put("dwo", "どぉ"); 612 | mRtoJ.put("na", "な"); 613 | mRtoJ.put("ni", "に"); 614 | mRtoJ.put("nu", "ぬ"); 615 | mRtoJ.put("ne", "ね"); 616 | mRtoJ.put("no", "の"); 617 | mRtoJ.put("nya", "にゃ"); 618 | mRtoJ.put("nyi", "にぃ"); 619 | mRtoJ.put("nyu", "にゅ"); 620 | mRtoJ.put("nye", "にぇ"); 621 | mRtoJ.put("nyo", "にょ"); 622 | mRtoJ.put("ha", "は"); 623 | mRtoJ.put("hi", "ひ"); 624 | mRtoJ.put("hu", "ふ"); 625 | mRtoJ.put("he", "へ"); 626 | mRtoJ.put("ho", "ほ"); 627 | mRtoJ.put("fu", "ふ"); 628 | mRtoJ.put("hya", "ひゃ"); 629 | mRtoJ.put("hyi", "ひぃ"); 630 | mRtoJ.put("hyu", "ひゅ"); 631 | mRtoJ.put("hye", "ひぇ"); 632 | mRtoJ.put("hyo", "ひょ"); 633 | mRtoJ.put("fya", "ふゃ"); 634 | mRtoJ.put("fyu", "ふゅ"); 635 | mRtoJ.put("fyo", "ふょ"); 636 | mRtoJ.put("fwa", "ふぁ"); 637 | mRtoJ.put("fwi", "ふぃ"); 638 | mRtoJ.put("fwu", "ふぅ"); 639 | mRtoJ.put("fwe", "ふぇ"); 640 | mRtoJ.put("fwo", "ふぉ"); 641 | mRtoJ.put("fa", "ふぁ"); 642 | mRtoJ.put("fi", "ふぃ"); 643 | mRtoJ.put("fe", "ふぇ"); 644 | mRtoJ.put("fo", "ふぉ"); 645 | mRtoJ.put("fyi", "ふぃ"); 646 | mRtoJ.put("fye", "ふぇ"); 647 | mRtoJ.put("ba", "ば"); 648 | mRtoJ.put("bi", "び"); 649 | mRtoJ.put("bu", "ぶ"); 650 | mRtoJ.put("be", "べ"); 651 | mRtoJ.put("bo", "ぼ"); 652 | mRtoJ.put("bya", "びゃ"); 653 | mRtoJ.put("byi", "びぃ"); 654 | mRtoJ.put("byu", "びゅ"); 655 | mRtoJ.put("bye", "びぇ"); 656 | mRtoJ.put("byo", "びょ"); 657 | mRtoJ.put("pa", "ぱ"); 658 | mRtoJ.put("pi", "ぴ"); 659 | mRtoJ.put("pu", "ぷ"); 660 | mRtoJ.put("pe", "ぺ"); 661 | mRtoJ.put("po", "ぽ"); 662 | mRtoJ.put("pya", "ぴゃ"); 663 | mRtoJ.put("pyi", "ぴぃ"); 664 | mRtoJ.put("pyu", "ぴゅ"); 665 | mRtoJ.put("pye", "ぴぇ"); 666 | mRtoJ.put("pyo", "ぴょ"); 667 | mRtoJ.put("ma", "ま"); 668 | mRtoJ.put("mi", "み"); 669 | mRtoJ.put("mu", "む"); 670 | mRtoJ.put("me", "め"); 671 | mRtoJ.put("mo", "も"); 672 | mRtoJ.put("mya", "みゃ"); 673 | mRtoJ.put("myi", "みぃ"); 674 | mRtoJ.put("myu", "みゅ"); 675 | mRtoJ.put("mye", "みぇ"); 676 | mRtoJ.put("myo", "みょ"); 677 | mRtoJ.put("ya", "や"); 678 | mRtoJ.put("yu", "ゆ"); 679 | mRtoJ.put("yo", "よ"); 680 | mRtoJ.put("xya", "ゃ"); 681 | mRtoJ.put("xyu", "ゅ"); 682 | mRtoJ.put("xyo", "ょ"); 683 | mRtoJ.put("ra", "ら"); 684 | mRtoJ.put("ri", "り"); 685 | mRtoJ.put("ru", "る"); 686 | mRtoJ.put("re", "れ"); 687 | mRtoJ.put("ro", "ろ"); 688 | mRtoJ.put("rya", "りゃ"); 689 | mRtoJ.put("ryi", "りぃ"); 690 | mRtoJ.put("ryu", "りゅ"); 691 | mRtoJ.put("rye", "りぇ"); 692 | mRtoJ.put("ryo", "りょ"); 693 | mRtoJ.put("la", "ら"); 694 | mRtoJ.put("li", "り"); 695 | mRtoJ.put("lu", "る"); 696 | mRtoJ.put("le", "れ"); 697 | mRtoJ.put("lo", "ろ"); 698 | mRtoJ.put("lya", "りゃ"); 699 | mRtoJ.put("lyi", "りぃ"); 700 | mRtoJ.put("lyu", "りゅ"); 701 | mRtoJ.put("lye", "りぇ"); 702 | mRtoJ.put("lyo", "りょ"); 703 | mRtoJ.put("wa", "わ"); 704 | mRtoJ.put("wo", "を"); 705 | mRtoJ.put("lwe", "ゎ"); 706 | mRtoJ.put("xwa", "ゎ"); 707 | mRtoJ.put("nn", "ん"); 708 | mRtoJ.put("'n '", "ん"); 709 | mRtoJ.put("xn", "ん"); 710 | mRtoJ.put("ltsu", "っ"); 711 | mRtoJ.put("xtsu", "っ"); 712 | } 713 | 714 | private void prepareJtoR() 715 | { 716 | mJtoR.put("あ", "a"); 717 | mJtoR.put("い", "i"); 718 | mJtoR.put("う", "u"); 719 | mJtoR.put("え", "e"); 720 | mJtoR.put("お", "o"); 721 | mJtoR.put("ゔぁ", "va"); 722 | mJtoR.put("ゔぃ", "vi"); 723 | mJtoR.put("ゔ", "vu"); 724 | mJtoR.put("ゔぇ", "ve"); 725 | mJtoR.put("ゔぉ", "vo"); 726 | mJtoR.put("か", "ka"); 727 | mJtoR.put("き", "ki"); 728 | mJtoR.put("きゃ", "kya"); 729 | mJtoR.put("きぃ", "kyi"); 730 | mJtoR.put("きゅ", "kyu"); 731 | mJtoR.put("く", "ku"); 732 | mJtoR.put("け", "ke"); 733 | mJtoR.put("こ", "ko"); 734 | mJtoR.put("が", "ga"); 735 | mJtoR.put("ぎ", "gi"); 736 | mJtoR.put("ぐ", "gu"); 737 | mJtoR.put("げ", "ge"); 738 | mJtoR.put("ご", "go"); 739 | mJtoR.put("ぎゃ", "gya"); 740 | mJtoR.put("ぎぃ", "gyi"); 741 | mJtoR.put("ぎゅ", "gyu"); 742 | mJtoR.put("ぎぇ", "gye"); 743 | mJtoR.put("ぎょ", "gyo"); 744 | mJtoR.put("さ", "sa"); 745 | mJtoR.put("す", "su"); 746 | mJtoR.put("せ", "se"); 747 | mJtoR.put("そ", "so"); 748 | mJtoR.put("ざ", "za"); 749 | mJtoR.put("ず", "zu"); 750 | mJtoR.put("ぜ", "ze"); 751 | mJtoR.put("ぞ", "zo"); 752 | mJtoR.put("し", "shi"); 753 | mJtoR.put("しゃ", "sha"); 754 | mJtoR.put("しゅ", "shu"); 755 | mJtoR.put("しょ", "sho"); 756 | mJtoR.put("じ", "ji"); 757 | mJtoR.put("じゃ", "ja"); 758 | mJtoR.put("じゅ", "ju"); 759 | mJtoR.put("じょ", "jo"); 760 | mJtoR.put("た", "ta"); 761 | mJtoR.put("ち", "chi"); 762 | mJtoR.put("ちゃ", "cha"); 763 | mJtoR.put("ちゅ", "chu"); 764 | mJtoR.put("ちょ", "cho"); 765 | mJtoR.put("つ", "tsu"); 766 | mJtoR.put("て", "te"); 767 | mJtoR.put("と", "to"); 768 | mJtoR.put("だ", "da"); 769 | mJtoR.put("ぢ", "di"); 770 | mJtoR.put("づ", "du"); 771 | mJtoR.put("で", "de"); 772 | mJtoR.put("ど", "do"); 773 | mJtoR.put("な", "na"); 774 | mJtoR.put("に", "ni"); 775 | mJtoR.put("にゃ", "nya"); 776 | mJtoR.put("にゅ", "nyu"); 777 | mJtoR.put("にょ", "nyo"); 778 | mJtoR.put("ぬ", "nu"); 779 | mJtoR.put("ね", "ne"); 780 | mJtoR.put("の", "no"); 781 | mJtoR.put("は", "ha"); 782 | mJtoR.put("ひ", "hi"); 783 | mJtoR.put("ふ", "fu"); 784 | mJtoR.put("へ", "he"); 785 | mJtoR.put("ほ", "ho"); 786 | mJtoR.put("ひゃ", "hya"); 787 | mJtoR.put("ひゅ", "hyu"); 788 | mJtoR.put("ひょ", "hyo"); 789 | mJtoR.put("ふぁ", "fa"); 790 | mJtoR.put("ふぃ", "fi"); 791 | mJtoR.put("ふぇ", "fe"); 792 | mJtoR.put("ふぉ", "fo"); 793 | mJtoR.put("ば", "ba"); 794 | mJtoR.put("び", "bi"); 795 | mJtoR.put("ぶ", "bu"); 796 | mJtoR.put("べ", "be"); 797 | mJtoR.put("ぼ", "bo"); 798 | mJtoR.put("びゃ", "bya"); 799 | mJtoR.put("びゅ", "byu"); 800 | mJtoR.put("びょ", "byo"); 801 | mJtoR.put("ぱ", "pa"); 802 | mJtoR.put("ぴ", "pi"); 803 | mJtoR.put("ぷ", "pu"); 804 | mJtoR.put("ぺ", "pe"); 805 | mJtoR.put("ぽ", "po"); 806 | mJtoR.put("ぴゃ", "pya"); 807 | mJtoR.put("ぴゅ", "pyu"); 808 | mJtoR.put("ぴょ", "pyo"); 809 | mJtoR.put("ま", "ma"); 810 | mJtoR.put("み", "mi"); 811 | mJtoR.put("む", "mu"); 812 | mJtoR.put("め", "me"); 813 | mJtoR.put("も", "mo"); 814 | mJtoR.put("みゃ", "mya"); 815 | mJtoR.put("みゅ", "myu"); 816 | mJtoR.put("みょ", "myo"); 817 | mJtoR.put("や", "ya"); 818 | mJtoR.put("ゆ", "yu"); 819 | mJtoR.put("よ", "yo"); 820 | mJtoR.put("ら", "ra"); 821 | mJtoR.put("り", "ri"); 822 | mJtoR.put("る", "ru"); 823 | mJtoR.put("れ", "re"); 824 | mJtoR.put("ろ", "ro"); 825 | mJtoR.put("りゃ", "rya"); 826 | mJtoR.put("りゅ", "ryu"); 827 | mJtoR.put("りょ", "ryo"); 828 | mJtoR.put("わ", "wa"); 829 | mJtoR.put("を", "wo"); 830 | mJtoR.put("ん", "n"); 831 | mJtoR.put("ゐ", "wi"); 832 | mJtoR.put("ゑ", "we"); 833 | mJtoR.put("きぇ", "kye"); 834 | mJtoR.put("きょ", "kyo"); 835 | mJtoR.put("じぃ", "jyi"); 836 | mJtoR.put("じぇ", "jye"); 837 | mJtoR.put("ちぃ", "cyi"); 838 | mJtoR.put("ちぇ", "che"); 839 | mJtoR.put("ひぃ", "hyi"); 840 | mJtoR.put("ひぇ", "hye"); 841 | mJtoR.put("びぃ", "byi"); 842 | mJtoR.put("びぇ", "bye"); 843 | mJtoR.put("ぴぃ", "pyi"); 844 | mJtoR.put("ぴぇ", "pye"); 845 | mJtoR.put("みぇ", "mye"); 846 | mJtoR.put("みぃ", "myi"); 847 | mJtoR.put("りぃ", "ryi"); 848 | mJtoR.put("りぇ", "rye"); 849 | mJtoR.put("にぃ", "nyi"); 850 | mJtoR.put("にぇ", "nye"); 851 | mJtoR.put("しぃ", "syi"); 852 | mJtoR.put("しぇ", "she"); 853 | mJtoR.put("いぇ", "ye"); 854 | mJtoR.put("うぁ", "wha"); 855 | mJtoR.put("うぉ", "who"); 856 | mJtoR.put("うぃ", "wi"); 857 | mJtoR.put("うぇ", "we"); 858 | mJtoR.put("ゔゃ", "vya"); 859 | mJtoR.put("ゔゅ", "vyu"); 860 | mJtoR.put("ゔょ", "vyo"); 861 | mJtoR.put("すぁ", "swa"); 862 | mJtoR.put("すぃ", "swi"); 863 | mJtoR.put("すぅ", "swu"); 864 | mJtoR.put("すぇ", "swe"); 865 | mJtoR.put("すぉ", "swo"); 866 | mJtoR.put("くゃ", "qya"); 867 | mJtoR.put("くゅ", "qyu"); 868 | mJtoR.put("くょ", "qyo"); 869 | mJtoR.put("くぁ", "qwa"); 870 | mJtoR.put("くぃ", "qwi"); 871 | mJtoR.put("くぅ", "qwu"); 872 | mJtoR.put("くぇ", "qwe"); 873 | mJtoR.put("くぉ", "qwo"); 874 | mJtoR.put("ぐぁ", "gwa"); 875 | mJtoR.put("ぐぃ", "gwi"); 876 | mJtoR.put("ぐぅ", "gwu"); 877 | mJtoR.put("ぐぇ", "gwe"); 878 | mJtoR.put("ぐぉ", "gwo"); 879 | mJtoR.put("つぁ", "tsa"); 880 | mJtoR.put("つぃ", "tsi"); 881 | mJtoR.put("つぇ", "tse"); 882 | mJtoR.put("つぉ", "tso"); 883 | mJtoR.put("てゃ", "tha"); 884 | mJtoR.put("てぃ", "thi"); 885 | mJtoR.put("てゅ", "thu"); 886 | mJtoR.put("てぇ", "the"); 887 | mJtoR.put("てょ", "tho"); 888 | mJtoR.put("とぁ", "twa"); 889 | mJtoR.put("とぃ", "twi"); 890 | mJtoR.put("とぅ", "twu"); 891 | mJtoR.put("とぇ", "twe"); 892 | mJtoR.put("とぉ", "two"); 893 | mJtoR.put("ぢゃ", "dya"); 894 | mJtoR.put("ぢぃ", "dyi"); 895 | mJtoR.put("ぢゅ", "dyu"); 896 | mJtoR.put("ぢぇ", "dye"); 897 | mJtoR.put("ぢょ", "dyo"); 898 | mJtoR.put("でゃ", "dha"); 899 | mJtoR.put("でぃ", "dhi"); 900 | mJtoR.put("でゅ", "dhu"); 901 | mJtoR.put("でぇ", "dhe"); 902 | mJtoR.put("でょ", "dho"); 903 | mJtoR.put("どぁ", "dwa"); 904 | mJtoR.put("どぃ", "dwi"); 905 | mJtoR.put("どぅ", "dwu"); 906 | mJtoR.put("どぇ", "dwe"); 907 | mJtoR.put("どぉ", "dwo"); 908 | mJtoR.put("ふぅ", "fwu"); 909 | mJtoR.put("ふゃ", "fya"); 910 | mJtoR.put("ふゅ", "fyu"); 911 | mJtoR.put("ふょ", "fyo"); 912 | mJtoR.put("ぁ", "a"); 913 | mJtoR.put("ぃ", "i"); 914 | mJtoR.put("ぇ", "e"); 915 | mJtoR.put("ぅ", "u"); 916 | mJtoR.put("ぉ", "o"); 917 | mJtoR.put("ゃ", "ya"); 918 | mJtoR.put("ゅ", "yu"); 919 | mJtoR.put("ょ", "yo"); 920 | mJtoR.put("っ", ""); 921 | mJtoR.put("ゕ", "ka"); 922 | mJtoR.put("ゖ", "ka"); 923 | mJtoR.put("ゎ", "wa"); 924 | mJtoR.put("' '", " "); 925 | mJtoR.put("んあ", "n'a"); 926 | mJtoR.put("んい", "n'i"); 927 | mJtoR.put("んう", "n'u"); 928 | mJtoR.put("んえ", "n'e"); 929 | mJtoR.put("んお", "n'o"); 930 | mJtoR.put("んや", "n'ya"); 931 | mJtoR.put("んゆ", "n'yu"); 932 | mJtoR.put("んよ", "n'yo"); 933 | } 934 | } 935 | --------------------------------------------------------------------------------