1 | /*
|
---|
2 | Adobe Systems Incorporated(r) Source Code License Agreement
|
---|
3 | Copyright(c) 2005 Adobe Systems Incorporated. All rights reserved.
|
---|
4 |
|
---|
5 | Please read this Source Code License Agreement carefully before using
|
---|
6 | the source code.
|
---|
7 |
|
---|
8 | Adobe Systems Incorporated grants to you a perpetual, worldwide, non-exclusive,
|
---|
9 | no-charge, royalty-free, irrevocable copyright license, to reproduce,
|
---|
10 | prepare derivative works of, publicly display, publicly perform, and
|
---|
11 | distribute this source code and such derivative works in source or
|
---|
12 | object code form without any attribution requirements.
|
---|
13 |
|
---|
14 | The name "Adobe Systems Incorporated" must not be used to endorse or promote products
|
---|
15 | derived from the source code without prior written permission.
|
---|
16 |
|
---|
17 | You agree to indemnify, hold harmless and defend Adobe Systems Incorporated from and
|
---|
18 | against any loss, damage, claims or lawsuits, including attorney's
|
---|
19 | fees that arise or result from your use or distribution of the source
|
---|
20 | code.
|
---|
21 |
|
---|
22 | THIS SOURCE CODE IS PROVIDED "AS IS" AND "WITH ALL FAULTS", WITHOUT
|
---|
23 | ANY TECHNICAL SUPPORT OR ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
|
---|
24 | BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
---|
25 | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ALSO, THERE IS NO WARRANTY OF
|
---|
26 | NON-INFRINGEMENT, TITLE OR QUIET ENJOYMENT. IN NO EVENT SHALL MACROMEDIA
|
---|
27 | OR ITS SUPPLIERS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
---|
28 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
---|
29 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
---|
30 | OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
---|
31 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
---|
32 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOURCE CODE, EVEN IF
|
---|
33 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
34 | */
|
---|
35 |
|
---|
36 | package com.adobe.net
|
---|
37 | {
|
---|
38 | import flash.utils.ByteArray;
|
---|
39 |
|
---|
40 | /**
|
---|
41 | * This class implements an efficient lookup table for URI
|
---|
42 | * character escaping. This class is only needed if you
|
---|
43 | * create a derived class of URI to handle custom URI
|
---|
44 | * syntax. This class is used internally by URI.
|
---|
45 | *
|
---|
46 | * @langversion ActionScript 3.0
|
---|
47 | * @playerversion Flash 9.0*
|
---|
48 | */
|
---|
49 | public class URIEncodingBitmap extends ByteArray
|
---|
50 | {
|
---|
51 | /**
|
---|
52 | * Constructor. Creates an encoding bitmap using the given
|
---|
53 | * string of characters as the set of characters that need
|
---|
54 | * to be URI escaped.
|
---|
55 | *
|
---|
56 | * @langversion ActionScript 3.0
|
---|
57 | * @playerversion Flash 9.0
|
---|
58 | */
|
---|
59 | public function URIEncodingBitmap(charsToEscape:String) : void
|
---|
60 | {
|
---|
61 | var i:int;
|
---|
62 | var data:ByteArray = new ByteArray();
|
---|
63 |
|
---|
64 | // Initialize our 128 bits (16 bytes) to zero
|
---|
65 | for (i = 0; i < 16; i++)
|
---|
66 | this.writeByte(0);
|
---|
67 |
|
---|
68 | data.writeUTFBytes(charsToEscape);
|
---|
69 | data.position = 0;
|
---|
70 |
|
---|
71 | while (data.bytesAvailable)
|
---|
72 | {
|
---|
73 | var c:int = data.readByte();
|
---|
74 |
|
---|
75 | if (c > 0x7f)
|
---|
76 | continue; // only escape low bytes
|
---|
77 |
|
---|
78 | var enc:int;
|
---|
79 | this.position = (c >> 3);
|
---|
80 | enc = this.readByte();
|
---|
81 | enc |= 1 << (c & 0x7);
|
---|
82 | this.position = (c >> 3);
|
---|
83 | this.writeByte(enc);
|
---|
84 | }
|
---|
85 | }
|
---|
86 |
|
---|
87 | /**
|
---|
88 | * Based on the data table contained in this object, check
|
---|
89 | * if the given character should be escaped.
|
---|
90 | *
|
---|
91 | * @param char the character to be escaped. Only the first
|
---|
92 | * character in the string is used. Any other characters
|
---|
93 | * are ignored.
|
---|
94 | *
|
---|
95 | * @return the integer value of the raw UTF8 character. For
|
---|
96 | * example, if '%' is given, the return value is 37 (0x25).
|
---|
97 | * If the character given does not need to be escaped, the
|
---|
98 | * return value is zero.
|
---|
99 | *
|
---|
100 | * @langversion ActionScript 3.0
|
---|
101 | * @playerversion Flash 9.0
|
---|
102 | */
|
---|
103 | public function ShouldEscape(char:String) : int
|
---|
104 | {
|
---|
105 | var data:ByteArray = new ByteArray();
|
---|
106 | var c:int, mask:int;
|
---|
107 |
|
---|
108 | // write the character into a ByteArray so
|
---|
109 | // we can pull it out as a raw byte value.
|
---|
110 | data.writeUTFBytes(char);
|
---|
111 | data.position = 0;
|
---|
112 | c = data.readByte();
|
---|
113 |
|
---|
114 | if (c & 0x80)
|
---|
115 | {
|
---|
116 | // don't escape high byte characters. It can make international
|
---|
117 | // URI's unreadable. We just want to escape characters that would
|
---|
118 | // make URI syntax ambiguous.
|
---|
119 | return 0;
|
---|
120 | }
|
---|
121 | else if ((c < 0x1f) || (c == 0x7f))
|
---|
122 | {
|
---|
123 | // control characters must be escaped.
|
---|
124 | return c;
|
---|
125 | }
|
---|
126 |
|
---|
127 | this.position = (c >> 3);
|
---|
128 | mask = this.readByte();
|
---|
129 |
|
---|
130 | if (mask & (1 << (c & 0x7)))
|
---|
131 | {
|
---|
132 | // we need to escape this, return the numeric value
|
---|
133 | // of the character
|
---|
134 | return c;
|
---|
135 | }
|
---|
136 | else
|
---|
137 | {
|
---|
138 | return 0;
|
---|
139 | }
|
---|
140 | }
|
---|
141 | }
|
---|
142 | }
|
---|