parseCapacity matches a Regexp in a []byte, returning the resulting value in bytes. Assumes that the value matched by the Regexp is in KB.
(b []byte, r *regexp.Regexp)
| 267 | // parseCapacity matches a Regexp in a []byte, returning the resulting value in bytes. |
| 268 | // Assumes that the value matched by the Regexp is in KB. |
| 269 | func parseCapacity(b []byte, r *regexp.Regexp) (uint64, error) { |
| 270 | matches := r.FindSubmatch(b) |
| 271 | if len(matches) != 2 { |
| 272 | return 0, fmt.Errorf("failed to match regexp in output: %q", string(b)) |
| 273 | } |
| 274 | m, err := strconv.ParseUint(string(matches[1]), 10, 64) |
| 275 | if err != nil { |
| 276 | return 0, err |
| 277 | } |
| 278 | |
| 279 | // Convert to bytes. |
| 280 | return m * 1024, err |
| 281 | } |
| 282 | |
| 283 | // getUniqueMatchesCount returns number of unique matches in given argument using provided regular expression |
| 284 | func getUniqueMatchesCount(s string, r *regexp.Regexp) int { |
no test coverage detected
searching dependent graphs…