int str_check(const char *str, int allowed) { int i, n; if (!str) return 1; n = str_len(str); for (i = 0; i < n; i++) { if (allowed & CC_ALNUM && char_isalnum (str[i])) continue; if (allowed & CC_ALPHA && char_isalpha (str[i])) continue; if (allowed & CC_ASCII && char_isascii (str[i])) continue; if (allowed & CC_BLANK && char_isblank (str[i])) continue; if (allowed & CC_CNTRL && char_iscntrl (str[i])) continue; if (allowed & CC_DIGIT && char_isdigit (str[i])) continue; if (allowed & CC_GRAPH && char_isgraph (str[i])) continue; if (allowed & CC_LOWER && char_islower (str[i])) continue; if (allowed & CC_PRINT && char_isprint (str[i])) continue; if (allowed & CC_PUNCT && char_ispunct (str[i])) continue; if (allowed & CC_SPACE && char_isspace (str[i])) continue; if (allowed & CC_UPPER && char_isupper (str[i])) continue; if (allowed & CC_XDIGIT && char_isxdigit(str[i])) continue; return 0; } return 1; }
static const char * str_8bit_term_substring (const char *text, int start, int width) { static char result[BUF_MEDIUM]; size_t remain; char *actual; size_t length; actual = result; remain = sizeof (result); length = strlen (text); if (start < (int) length) { size_t pos; for (pos = start; pos < length && width > 0 && remain > 1; pos++, width--, actual++, remain--) actual[0] = char_isprint (text[pos]) ? text[pos] : '.'; } for (; width > 0 && remain > 1; actual++, remain--, width--) actual[0] = ' '; actual[0] = '\0'; return result; }
static const char * str_8bit_trunc (const char *text, int width) { static char result[MC_MAXPATHLEN]; int remain; char *actual; size_t pos = 0; size_t length; actual = result; remain = sizeof (result); length = strlen (text); if ((int) length > width) { for (; pos + 1 <= (gsize) width / 2 && remain > 1; actual++, pos++, remain--) { actual[0] = char_isprint (text[pos]) ? text[pos] : '.'; } if (remain <= 1) goto finally; actual[0] = '~'; actual++; remain--; pos += length - width + 1; for (; pos < length && remain > 1; pos++, actual++, remain--) { actual[0] = char_isprint (text[pos]) ? text[pos] : '.'; } } else { for (; pos < length && remain > 1; pos++, actual++, remain--) { actual[0] = char_isprint (text[pos]) ? text[pos] : '.'; } } finally: actual[0] = '\0'; return result; }
static const char * str_8bit_term_trim (const char *text, int width) { static char result[BUF_MEDIUM]; size_t remain; char *actual; size_t pos = 0; size_t length; length = strlen (text); actual = result; remain = sizeof (result); if (width > 0) { if (width < (int) length) { if (width <= 3) { memset (actual, '.', width); actual += width; remain -= width; } else { memset (actual, '.', 3); actual += 3; remain -= 3; pos += length - width + 3; for (; pos < length && remain > 1; pos++, actual++, remain--) actual[0] = char_isprint (text[pos]) ? text[pos] : '.'; } } else { for (; pos < length && remain > 1; pos++, actual++, remain--) actual[0] = char_isprint (text[pos]) ? text[pos] : '.'; } } actual[0] = '\0'; return result; }
static const char * str_8bit_term_form (const char *text) { static char result[BUF_MEDIUM]; char *actual; size_t remain; size_t length; size_t pos = 0; actual = result; remain = sizeof (result); length = strlen (text); for (; pos < length && remain > 1; pos++, actual++, remain--) actual[0] = char_isprint (text[pos]) ? text[pos] : '.'; actual[0] = '\0'; return result; }
static const char * str_8bit_fit_to_term (const char *text, int width, align_crt_t just_mode) { static char result[BUF_MEDIUM]; char *actual; size_t remain; int ident = 0; size_t length; size_t pos = 0; length = strlen (text); actual = result; remain = sizeof (result); if ((int) length <= width) { switch (HIDE_FIT (just_mode)) { case J_CENTER_LEFT: case J_CENTER: ident = (width - length) / 2; break; case J_RIGHT: ident = width - length; break; default: break; } if ((int) remain <= ident) goto finally; memset (actual, ' ', ident); actual += ident; remain -= ident; for (; pos < length && remain > 1; pos++, actual++, remain--) actual[0] = char_isprint (text[pos]) ? text[pos] : '.'; if (width - length - ident > 0) { if (remain <= width - length - ident) goto finally; memset (actual, ' ', width - length - ident); actual += width - length - ident; } } else if (IS_FIT (just_mode)) { for (; pos + 1 <= (gsize) width / 2 && remain > 1; actual++, pos++, remain--) actual[0] = char_isprint (text[pos]) ? text[pos] : '.'; if (remain <= 1) goto finally; actual[0] = '~'; actual++; remain--; pos += length - width + 1; for (; pos < length && remain > 1; pos++, actual++, remain--) actual[0] = char_isprint (text[pos]) ? text[pos] : '.'; } else { switch (HIDE_FIT (just_mode)) { case J_CENTER: ident = (length - width) / 2; break; case J_RIGHT: ident = length - width; break; default: break; } pos += ident; for (; pos < (gsize) (ident + width) && remain > 1; pos++, actual++, remain--) actual[0] = char_isprint (text[pos]) ? text[pos] : '.'; } finally: if (actual >= result + sizeof (result)) actual = result + sizeof (result) - 1; actual[0] = '\0'; return result; }
static int str_8bit_isprint (const char *text) { return char_isprint (text[0]); }