mirror of
https://github.com/unidoc/unipdf.git
synced 2025-05-01 22:17:29 +08:00
Reducing the number of types of errors returned
This commit is contained in:
parent
9de46c5b9f
commit
347c2ee0e4
@ -188,8 +188,7 @@ func GetString(obj PdfObject) (string, error) {
|
|||||||
if s, ok := obj.(*PdfObjectString); ok {
|
if s, ok := obj.(*PdfObjectString); ok {
|
||||||
return string(*s), nil
|
return string(*s), nil
|
||||||
}
|
}
|
||||||
err := errors.New("Not a string")
|
return "", ErrTypeCheck
|
||||||
return "", err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetStringBytes returns the bytes represented by `obj` if `obj` is a PdfObjectString or an error if it isn't.
|
// GetStringBytes returns the bytes represented by `obj` if `obj` is a PdfObjectString or an error if it isn't.
|
||||||
@ -197,8 +196,7 @@ func GetStringBytes(obj PdfObject) ([]byte, error) {
|
|||||||
if s, ok := obj.(*PdfObjectString); ok {
|
if s, ok := obj.(*PdfObjectString); ok {
|
||||||
return []byte(*s), nil
|
return []byte(*s), nil
|
||||||
}
|
}
|
||||||
err := errors.New("Not a string")
|
return []byte{}, ErrTypeCheck
|
||||||
return []byte{}, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetName returns the string represented by `obj` if `obj` is a PdfObjectName or an error if it isn't.
|
// GetName returns the string represented by `obj` if `obj` is a PdfObjectName or an error if it isn't.
|
||||||
@ -206,8 +204,7 @@ func GetName(obj PdfObject) (string, error) {
|
|||||||
if s, ok := obj.(*PdfObjectName); ok {
|
if s, ok := obj.(*PdfObjectName); ok {
|
||||||
return string(*s), nil
|
return string(*s), nil
|
||||||
}
|
}
|
||||||
err := errors.New("Not a name")
|
return "", ErrTypeCheck
|
||||||
return "", err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetInteger returns the int represented by `obj` if `obj` is a PdfObjectInteger or an error if it isn't.
|
// GetInteger returns the int represented by `obj` if `obj` is a PdfObjectInteger or an error if it isn't.
|
||||||
@ -215,8 +212,7 @@ func GetInteger(obj PdfObject) (int, error) {
|
|||||||
if i, ok := obj.(*PdfObjectInteger); ok {
|
if i, ok := obj.(*PdfObjectInteger); ok {
|
||||||
return int(*i), nil
|
return int(*i), nil
|
||||||
}
|
}
|
||||||
err := errors.New("Not an integer")
|
return 0, ErrTypeCheck
|
||||||
return 0, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetArray returns the slice of PdfObjects represented by `obj` if `obj` is a PdfObjectArray or an
|
// GetArray returns the slice of PdfObjects represented by `obj` if `obj` is a PdfObjectArray or an
|
||||||
@ -225,8 +221,7 @@ func GetArray(obj PdfObject) ([]PdfObject, error) {
|
|||||||
if s, ok := obj.(*PdfObjectArray); ok {
|
if s, ok := obj.(*PdfObjectArray); ok {
|
||||||
return []PdfObject(*s), nil
|
return []PdfObject(*s), nil
|
||||||
}
|
}
|
||||||
err := errors.New("Not an array")
|
return nil, ErrTypeCheck
|
||||||
return nil, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// EqualObjects returns true if `obj1` and `obj2` have the same contents.
|
// EqualObjects returns true if `obj1` and `obj2` have the same contents.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user