convertExpiresIntegerLineToDayString converts an expires line with an integer value to use a day string. For example: " expires: 7" -> " expires: 7d" Lines that already use a string format (e.g., "expires: 7d", "expires: 24h") are left unchanged. Returns the (possibly converted) line and wheth
(line string)
| 109 | // Lines that already use a string format (e.g., "expires: 7d", "expires: 24h") are left unchanged. |
| 110 | // Returns the (possibly converted) line and whether a conversion was made. |
| 111 | func convertExpiresIntegerLineToDayString(line string) (string, bool) { |
| 112 | indent := getIndentation(line) |
| 113 | trimmedLine := strings.TrimSpace(line) |
| 114 | |
| 115 | // Extract the value part after "expires:" |
| 116 | valuePart := strings.TrimPrefix(trimmedLine, "expires:") |
| 117 | |
| 118 | // Match an integer value optionally followed by whitespace and a comment |
| 119 | matches := expiresIntegerValuePattern.FindStringSubmatch(valuePart) |
| 120 | if matches == nil { |
| 121 | // Not an integer value (already a string like "7d" or "false") |
| 122 | return line, false |
| 123 | } |
| 124 | |
| 125 | intValue := matches[2] // the digits |
| 126 | trailingWS := matches[3] // whitespace between value and comment |
| 127 | comment := matches[4] // optional trailing comment |
| 128 | |
| 129 | // Build the new line, preserving any trailing comment |
| 130 | if comment != "" { |
| 131 | return fmt.Sprintf("%sexpires: %sd%s%s", indent, intValue, trailingWS, comment), true |
| 132 | } |
| 133 | return fmt.Sprintf("%sexpires: %sd", indent, intValue), true |
| 134 | } |