Improves names and comments

pull/210/head
Manni Wood 2016-11-17 22:18:09 -05:00
parent 09ee8a9b70
commit 7bd2e85f31
1 changed files with 31 additions and 26 deletions

View File

@ -3105,51 +3105,55 @@ func parseAclItemArray(arr string) ([]AclItem, error) {
} }
} }
func parseBareAclItem(r *strings.Reader) (AclItem, error) { // parseBareAclItem parses a bare (unquoted) aclitem from reader
var buf bytes.Buffer func parseBareAclItem(reader *strings.Reader) (AclItem, error) {
var aclItem bytes.Buffer
for { for {
rn, _, err := r.ReadRune() rn, _, err := reader.ReadRune()
if err != nil { if err != nil {
// Return the read value in case the error is a harmless io.EOF. // Return the read value in case the error is a harmless io.EOF.
// (io.EOF marks the end of a bare value at the end of a string) // (io.EOF marks the end of a bare aclitem at the end of a string)
return AclItem(buf.String()), err return AclItem(aclItem.String()), err
} }
if rn == ',' { if rn == ',' {
// A comma marks the end of a bare value. // A comma marks the end of a bare aclitem.
return AclItem(buf.String()), nil return AclItem(aclItem.String()), nil
} else { } else {
buf.WriteRune(rn) aclItem.WriteRune(rn)
} }
} }
} }
func parseQuotedAclItem(r *strings.Reader) (AclItem, error) { // parseQuotedAclItem parses an aclitem which is in double quotes from reader
var buf bytes.Buffer func parseQuotedAclItem(reader *strings.Reader) (AclItem, error) {
var aclItem bytes.Buffer
for { for {
rn, escaped, err := readPossiblyEscapedRune(r) rn, escaped, err := readPossiblyEscapedRune(reader)
if err != nil { if err != nil {
if err == io.EOF { if err == io.EOF {
// Even when it is the last value, the final rune of // Even when it is the last value, the final rune of
// a quoted value should be the final closing quote, not io.EOF. // a quoted aclitem should be the final closing quote, not io.EOF.
return AclItem(""), fmt.Errorf("unexpected end of quoted value") return AclItem(""), fmt.Errorf("unexpected end of quoted value")
} }
// Return the read value in case the error is a harmless io.EOF. // Return the read aclitem in case the error is a harmless io.EOF,
return AclItem(buf.String()), err // which will be determined by the caller.
return AclItem(aclItem.String()), err
} }
if !escaped && rn == '"' { if !escaped && rn == '"' {
// An unescaped double quote marks the end of a quoted value. // An unescaped double quote marks the end of a quoted value.
// The next rune should either be a comma or the end of the string. // The next rune should either be a comma or the end of the string.
rn, _, err := r.ReadRune() rn, _, err := reader.ReadRune()
if err != nil { if err != nil {
// Return the read value in case the error is a harmless io.EOF. // Return the read value in case the error is a harmless io.EOF,
return AclItem(buf.String()), err // which will be determined by the caller.
return AclItem(aclItem.String()), err
} }
if rn != ',' { if rn != ',' {
return AclItem(""), fmt.Errorf("unexpected rune after quoted value") return AclItem(""), fmt.Errorf("unexpected rune after quoted value")
} }
return AclItem(buf.String()), nil return AclItem(aclItem.String()), nil
} }
buf.WriteRune(rn) aclItem.WriteRune(rn)
} }
} }
@ -3157,14 +3161,14 @@ func parseQuotedAclItem(r *strings.Reader) (AclItem, error) {
// in that case, it returns the rune after the backslash. The second // in that case, it returns the rune after the backslash. The second
// return value tells us whether or not the rune was // return value tells us whether or not the rune was
// preceeded by a backslash (escaped). // preceeded by a backslash (escaped).
func readPossiblyEscapedRune(r *strings.Reader) (rune, bool, error) { func readPossiblyEscapedRune(reader *strings.Reader) (rune, bool, error) {
rn, _, err := r.ReadRune() rn, _, err := reader.ReadRune()
if err != nil { if err != nil {
return 0, false, err return 0, false, err
} }
if rn == '\\' { if rn == '\\' {
// Discard the backslash and read the next rune. // Discard the backslash and read the next rune.
rn, _, err = r.ReadRune() rn, _, err = reader.ReadRune()
if err != nil { if err != nil {
return 0, false, err return 0, false, err
} }
@ -3181,19 +3185,20 @@ func decodeAclItemArray(vr *ValueReader) []AclItem {
str := vr.ReadString(vr.Len()) str := vr.ReadString(vr.Len())
// short-circuit empty array // Short-circuit empty array.
if str == "{}" { if str == "{}" {
return []AclItem{} return []AclItem{}
} }
// remove the '{' at the front and the '}' at the end // Remove the '{' at the front and the '}' at the end,
// so that parseAclItemArray doesn't have to deal with them.
str = str[1 : len(str)-1] str = str[1 : len(str)-1]
strs, err := parseAclItemArray(str) aclItems, err := parseAclItemArray(str)
if err != nil { if err != nil {
vr.Fatal(ProtocolError(err.Error())) vr.Fatal(ProtocolError(err.Error()))
return nil return nil
} }
return strs return aclItems
} }
func encodeStringSlice(w *WriteBuf, oid Oid, slice []string) error { func encodeStringSlice(w *WriteBuf, oid Oid, slice []string) error {