urllib: switch => match
parent
d0cbb4041b
commit
a83aa28a67
|
@ -247,7 +247,9 @@ fn (table mut Table) fn_gen_name(f &Fn) string {
|
||||||
return name
|
return name
|
||||||
}
|
}
|
||||||
|
|
||||||
fn (p mut Parser) gen_method_call(receiver_type, ftyp string, cgen_name string, receiver Var,method_ph int) {
|
fn (p mut Parser) gen_method_call(receiver_type, ftyp string, cgen_name string,
|
||||||
|
receiver Var,method_ph int)
|
||||||
|
{
|
||||||
//mut cgen_name := p.table.fn_gen_name(f)
|
//mut cgen_name := p.table.fn_gen_name(f)
|
||||||
mut method_call := cgen_name + '('
|
mut method_call := cgen_name + '('
|
||||||
// if receiver is key_mut or a ref (&), generate & for the first arg
|
// if receiver is key_mut or a ref (&), generate & for the first arg
|
||||||
|
|
|
@ -91,7 +91,9 @@ fn (table &Table) fn_gen_name(f &Fn) string {
|
||||||
return name
|
return name
|
||||||
}
|
}
|
||||||
|
|
||||||
fn (p mut Parser) gen_method_call(receiver_type, ftyp string, cgen_name string, receiver Var,method_ph int) {
|
fn (p mut Parser) gen_method_call(receiver_type, ftyp string,
|
||||||
|
cgen_name string, receiver Var,method_ph int)
|
||||||
|
{
|
||||||
//mut cgen_name := p.table.fn_gen_name(f)
|
//mut cgen_name := p.table.fn_gen_name(f)
|
||||||
//mut method_call := cgen_name + '('
|
//mut method_call := cgen_name + '('
|
||||||
p.gen('.' + cgen_name.all_after('_') + '(')
|
p.gen('.' + cgen_name.all_after('_') + '(')
|
||||||
|
|
|
@ -55,48 +55,56 @@ fn should_escape(c byte, mode EncodingMode) bool {
|
||||||
// we could possibly allow, and parse will reject them if we
|
// we could possibly allow, and parse will reject them if we
|
||||||
// escape them (because hosts can`t use %-encoding for
|
// escape them (because hosts can`t use %-encoding for
|
||||||
// ASCII bytes).
|
// ASCII bytes).
|
||||||
switch c {
|
if c in [`!`, `$`, `&`, `\\`, `(`, `)`, `*`, `+`, `,`, `;`, `=`,
|
||||||
case `!`, `$`, `&`, `\\`, `(`, `)`, `*`, `+`, `,`, `;`, `=`, `:`, `[`, `]`, `<`, `>`, `"`:
|
`:`, `[`, `]`, `<`, `>`, `"`]
|
||||||
|
{
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
switch c {
|
match c {
|
||||||
case `-`, `_`, `.`, `~`: // §2.3 Unreserved characters (mark)
|
`-`, `_`, `.`, `~` { // §2.3 Unreserved characters (mark)
|
||||||
return false
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
case `$`, `&`, `+`, `,`, `/`, `:`, `;`, `=`, `?`, `@`: // §2.2 Reserved characters (reserved)
|
`$`, `&`, `+`, `,`, `/`, `:`, `;`, `=`, `?`, `@` { // §2.2 Reserved characters (reserved)
|
||||||
// Different sections of the URL allow a few of
|
// Different sections of the URL allow a few of
|
||||||
// the reserved characters to appear unescaped.
|
// the reserved characters to appear unescaped.
|
||||||
switch mode {
|
match mode {
|
||||||
case EncodingMode.encode_path: // §3.3
|
.encode_path { // §3.3
|
||||||
// The RFC allows : @ & = + $ but saves / ; , for assigning
|
// The RFC allows : @ & = + $ but saves / ; , for assigning
|
||||||
// meaning to individual path segments. This package
|
// meaning to individual path segments. This package
|
||||||
// only manipulates the path as a whole, so we allow those
|
// only manipulates the path as a whole, so we allow those
|
||||||
// last three as well. That leaves only ? to escape.
|
// last three as well. That leaves only ? to escape.
|
||||||
return c == `?`
|
return c == `?`
|
||||||
|
}
|
||||||
|
|
||||||
case EncodingMode.encode_path_segment: // §3.3
|
.encode_path_segment { // §3.3
|
||||||
// The RFC allows : @ & = + $ but saves / ; , for assigning
|
// The RFC allows : @ & = + $ but saves / ; , for assigning
|
||||||
// meaning to individual path segments.
|
// meaning to individual path segments.
|
||||||
return c == `/` || c == `;` || c == `,` || c == `?`
|
return c == `/` || c == `;` || c == `,` || c == `?`
|
||||||
|
}
|
||||||
|
|
||||||
case EncodingMode.encode_user_password: // §3.2.1
|
.encode_user_password { // §3.2.1
|
||||||
// The RFC allows `;`, `:`, `&`, `=`, `+`, `$`, and `,` in
|
// The RFC allows `;`, `:`, `&`, `=`, `+`, `$`, and `,` in
|
||||||
// userinfo, so we must escape only `@`, `/`, and `?`.
|
// userinfo, so we must escape only `@`, `/`, and `?`.
|
||||||
// The parsing of userinfo treats `:` as special so we must escape
|
// The parsing of userinfo treats `:` as special so we must escape
|
||||||
// that too.
|
// that too.
|
||||||
return c == `@` || c == `/` || c == `?` || c == `:`
|
return c == `@` || c == `/` || c == `?` || c == `:`
|
||||||
|
}
|
||||||
|
|
||||||
case EncodingMode.encode_query_component: // §3.4
|
.encode_query_component { // §3.4
|
||||||
// The RFC reserves (so we must escape) everything.
|
// The RFC reserves (so we must escape) everything.
|
||||||
return true
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
case EncodingMode.encode_fragment: // §4.1
|
.encode_fragment { // §4.1
|
||||||
// The RFC text is silent but the grammar allows
|
// The RFC text is silent but the grammar allows
|
||||||
// everything, so escape nothing.
|
// everything, so escape nothing.
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if mode == .encode_fragment {
|
if mode == .encode_fragment {
|
||||||
|
|
Loading…
Reference in New Issue