2
* This file is part of the dis-Emi-A HaXe Library. Copyright © edA-qa mort-ora-y
3
* For full copyright and license information please refer to doc/license.txt.
9
* An English locale encoder
11
class Encoder_EN implements Encoder
13
inline static var SKIPCHAR : Int = -1;
14
inline static var BADCHAR : Int = -1;
16
inline static var charsetSize : Int = 27;
22
inline function encodeChar( char : String ) : Int
24
var ret; //do this way to allow inlining
26
var raw = char.toLowerCase().charCodeAt( 0 );
27
raw -= 'a'.charCodeAt( 0 );
33
if( raw >= charsetSize )
42
public function encode( str : String ) : Array<Int>
44
var word = new Array<Int>();
46
for( i in 0...str.length )
48
var c = encodeChar( str.charAt( i ) );
52
throw new EncoderException( "Cannot encode character: " + str.charAt(i) );
57
if( word.length == 0 )
58
throw new EncoderException( "Resulting word is 0 length: " + str );
63
inline function decodeChar( val : Int ) : String
65
return String.fromCharCode( val + 'a'.charCodeAt(0) - 1 );
68
public function decode( str : Array<Int> ) : String
72
ret += decodeChar( q );
77
public function getSeqDistrib() : Array<Array<Dynamic>>