bencode: More renames

This commit is contained in:
Matt Joiner 2016-08-26 14:51:38 +10:00
parent ebdab2d9de
commit 7b2561cea8
3 changed files with 20 additions and 20 deletions

View File

@ -92,7 +92,7 @@ func (d *Decoder) throwSyntaxError(offset int64, err error) {
} }
// called when 'i' was consumed // called when 'i' was consumed
func (d *Decoder) parse_int(v reflect.Value) { func (d *Decoder) parseInt(v reflect.Value) {
start := d.offset - 1 start := d.offset - 1
d.readUntil('e') d.readUntil('e')
if d.buf.Len() == 0 { if d.buf.Len() == 0 {
@ -138,7 +138,7 @@ func (d *Decoder) parse_int(v reflect.Value) {
d.buf.Reset() d.buf.Reset()
} }
func (d *Decoder) parse_string(v reflect.Value) { func (d *Decoder) parseString(v reflect.Value) {
start := d.offset - 1 start := d.offset - 1
// read the string length first // read the string length first
@ -180,7 +180,7 @@ func (d *Decoder) parse_string(v reflect.Value) {
d.buf.Reset() d.buf.Reset()
} }
func (d *Decoder) parse_dict(v reflect.Value) { func (d *Decoder) parseDict(v reflect.Value) {
switch v.Kind() { switch v.Kind() {
case reflect.Map: case reflect.Map:
t := v.Type() t := v.Type()
@ -201,7 +201,7 @@ func (d *Decoder) parse_dict(v reflect.Value) {
}) })
} }
var map_elem reflect.Value var mapElem reflect.Value
// so, at this point 'd' byte was consumed, let's just read key/value // so, at this point 'd' byte was consumed, let's just read key/value
// pairs one by one // pairs one by one
@ -216,12 +216,12 @@ func (d *Decoder) parse_dict(v reflect.Value) {
switch v.Kind() { switch v.Kind() {
case reflect.Map: case reflect.Map:
elem_type := v.Type().Elem() elem_type := v.Type().Elem()
if !map_elem.IsValid() { if !mapElem.IsValid() {
map_elem = reflect.New(elem_type).Elem() mapElem = reflect.New(elem_type).Elem()
} else { } else {
map_elem.Set(reflect.Zero(elem_type)) mapElem.Set(reflect.Zero(elem_type))
} }
valuev = map_elem valuev = mapElem
case reflect.Struct: case reflect.Struct:
var f reflect.StructField var f reflect.StructField
var ok bool var ok bool
@ -237,7 +237,7 @@ func (d *Decoder) parse_dict(v reflect.Value) {
continue continue
} }
tag_name, _ := parse_tag(tag) tag_name, _ := parseTag(tag)
if tag_name == d.key { if tag_name == d.key {
ok = true ok = true
break break
@ -284,7 +284,7 @@ func (d *Decoder) parse_dict(v reflect.Value) {
} }
} }
func (d *Decoder) parse_list(v reflect.Value) { func (d *Decoder) parseList(v reflect.Value) {
switch v.Kind() { switch v.Kind() {
case reflect.Array, reflect.Slice: case reflect.Array, reflect.Slice:
default: default:
@ -441,17 +441,17 @@ func (d *Decoder) parseValue(v reflect.Value) bool {
case 'e': case 'e':
return false return false
case 'd': case 'd':
d.parse_dict(v) d.parseDict(v)
case 'l': case 'l':
d.parse_list(v) d.parseList(v)
case 'i': case 'i':
d.parse_int(v) d.parseInt(v)
default: default:
if b >= '0' && b <= '9' { if b >= '0' && b <= '9' {
// string // string
// append first digit of the length to the buffer // append first digit of the length to the buffer
d.buf.WriteByte(b) d.buf.WriteByte(b)
d.parse_string(v) d.parseString(v)
break break
} }

View File

@ -236,7 +236,7 @@ func encodeFields(t reflect.Type) []encodeField {
if tv == "-" { if tv == "-" {
continue continue
} }
name, opts := parse_tag(tv) name, opts := parseTag(tv)
if name != "" { if name != "" {
ef.tag = name ef.tag = name
} }

View File

@ -4,16 +4,16 @@ import (
"strings" "strings"
) )
type tag_options string type tagOptions string
func parse_tag(tag string) (string, tag_options) { func parseTag(tag string) (string, tagOptions) {
if idx := strings.Index(tag, ","); idx != -1 { if idx := strings.Index(tag, ","); idx != -1 {
return tag[:idx], tag_options(tag[idx+1:]) return tag[:idx], tagOptions(tag[idx+1:])
} }
return tag, tag_options("") return tag, tagOptions("")
} }
func (opts tag_options) contains(option_name string) bool { func (opts tagOptions) contains(option_name string) bool {
if len(opts) == 0 { if len(opts) == 0 {
return false return false
} }