summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/go-git/gcfg/types/scan.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/go-git/gcfg/types/scan.go')
-rw-r--r--vendor/github.com/go-git/gcfg/types/scan.go23
1 files changed, 23 insertions, 0 deletions
diff --git a/vendor/github.com/go-git/gcfg/types/scan.go b/vendor/github.com/go-git/gcfg/types/scan.go
new file mode 100644
index 000000000..db2f6ed3c
--- /dev/null
+++ b/vendor/github.com/go-git/gcfg/types/scan.go
@@ -0,0 +1,23 @@
+package types
+
+import (
+ "fmt"
+ "io"
+ "reflect"
+)
+
+// ScanFully uses fmt.Sscanf with verb to fully scan val into ptr.
+func ScanFully(ptr interface{}, val string, verb byte) error {
+ t := reflect.ValueOf(ptr).Elem().Type()
+ // attempt to read extra bytes to make sure the value is consumed
+ var b []byte
+ n, err := fmt.Sscanf(val, "%"+string(verb)+"%s", ptr, &b)
+ switch {
+ case n < 1 || n == 1 && err != io.EOF:
+ return fmt.Errorf("failed to parse %q as %v: %v", val, t, err)
+ case n > 1:
+ return fmt.Errorf("failed to parse %q as %v: extra characters %q", val, t, string(b))
+ }
+ // n == 1 && err == io.EOF
+ return nil
+}