Actionscript 3 试图了解com.adobe.net.URIEncodingBitmap的工作原理
我正在检查Actionscript 3 试图了解com.adobe.net.URIEncodingBitmap的工作原理,actionscript-3,bit-manipulation,urlencode,bit-shift,bitmask,Actionscript 3,Bit Manipulation,Urlencode,Bit Shift,Bitmask,我正在检查com.adobe.net包的URIEncodingBitmap类,我很难准确地理解内部工作原理。代码如下: package com.adobe.net { import flash.utils.ByteArray; /** * This class implements an efficient lookup table for URI * character escaping. This class is only needed if you
com.adobe.net
包的URIEncodingBitmap
类,我很难准确地理解内部工作原理。代码如下:
package com.adobe.net
{
import flash.utils.ByteArray;
/**
* This class implements an efficient lookup table for URI
* character escaping. This class is only needed if you
* create a derived class of URI to handle custom URI
* syntax. This class is used internally by URI.
*
* @langversion ActionScript 3.0
* @playerversion Flash 9.0*
*/
public class URIEncodingBitmap extends ByteArray
{
/**
* Constructor. Creates an encoding bitmap using the given
* string of characters as the set of characters that need
* to be URI escaped.
*
* @langversion ActionScript 3.0
* @playerversion Flash 9.0
*/
public function URIEncodingBitmap(charsToEscape:String) : void
{
var i:int;
var data:ByteArray = new ByteArray();
// Initialize our 128 bits (16 bytes) to zero
for (i = 0; i < 16; i++)
this.writeByte(0);
data.writeUTFBytes(charsToEscape);
data.position = 0;
while (data.bytesAvailable)
{
var c:int = data.readByte();
if (c > 0x7f)
continue; // only escape low bytes
var enc:int;
this.position = (c >> 3);
enc = this.readByte();
enc |= 1 << (c & 0x7);
this.position = (c >> 3);
this.writeByte(enc);
}
}
/**
* Based on the data table contained in this object, check
* if the given character should be escaped.
*
* @param char the character to be escaped. Only the first
* character in the string is used. Any other characters
* are ignored.
*
* @return the integer value of the raw UTF8 character. For
* example, if '%' is given, the return value is 37 (0x25).
* If the character given does not need to be escaped, the
* return value is zero.
*
* @langversion ActionScript 3.0
* @playerversion Flash 9.0
*/
public function ShouldEscape(char:String) : int
{
var data:ByteArray = new ByteArray();
var c:int, mask:int;
// write the character into a ByteArray so
// we can pull it out as a raw byte value.
data.writeUTFBytes(char);
data.position = 0;
c = data.readByte();
if (c & 0x80)
{
// don't escape high byte characters. It can make international
// URI's unreadable. We just want to escape characters that would
// make URI syntax ambiguous.
return 0;
}
else if ((c < 0x1f) || (c == 0x7f))
{
// control characters must be escaped.
return c;
}
this.position = (c >> 3);
mask = this.readByte();
if (mask & (1 << (c & 0x7)))
{
// we need to escape this, return the numeric value
// of the character
return c;
}
else
{
return 0;
}
}
}
}
package com.adobe.net
{
导入flash.utils.ByteArray;
/**
*此类实现了一个有效的URI查找表
*字符转义。仅当您
*创建URI的派生类以处理自定义URI
*这个类由URI在内部使用。
*
*@langversion ActionScript 3.0
*@playervision Flash 9.0*
*/
公共类URIEncodingBitmap扩展ByteArray
{
/**
*构造函数。使用给定的
*字符串作为需要的字符集
*要转义。
*
*@langversion ActionScript 3.0
*@playervision Flash 9.0
*/
公用函数URIEncodingBitmap(charsToEscape:String):void
{
变量i:int;
var数据:ByteArray=新的ByteArray();
//将128位(16字节)初始化为零
对于(i=0;i<16;i++)
这个.writeByte(0);
数据写入字节(charsToEscape);
data.position=0;
while(数据字节可用)
{
var c:int=data.readByte();
如果(c>0x7f)
continue;//仅转义低字节
var-enc:int;
这个位置=(c>>3);
enc=this.readByte();
enc |=1>3);
这个.writeByte(enc);
}
}
/**
*根据此对象中包含的数据表,选中
*如果给定的字符应该转义。
*
*@param char要转义的字符。仅第一个字符
*使用字符串中的字符。是否使用其他字符
*都被忽略了。
*
*@返回原始UTF8字符的整数值。对于
*例如,如果给定“%”,则返回值为37(0x25)。
*如果给定的字符不需要转义,则
*返回值为零。
*
*@langversion ActionScript 3.0
*@playervision Flash 9.0
*/
公共函数ShouldEscape(char:String):int
{
var数据:ByteArray=新的ByteArray();
变量c:int,掩码:int;
//将字符写入ByteArray以便
//我们可以把它作为原始字节值提取出来。
数据写入字节(字符);
data.position=0;
c=data.readByte();
if(c&0x80)
{
//不要转义高字节字符。它可以使
//URI不可读。我们只想转义
//使URI语法不明确。
返回0;
}
else如果((c<0x1f)| |(c==0x7f))
{
//必须转义控件字符。
返回c;
}
这个位置=(c>>3);
mask=this.readByte();
if(mask&(1>
,ad 1.构造函数创建转义定义数组(长度16字节=128位)。每个字符一位。位的位置对应于字符的序号值,其值表示是否应转义字符
ad a。此行计算给定字符转义定义数组中的适当字节
ad b.设置与字节内字符对应的位
掩码包含给定字符的适当字节,用于检查是否设置了相应的位