日本語sort test
読みとkeyを追加して
keyでsort
もっといいやり方があるんでしょうね...
/**
* Copyright meemeer ( http://wonderfl.net/user/meemeer )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/eeal
*/
package {
/**
* ...
* @author meemeer
* @author http://meemeer.sitemix.jp/blog/
*/
import flash.display.Sprite;
import flash.text.TextField;
public class FlashTest extends Sprite {
public function FlashTest() {
// write as3 code here..
var list:Array = [
{ 'name':'荒木飛呂彦', 'yomi':'arakihirohiko' },
{ 'name':'小畑健', 'yomi':'obataken' },
{ 'name':'豪血寺一族', 'yomi':'gouketuziitizoku' },
{ 'name':'魔夜峰雄', 'yomi':'mayamineo' },
{ 'name':'篠原千絵', 'yomi':'sinoharatie' },
{ 'name':'天野月子', 'yomi':'amanotsukiko' }
];
var tfy:int = 0;
for each (var a:Object in new Jasort_test().jasort(list)) {
trace(a.name, a.yomi, a.key);
var tf:TextField = new TextField();
tf.text = a.name;
tf.y = tfy;
addChild(tf);
tfy += 14;
}
}
}
}
/**
* ...
* @author meemeer
* @author http://meemeer.sitemix.jp/blog/
*/
class Jasort_test
{
public const romaji:Object = {
'a' :'01', 'i' :'02', 'u' :'03', 'e' :'04', 'o' :'05',
'ka' :'06', 'ki' :'07', 'ku' :'08', 'ke' :'09', 'ko' :'10',
'ga' :'11', 'gi' :'12', 'gu' :'13', 'ge' :'14', 'go' :'15',
'sa' :'16', 'si' :'17', 'su' :'18', 'se' :'19', 'so' :'20',
'za' :'21', 'zi' :'22', 'zu' :'23', 'ze' :'24', 'zo' :'25',
'ta' :'26', 'ti' :'27', 'tu' :'28', 'te' :'29', 'to' :'30',
'da' :'31', 'di' :'32', 'du' :'33', 'de' :'34', 'do' :'35',
'na' :'36', 'ni' :'37', 'nu' :'38', 'ne' :'39', 'no' :'40',
'ha' :'41', 'hi' :'42', 'hu' :'43', 'he' :'44', 'ho' :'45',
'ba' :'46', 'bi' :'47', 'bu' :'48', 'be' :'49', 'bo' :'50',
'pa' :'51', 'pi' :'52', 'pu' :'53', 'pe' :'54', 'po' :'55',
'ma' :'56', 'mi' :'57', 'mu' :'58', 'me' :'59', 'mo' :'60',
'ya' :'61', 'yu' :'62', 'yo' :'63',
'ra' :'66', 'ri' :'67', 'ru' :'68', 're' :'69', 'ro' :'70',
'wa' :'71', 'wo' :'72', 'n' :'73',
'vu' :'03',
'shi' :'17',
'chi' :'27',
'tsu':'28',
'fu' :'43',
'ji' :'22',
'sya':'1761', 'syu':'1762', 'syo':'1763',
'sha':'1761', 'shu':'1762', 'sho':'1763',
'tya':'2761', 'tyu':'2762', 'tyo':'2763',
'cya':'2761', 'cyu':'2762', 'cyo':'2763',
'cha':'2761', 'chu':'2762', 'cho':'2763',
'jya':'2261', 'jyu':'2262', 'jyo':'2263',
'mya':'5761', 'myu':'5762', 'myo':'5763',
'pha':'4301'
}
public function Jasort_test()
{
}
public function jasort(list:Array):Array
{
var romaji_array:Array = [];
for (var x:String in romaji) {
romaji_array.push( {'len':x.length, 'val':x } );
}
var romaji_array2:Array = [];
for each (var xx:* in romaji_array.sortOn('len', Array.DESCENDING)) {
romaji_array2.push(xx.val);
}
var re_romaji:RegExp = new RegExp(romaji_array2.join('|'));
for each (var r:Object in list) {
var match:String = '';
r.key = r.yomi;
while ((match = r.key.match(re_romaji)) != null) {
r.key = r.key.replace(re_romaji, romaji[match]);
}
}
return list.sortOn('key');
}
}