/** * Creates the text lookup table. * * This should only need to be called once. The results could be made static to * eliminate the need to have lightmagic re-create this static table every time * the program runs, but the overhead is pretty minimal it's probably not worth it. * * Only ASCII is supported - there is no intention to support EBCDIC. */ static void make_text_lookup_table(void) { memset(text_lookup_table, 0, sizeof(text_lookup_table)); int i; for (i = 0; i < LUT_SIZE; i++) { // Formatting characters if ((i == ' ') || (i == '\r') || (i == '\n')) { text_lookup_table[i] |= LUT_TEXT_TEXT | LUT_TEXT_BASE64 | LUT_TEXT_BASE85 | LUT_TEXT_HEX; } // General text if ((g_ascii_isprint(i) || g_ascii_ispunct(i) || g_ascii_isspace(i)) != 0) { text_lookup_table[i] |= LUT_TEXT_TEXT; } // Base64 if (isbase64(i) != 0) { text_lookup_table[i] |= LUT_TEXT_BASE64; } // Base85 if (isbase85(i) != 0) { text_lookup_table[i] |= LUT_TEXT_BASE85; } // Hex digits if (isxdigit(i) != 0) { text_lookup_table[i] |= LUT_TEXT_HEX; } } }
//Removes all punctuation and returns the stripped string gchar* punct_strip(gchar *to_strip){ char *s = g_strdup(to_strip); int i; for (i = 0; s[i]; i++){ if(g_ascii_ispunct(s[i])){ g_stpcpy(&s[i],&s[i+1]); i--; } } return s; }
int length_of_text(char *buff, int buff_len) { int i; for (i = 0; i < buff_len; i++) { if (!(g_ascii_isprint(buff[i]) || g_ascii_ispunct(buff[i]) || g_ascii_isspace(buff[i]))) { break; } } return i; }
/** * mcm_utils_ensure_printable: **/ void mcm_utils_ensure_printable (gchar *text) { guint i; guint idx = 0; g_return_if_fail (text != NULL); for (i=0; text[i] != '\0'; i++) { if (g_ascii_isalnum (text[i]) || g_ascii_ispunct (text[i]) || text[i] == ' ') text[idx++] = text[i]; } text[idx] = '\0'; /* broken profiles have _ instead of spaces */ g_strdelimit (text, "_", ' '); }
gchar *removePunct(gchar *word) { int len = strlen((char *)word); int numpunc = 0; gchar *dest = malloc(sizeof(gchar) * len); for (; NULL != *word; ++word) { gchar c = (gchar) * word; if (!g_ascii_ispunct(c)) { *dest = c; dest++; } else { numpunc++; } } int newlen = len - numpunc; dest = dest - newlen; return dest; }
static int str_ascii_ispunct (const char *text) { return g_ascii_ispunct ((gchar) text[0]); }