Add proptools.Int and proptools.IntDefault

Add proptools.Int and proptools.IntDefault that behave analogously
to proptools.String and proptools.StringDefault.

Change-Id: I41fd3417c973c9ff4a5aa6680546b4b893784745
This commit is contained in:
Colin Cross 2019-09-25 11:25:04 -07:00
parent 884e7374fb
commit 66c0b13553
2 changed files with 17 additions and 0 deletions

2
go.mod
View file

@ -1 +1,3 @@
module github.com/google/blueprint
go 1.13

View file

@ -82,3 +82,18 @@ func StringDefault(s *string, def string) string {
func String(s *string) string {
return StringDefault(s, "")
}
// IntDefault takes a pointer to an int64 and returns the value pointed to by the pointer cast to int
// if it is non-nil, or def if the pointer is nil.
func IntDefault(i *int64, def int) int {
if i != nil {
return int(*i)
}
return def
}
// Int takes a pointer to an int64 and returns the value pointed to by the pointer cast to int
// if it is non-nil, or 0 if the pointer is nil.
func Int(i *int64) int {
return IntDefault(i, 0)
}