/
CharCodeUtil.as
77 lines (70 loc) · 2.15 KB
/
CharCodeUtil.as
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package harayoki.util {
public class CharCodeUtil {
public static const CODE_TAB:int = 9;
public static const CODE_SPACE:int = 32;
public static const CODE_ZENKAKU_SPACE:int = 12288;
private static var _workVector:Vector.<int> = new <int>[];
private static var _ASCII_RANGE:Vector.<int>;
/**
* 文字コード一覧を文字指定範囲から返す
* @param charFrom 最初の文字列
* @param charTo 最後の文字列
* @param out 結果を(追加で)格納するVector
*/
public static function getIdListByCharRange(charFrom:String, charTo:String = null, out:Vector.<int> = null):Vector.<int> {
if (charFrom == null || charFrom.length == 0) {
return out;
}
if (charTo == null || charTo.length == 0) {
charTo = charFrom;
}
return getIdListByCodeRange(charFrom.charCodeAt(0), charTo.charCodeAt(0));
}
/**
* 文字コード一覧を文字一覧から返す
* @param letters 文字列
* @param out 結果を(追加で)格納するVector
*/
public static function getIdListByLetters(letters:String, out:Vector.<int> = null):Vector.<int> {
if (!out) {
out = new <int>[];
}
_workVector.length = 0;
var i:int = letters.length;
while(i--) {
var code:int = letters.charCodeAt(i);
// 重複をはぶいて一覧に追加
if(_workVector.indexOf(code) == -1) {
out.push(code);
}
_workVector.push(code)
}
return out;
}
/**
* 文字コード一覧を文字コード指定範囲から返す
* @param idFrom 最初の文字コード
* @param idTo 最後の文字コード
* @param out 結果を(追加で)格納するVector
*/
public static function getIdListByCodeRange(idFrom:int, idTo:int = -1, out:Vector.<int> = null):Vector.<int> {
if (!out) {
out = new <int>[];
}
for (var i:int = idFrom; i <= idTo; i++) {
out.push(i);
}
return out;
}
/**
* ASCII範囲の文字コード一覧を返す
*/
public static function getIdListForAscii():Vector.<int> {
if(!_ASCII_RANGE) {
_ASCII_RANGE = getIdListByCodeRange(32, 126); // ' ' から '~'
_ASCII_RANGE.fixed = true;
}
return _ASCII_RANGE;
}
}
}