+ return false;
+}
+
+static bool
+validate_esc_clean_all (const char **p)
+{
+ while (isdigit (**p) || **p == ';')
+ (*p)++;
+ return (**p == 'm');
+}
+
+static bool
+validate_esc_clean (int value, unsigned int iter, const char **p, bool *check_values)
+{
+ if (is_reset (value, iter, p))
+ return true;
+ else if (is_bold (value, iter, p))
+ {
+ (*p)++;
+ *check_values = true;
+ return false; /* partial escape sequence, need another valid value */
+ }
+ else if (is_fg_color (value, p))
+ return true;
+ else if (is_bg_color (value, iter, p))
+ return true;
+ else
+ return false;
+}
+
+static bool
+is_reset (int value, unsigned int iter, const char **p)
+{
+ return (value == 0 && iter == 1 && **p == 'm');
+}
+
+static bool
+is_bold (int value, unsigned int iter, const char **p)
+{
+ return (value == 1 && iter == 1 && **p == ';');
+}
+
+static bool
+is_fg_color (int value, const char **p)
+{
+ return (((value >= 30 && value <= 37) || value == 39) && **p == 'm');
+}
+
+static bool
+is_bg_color (int value, unsigned int iter, const char **p)
+{
+ return (((value >= 40 && value <= 47) || value == 49) && iter == 1 && **p == 'm');