Method: URI.Encode
- Defined in:
- lib/gollum/frontend/uri_encode_component.rb
.Encode(uri, unescape) ⇒ Object
ECMA-262, section 15.1.3
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/gollum/frontend/uri_encode_component.rb', line 140 def Encode(uri, unescape) uriLength = uri.length; # We are going to pass result to %StringFromCharCodeArray # which does not expect any getters/setters installed # on the incoming array. result = Array.new(uriLength); index = 0; k = -1; while ((k+=1) < uriLength) do cc1 = uri.charCodeAt(k); if (self.send(unescape, cc1)) result[index] = cc1; index += 1 else if (cc1 >= 0xDC00 && cc1 <= 0xDFFF); throw("URI malformed") end if (cc1 < 0xD800 || cc1 > 0xDBFF) index = URIEncodeSingle(cc1, result, index); else k+=1; if (k == uriLength); throw("URI malformed") end cc2 = uri.charCodeAt(k); if (cc2 < 0xDC00 || cc2 > 0xDFFF); throw("URI malformed") end index = URIEncodePair(cc1, cc2, result, index); end end end # return %StringFromCharCodeArray(result); # 'c' = 8 bit signed char # http://www.ruby-doc.org/core-1.9.3/Array.html#method-i-pack return result.pack 'c*' end |