-/*\r
- Copyright (c) 2008, Adobe Systems Incorporated\r
- All rights reserved.\r
-\r
- Redistribution and use in source and binary forms, with or without \r
- modification, are permitted provided that the following conditions are\r
- met:\r
-\r
- * Redistributions of source code must retain the above copyright notice, \r
- this list of conditions and the following disclaimer.\r
- \r
- * Redistributions in binary form must reproduce the above copyright\r
- notice, this list of conditions and the following disclaimer in the \r
- documentation and/or other materials provided with the distribution.\r
- \r
- * Neither the name of Adobe Systems Incorporated nor the names of its \r
- contributors may be used to endorse or promote products derived from \r
- this software without specific prior written permission.\r
-\r
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS\r
- IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,\r
- THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
- PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR \r
- CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,\r
- EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,\r
- PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\r
- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF\r
- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING\r
- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\r
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
-*/\r
-\r
-package com.adobe.net\r
-{\r
- import flash.utils.ByteArray;\r
- \r
- /**\r
- * This class implements an efficient lookup table for URI\r
- * character escaping. This class is only needed if you\r
- * create a derived class of URI to handle custom URI\r
- * syntax. This class is used internally by URI.\r
- * \r
- * @langversion ActionScript 3.0\r
- * @playerversion Flash 9.0* \r
- */\r
- public class URIEncodingBitmap extends ByteArray\r
- {\r
- /**\r
- * Constructor. Creates an encoding bitmap using the given\r
- * string of characters as the set of characters that need\r
- * to be URI escaped.\r
- * \r
- * @langversion ActionScript 3.0\r
- * @playerversion Flash 9.0\r
- */\r
- public function URIEncodingBitmap(charsToEscape:String) : void\r
- {\r
- var i:int;\r
- var data:ByteArray = new ByteArray();\r
- \r
- // Initialize our 128 bits (16 bytes) to zero\r
- for (i = 0; i < 16; i++)\r
- this.writeByte(0);\r
- \r
- data.writeUTFBytes(charsToEscape);\r
- data.position = 0;\r
- \r
- while (data.bytesAvailable)\r
- {\r
- var c:int = data.readByte();\r
- \r
- if (c > 0x7f)\r
- continue; // only escape low bytes\r
- \r
- var enc:int;\r
- this.position = (c >> 3);\r
- enc = this.readByte();\r
- enc |= 1 << (c & 0x7);\r
- this.position = (c >> 3);\r
- this.writeByte(enc);\r
- }\r
- }\r
- \r
- /**\r
- * Based on the data table contained in this object, check\r
- * if the given character should be escaped.\r
- * \r
- * @param char the character to be escaped. Only the first\r
- * character in the string is used. Any other characters\r
- * are ignored.\r
- * \r
- * @return the integer value of the raw UTF8 character. For\r
- * example, if '%' is given, the return value is 37 (0x25).\r
- * If the character given does not need to be escaped, the\r
- * return value is zero.\r
- * \r
- * @langversion ActionScript 3.0\r
- * @playerversion Flash 9.0 \r
- */\r
- public function ShouldEscape(char:String) : int\r
- {\r
- var data:ByteArray = new ByteArray();\r
- var c:int, mask:int;\r
- \r
- // write the character into a ByteArray so\r
- // we can pull it out as a raw byte value.\r
- data.writeUTFBytes(char);\r
- data.position = 0;\r
- c = data.readByte();\r
- \r
- if (c & 0x80)\r
- {\r
- // don't escape high byte characters. It can make international\r
- // URI's unreadable. We just want to escape characters that would\r
- // make URI syntax ambiguous.\r
- return 0;\r
- }\r
- else if ((c < 0x1f) || (c == 0x7f))\r
- {\r
- // control characters must be escaped.\r
- return c;\r
- }\r
- \r
- this.position = (c >> 3);\r
- mask = this.readByte();\r
- \r
- if (mask & (1 << (c & 0x7)))\r
- {\r
- // we need to escape this, return the numeric value\r
- // of the character\r
- return c;\r
- }\r
- else\r
- {\r
- return 0;\r
- }\r
- }\r
- }\r
-}
\ No newline at end of file