Skip to content

Commit

Permalink
Fixes bug parsing control fields
Browse files Browse the repository at this point in the history
  • Loading branch information
hectorcorrea committed Jun 28, 2018
1 parent 1074cd3 commit fb35307
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions field.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,24 @@ func (f *Fields) Add(field Field) {

func NewField(tag, valueStr string) Field {
value := Field{Tag: tag}
if tag <= "008" {
// Control fields (001-008) don't have indicators or subfields
// so we just get the value as-is.
value.RawValue = valueStr
return value
}

// Process the indicators and subfields
if len(valueStr) >= 2 {
value.Ind1 = string(valueStr[0])
value.Ind2 = string(valueStr[1])
}

if len(valueStr) > 2 {
// notice that we skip the indicators because they are handled above
// and valueStr[2] because that's a separator character
// notice that we skip the indicators [0] and [1] because they are handled
// above and valueStr[2] because that's a separator character
value.RawValue = valueStr[3:]
}

if tag > "009" {
value.SubFields = NewSubFieldValues(valueStr)
}
value.SubFields = NewSubFieldValues(valueStr)
return value
}

Expand Down

0 comments on commit fb35307

Please sign in to comment.