ちょっと
置き場所がなくてとりあえずここに。
了解をえてないんだよね〜
DMonkey用です
追記、本日了解を頂きました。
というかさぁ〜優れている人は、親切なものだとつくづく思う。
天気屋だからね〜俺って。もうちょっとOKWaveのJavascriptの住人でいようと
思うけど、今日は不親切だった。 ちと反省。
class kanaToRoman { chop = false; //ローマ字文字列をアルファベット1文字ごとに分解するかどうか vowel = ['a','i','u','e','o']; child = ['a','k','s','t','n','h','m','y','r','w','g','z','d','b','p','x','y','t']; symbol = "!?-',"; number = '0123456789'; znumber = '0123456789'; cols_H = { 'A': 'あかさたなはまやらわがざだばぱぁゃ', 'I': 'いきしちにひみ@り@ぎじぢびぴぃ', 'U': 'うくすつぬふむゆるんぐずづぶぷぅゅっ', 'E': 'えけせてねへめ@れ@げぜでべぺぇ', 'O': 'おこそとのほもよろをごぞどぼぽぉょ' }; mode_Krows = "k"; //か・く・こ mode_XArows = "x"; //小文字ぁ行と「っ」 mode_TYrows = "ty"; //ち行+小文字や行 mode_SYrows = "sh"; //し行+小文字や行 mode_JYrows = "zy"; //じ行+小文字や行 mode_Sstr = "s"; //し mode_Jstr = "j"; //じ mode_TUstr = "t"; //つ mode_FUstr = "h"; //ふ mode_TIstr = "t"; //ち mode_Nstr = "n"; //ん function convert ( txt ) { var stack = this._TextSlice( txt + '' ), out = [ ]; for( var i = 0; i < stack.length; i++ ) out.push( stack[i].length == 1 ? this._baseOne( stack[i] ): this._baseTwo( stack[i] ) ); return out.join(''); } function _TextSlice ( txt ) { var max = txt.length; var array = [ ]; for( i = 0; i < max; i++ ) { var str = txt.charAt(i);//今の文字 var nxt = txt.charAt( i + 1);//次の文字 //隣接する1文字目が小文字や行なら if( nxt == 'ゃ' || nxt == 'ゅ' || nxt == 'ょ' ) { array.push( str + nxt ); i++; } else if( str == 'っ' && this.symbol.indexOf( nxt ) == -1 ) { if( this.number.indexOf( nxt ) == -1 ) { array.push( str + nxt ); i++; } else { array.push( str ); } } else { array.push( str ); } } return array; } function _baseTwo ( str ) { if( str.indexOf( 'っ' ) != -1 ) { if( str.length == 2 ) { var txt = this._baseOne( str.charAt(1) ); return txt.charAt(0) + txt; } else { return this._baseOne( str ); } } else { switch( str ) { case 'ちゃ': return this.mode_TYrows + this.vowel[0]; case 'ちゅ': return this.mode_TYrows + this.vowel[2]; case 'ちょ': return this.mode_TYrows + this.vowel[4]; case 'しゃ': return this.mode_SYrows + this.vowel[0]; case 'しゅ': return this.mode_SYrows + this.vowel[2]; case 'しょ': return this.mode_SYrows + this.vowel[4]; case 'じゃ': return this.mode_JYrows + this.vowel[0]; case 'じゅ': return this.mode_JYrows + this.vowel[2]; case 'じょ': return this.mode_JYrows + this.vowel[4]; default: var first = this._baseOne( str.charAt(0) ); var second = this._baseOne( str.charAt(1) ); return first.charAt(0) + second; } } } function _baseOne ( str ){ var tmp; if( (tmp = this.cols_H.A.indexOf(str)) != -1 ) return this._Change_A_Rows( tmp ); if( (tmp = this.cols_H.I.indexOf(str)) != -1 ) return this._Change_I_Rows( tmp ); if( (tmp = this.cols_H.U.indexOf(str)) != -1 ) return this._Change_U_Rows( tmp ); if( (tmp = this.cols_H.E.indexOf(str)) != -1 ) return this._Change_E_Rows( tmp ); if( (tmp = this.cols_H.O.indexOf(str)) != -1 ) return this._Change_O_Rows( tmp ); if( (tmp = this.znumber.indexOf(str)) != -1 ) return this.number.substring( tmp, tmp + 1 ); if( (tmp = this.symbol.indexOf(str)) != -1 ) return this.symbol.substring( tmp, 1 ); if( (tmp = this.number.indexOf(str)) != -1 ) return str; return null; } function _Change_A_Rows ( key ) { switch( key ) { case 1: return this.mode_Krows + this.vowel[0]; case 15: return this.mode_XArows + this.vowel[0]; case 0: return this.vowel[0]; default: return this.child[ key ] + this.vowel[0]; } } function _Change_I_Rows ( key ) { switch( key ) { case 0: return this.vowel[1]; case 15: return this.mode_XArows + this.vowel[1]; case 2: return this.mode_Sstr + this.vowel[1]; case 11: return this.mode_Jstr + this.vowel[1]; case 3: return this.mode_TIstr + this.vowel[1]; default: return this.child[ key ] + this.vowel[1]; } } function _Change_U_Rows ( key ) { switch( key ) { case 0: return this.vowel[2]; case 1: return this.mode_Krows + this.vowel[2]; case 15: return this.mode_XArows + this.vowel[2]; case 3: return this.mode_TUstr + this.vowel[2]; case 5: return this.mode_FUstr + this.vowel[2]; case 9: return this.mode_Nstr; case 17: return this.mode_XArows + this.mode_TUstr + this.vowel[2]; default: return this.child[ key ] + this.vowel[2]; } } function _Change_E_Rows ( key ) { switch( key ) { case 0: return this.vowel[3]; case 15: return this.mode_XArows + this.vowel[3]; default: return this.child[ key ] + this.vowel[3]; } } function _Change_O_Rows ( key ) { switch( key ) { case 0: return this.vowel[4]; case 1: return this.mode_Krows + this.vowel[4]; case 15: return this.mode_XArows + this.vowel[4]; default: return this.child[ key ] + this.vowel[4]; } } } Strings.prototype.toRoman = (function () { var toRoman = new kanaToRoman(); return function() { return toRoman.convert( this ); }; })(); alert((new Strings('あいう123だっちゃ')).toRoman());