mirror of https://github.com/dsoprea/go-exif.git
Rewrite if-else-if-else to switch statements
parent
c20b208309
commit
9dc630677f
|
@ -108,12 +108,12 @@ func main() {
|
|||
var value interface{}
|
||||
if tagType.Type() == exif.TypeUndefined {
|
||||
var err error
|
||||
value, err = exif.UndefinedValue(ifdPath, tagId, valueContext, tagType.ByteOrder())
|
||||
if log.Is(err, exif.ErrUnhandledUnknownTypedTag) {
|
||||
switch value, err = exif.UndefinedValue(ifdPath, tagId, valueContext, tagType.ByteOrder()); {
|
||||
case log.Is(err, exif.ErrUnhandledUnknownTypedTag):
|
||||
value = nil
|
||||
} else if err != nil {
|
||||
case err != nil:
|
||||
log.Panic(err)
|
||||
} else {
|
||||
default:
|
||||
valueString = fmt.Sprintf("%v", value)
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -30,7 +30,8 @@ type IfdBuilderTagValue struct {
|
|||
}
|
||||
|
||||
func (ibtv IfdBuilderTagValue) String() string {
|
||||
if ibtv.IsBytes() == true {
|
||||
switch {
|
||||
case ibtv.IsBytes():
|
||||
var valuePhrase string
|
||||
if len(ibtv.valueBytes) <= 8 {
|
||||
valuePhrase = fmt.Sprintf("%v", ibtv.valueBytes)
|
||||
|
@ -39,9 +40,9 @@ func (ibtv IfdBuilderTagValue) String() string {
|
|||
}
|
||||
|
||||
return fmt.Sprintf("IfdBuilderTagValue<BYTES=%v LEN=(%d)>", valuePhrase, len(ibtv.valueBytes))
|
||||
} else if ibtv.IsIb() == true {
|
||||
case ibtv.IsIb():
|
||||
return fmt.Sprintf("IfdBuilderTagValue<IB=%s>", ibtv.ib)
|
||||
} else {
|
||||
default:
|
||||
log.Panicf("IBTV state undefined")
|
||||
return ""
|
||||
}
|
||||
|
@ -567,12 +568,12 @@ func (ib *IfdBuilder) printTagTree(levels int) {
|
|||
if isChildIb == true {
|
||||
tagName = "<Child IFD>"
|
||||
} else {
|
||||
it, err := ib.tagIndex.Get(tag.ifdPath, tag.tagId)
|
||||
if log.Is(err, ErrTagNotFound) == true {
|
||||
switch it, err := ib.tagIndex.Get(tag.ifdPath, tag.tagId); {
|
||||
case log.Is(err, ErrTagNotFound):
|
||||
tagName = "<UNKNOWN>"
|
||||
} else if err != nil {
|
||||
case err != nil:
|
||||
log.Panic(err)
|
||||
} else {
|
||||
default:
|
||||
tagName = it.Name
|
||||
}
|
||||
}
|
||||
|
@ -808,13 +809,13 @@ func (ib *IfdBuilder) Set(bt *BuilderTag) (err error) {
|
|||
}
|
||||
}()
|
||||
|
||||
position, err := ib.Find(bt.tagId)
|
||||
if err == nil {
|
||||
switch position, err := ib.Find(bt.tagId); {
|
||||
case err == nil:
|
||||
ib.tags[position] = bt
|
||||
} else if log.Is(err, ErrTagEntryNotFound) == true {
|
||||
case log.Is(err, ErrTagEntryNotFound):
|
||||
err = ib.add(bt)
|
||||
log.PanicIf(err)
|
||||
} else {
|
||||
default:
|
||||
log.Panic(err)
|
||||
}
|
||||
|
||||
|
@ -907,11 +908,12 @@ func (ib *IfdBuilder) add(bt *BuilderTag) (err error) {
|
|||
}
|
||||
}()
|
||||
|
||||
if bt.ifdPath == "" {
|
||||
switch {
|
||||
case bt.ifdPath == "":
|
||||
log.Panicf("BuilderTag ifdPath is not set: %s", bt)
|
||||
} else if bt.typeId == 0x0 {
|
||||
case bt.typeId == 0x0:
|
||||
log.Panicf("BuilderTag type-ID is not set: %s", bt)
|
||||
} else if bt.value == nil {
|
||||
case bt.value == nil:
|
||||
log.Panicf("BuilderTag value is not set: %s", bt)
|
||||
}
|
||||
|
||||
|
|
|
@ -209,8 +209,10 @@ func UndefinedValue(ifdPath string, tagId uint16, valueContext ValueContext, byt
|
|||
|
||||
typeLogger.Debugf(nil, "UndefinedValue: IFD-PATH=[%s] TAG-ID=(0x%02x)", ifdPath, tagId)
|
||||
|
||||
if ifdPath == IfdPathStandardExif {
|
||||
if tagId == 0x9000 {
|
||||
switch ifdPath {
|
||||
case IfdPathStandardExif:
|
||||
switch tagId {
|
||||
case 0x9000:
|
||||
// ExifVersion
|
||||
|
||||
tt := NewTagType(TypeAsciiNoNul, byteOrder)
|
||||
|
@ -219,7 +221,7 @@ func UndefinedValue(ifdPath string, tagId uint16, valueContext ValueContext, byt
|
|||
log.PanicIf(err)
|
||||
|
||||
return TagUnknownType_GeneralString(valueString), nil
|
||||
} else if tagId == 0xa000 {
|
||||
case 0xa000:
|
||||
// FlashpixVersion
|
||||
|
||||
tt := NewTagType(TypeAsciiNoNul, byteOrder)
|
||||
|
@ -228,7 +230,7 @@ func UndefinedValue(ifdPath string, tagId uint16, valueContext ValueContext, byt
|
|||
log.PanicIf(err)
|
||||
|
||||
return TagUnknownType_GeneralString(valueString), nil
|
||||
} else if tagId == 0x9286 {
|
||||
case 0x9286:
|
||||
// UserComment
|
||||
|
||||
tt := NewTagType(TypeByte, byteOrder)
|
||||
|
@ -255,7 +257,7 @@ func UndefinedValue(ifdPath string, tagId uint16, valueContext ValueContext, byt
|
|||
|
||||
typeLogger.Warningf(nil, "User-comment encoding not valid. Returning 'unknown' type (the default).")
|
||||
return unknownUc, nil
|
||||
} else if tagId == 0x927c {
|
||||
case 0x927c:
|
||||
// MakerNote
|
||||
// TODO(dustin): !! This is the Wild Wild West. This very well might be a child IFD, but any and all OEM's define their own formats. If we're going to be writing changes and this is complete EXIF (which may not have the first eight bytes), it might be fine. However, if these are just IFDs they'll be relative to the main EXIF, this will invalidate the MakerNote data for IFDs and any other implementations that use offsets unless we can interpret them all. It be best to return to this later and just exclude this from being written for now, though means a loss of a wealth of image metadata.
|
||||
// -> We can also just blindly try to interpret as an IFD and just validate that it's looks good (maybe it will even have a 'next ifd' pointer that we can validate is 0x0).
|
||||
|
@ -284,7 +286,7 @@ func UndefinedValue(ifdPath string, tagId uint16, valueContext ValueContext, byt
|
|||
}
|
||||
|
||||
return mn, nil
|
||||
} else if tagId == 0x9101 {
|
||||
case 0x9101:
|
||||
// ComponentsConfiguration
|
||||
|
||||
tt := NewTagType(TypeByte, byteOrder)
|
||||
|
@ -310,7 +312,7 @@ func UndefinedValue(ifdPath string, tagId uint16, valueContext ValueContext, byt
|
|||
|
||||
return cc, nil
|
||||
}
|
||||
} else if ifdPath == IfdPathStandardGps {
|
||||
case IfdPathStandardGps:
|
||||
if tagId == 0x001c {
|
||||
// GPSAreaInformation
|
||||
|
||||
|
@ -330,7 +332,7 @@ func UndefinedValue(ifdPath string, tagId uint16, valueContext ValueContext, byt
|
|||
|
||||
return TagUnknownType_GeneralString(valueString), nil
|
||||
}
|
||||
} else if ifdPath == IfdPathStandardExifIop {
|
||||
case IfdPathStandardExifIop:
|
||||
if tagId == 0x0002 {
|
||||
// InteropVersion
|
||||
|
||||
|
|
Loading…
Reference in New Issue