https://tc39.es/ecma262/multipage/global-object.html#sec-encodeuri-uri
(s string)
| 151 | |
| 152 | // https://tc39.es/ecma262/multipage/global-object.html#sec-encodeuri-uri |
| 153 | func EncodeURI(s string) string { |
| 154 | var builder strings.Builder |
| 155 | for i := range len(s) { |
| 156 | b := s[i] |
| 157 | if !shouldEscapeForEncodeURI(b) { |
| 158 | builder.WriteByte(b) |
| 159 | continue |
| 160 | } |
| 161 | |
| 162 | for _, escaped := range []byte(s[i : i+1]) { |
| 163 | builder.WriteByte('%') |
| 164 | builder.WriteByte(upperhex[escaped>>4]) |
| 165 | builder.WriteByte(upperhex[escaped&0x0f]) |
| 166 | } |
| 167 | } |
| 168 | return builder.String() |
| 169 | } |
| 170 | |
| 171 | const upperhex = "0123456789ABCDEF" |
| 172 |