Parse a color hex string (`#RRGGBB`) and return a C2D color. Return 0 if parsing failed. */
| 142 | Return 0 if parsing failed. |
| 143 | */ |
| 144 | uint32_t StringUtils::ParseColorHexString(std::string_view str) { |
| 145 | if (str.size() != 7) return 0; |
| 146 | if (str[0] != '#') return 0; |
| 147 | |
| 148 | uint8_t colorVal[3]; |
| 149 | for (int i = 0; i < 3; i++) { |
| 150 | const char *colorValStart = str.data() + 1 + i * 2; |
| 151 | auto result = std::from_chars(colorValStart, colorValStart + 2, colorVal[i], 16); |
| 152 | if (result.ec != std::errc()) return 0; |
| 153 | if (result.ptr != colorValStart + 2) return 0; |
| 154 | } |
| 155 | |
| 156 | return C2D_Color32(colorVal[0], colorVal[1], colorVal[2], 255); |
| 157 | } |
| 158 | |
| 159 | /* |
| 160 | Formats a date to a relative date (ie 1 month ago) |