diff options
| author | Jeff Carr <[email protected]> | 2025-10-20 13:19:36 -0500 | 
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2025-10-20 13:19:36 -0500 | 
| commit | c80607489ccab9f72a1efe860757725896515f87 (patch) | |
| tree | e04f0d38b38a19e5742098a2a2287f9271e773f9 | |
| parent | aba84efbf84d61a538e8c1e34834cd604f81372c (diff) | |
the point of cobol is to turn everything into a stringv0.0.28
| -rw-r--r-- | int.go | 41 | 
1 files changed, 41 insertions, 0 deletions
@@ -0,0 +1,41 @@ +package cobol + +import ( +	"strconv" +	"strings" +) + +// just give back an int +func Int(maybeInt any) int { +	switch v := maybeInt.(type) { +	case int: +		return v +	case *int: +		return *v +	case string: +		s := strings.TrimSpace(v) +		if s == "" { +			return 0 +		} +		i, err := strconv.Atoi(s) +		if err == nil { +			return i +		} +		parts := strings.Fields(s) +		if len(parts) == 0 { +			return 0 +		} +		// check every field for an int. sure, why not +		for _, part := range parts { +			if part == "" { +				continue +			} +			i, err := strconv.Atoi(part) +			if err == nil { +				return i +			} +		} +		return i +	} +	return 0 +}  | 
