int main( void ) { TESTCASE(iswblank(L' ')); TESTCASE(iswblank(L'\t')); TESTCASE(!iswblank(L'\n')); TESTCASE(!iswblank(L'a')); return TEST_RESULTS; }
int main (void) { /* Check that the function exist as a function or as a macro. */ (void) iswblank (0); /* Check that the isw* functions map WEOF to 0. */ ASSERT (!iswblank (e)); return 0; }
size_t MoveWordEnd(const std::vector<wchar_t>& chars, size_t p) { if (iswpunct(chars[p])) // TODO Use locale? ++p; else if (iswblank(chars[p])) // TODO Use locale? while (p < chars.size() && iswblank(chars[p])) // TODO Use locale? ++p; else while (p < chars.size() && (iswalnum(chars[p]) || chars[p] == L'_')) // TODO Use locale? ++p; return p; }
size_t MoveWordBegin(const std::vector<wchar_t>& chars, size_t p) { if (iswpunct(chars[p])) // TODO Use locale? --p; else if (iswblank(chars[p]) && (p == 0 || iswblank(chars[p - 1]))) // TODO Use locale? while (p > 0 && iswblank(chars[p - 1])) // TODO Use locale? --p; else while (p > 0 && (iswalnum(chars[p - 1]) || chars[p - 1] == L'_')) // TODO Use locale? --p; return p; }
static wchar_t * skip(wchar_t *str) { int nchars, nfields; for (nfields = 0; *str != L'\0' && nfields++ != numfields; ) { while (iswblank(*str)) str++; while (*str != L'\0' && !iswblank(*str)) str++; } for (nchars = numchars; nchars-- && *str != L'\0'; ++str) ; return(str); }
int BLC_PREFIX(iswctype)(wint_t wc, wctype_t desc) { switch (desc) { case wctype_alnum: return iswalnum(wc); case wctype_alpha: return iswalpha(wc); case wctype_blank: return iswblank(wc); case wctype_cntrl: return iswcntrl(wc); case wctype_digit: return iswdigit(wc); case wctype_graph: return iswgraph(wc); case wctype_lower: return iswlower(wc); case wctype_print: return iswprint(wc); case wctype_punct: return iswpunct(wc); case wctype_space: return iswspace(wc); case wctype_upper: return iswupper(wc); case wctype_xdigit: return iswxdigit(wc); default: return 0; } }
int get_trait (qse_wcint_t code) { int trait = 0; if (iswupper(code)) trait |= TRAIT_UPPER; if (iswlower(code)) trait |= TRAIT_LOWER; if (iswalpha(code)) trait |= TRAIT_ALPHA; if (iswdigit(code)) trait |= TRAIT_DIGIT; if (iswxdigit(code)) trait |= TRAIT_XDIGIT; if (iswalnum(code)) trait |= TRAIT_ALNUM; if (iswspace(code)) trait |= TRAIT_SPACE; if (iswprint(code)) trait |= TRAIT_PRINT; if (iswgraph(code)) trait |= TRAIT_GRAPH; if (iswcntrl(code)) trait |= TRAIT_CNTRL; if (iswpunct(code)) trait |= TRAIT_PUNCT; if (iswblank(code)) trait |= TRAIT_BLANK; /* if (iswascii(code)) trait |= TRAIT_ASCII; if (isphonogram(code)) trait |= TRAIT_PHONO; if (isideogram(code)) trait |= TRAIT_IDEOG; if (isenglish(code)) trait |= TRAIT_ENGLI; */ return trait; }
/* * Read string s and parse the string into a fixed-decimal-point number. * sign equals -1 if the number is negative (explicit plus is not allowed, * according to GNU sort's "info sort". * The number part before decimal point is in the smain, after the decimal * point is in sfrac, tail is the pointer to the remainder of the string. */ static int read_number(struct bwstring *s0, int *sign, wchar_t *smain, size_t *main_len, wchar_t *sfrac, size_t *frac_len, unsigned char *si) { bwstring_iterator s; s = bws_begin(s0); /* always end the fraction with zero, even if we have no fraction */ sfrac[0] = 0; while (iswblank(bws_get_iter_value(s))) s = bws_iterator_inc(s, 1); if (bws_get_iter_value(s) == (wchar_t)symbol_negative_sign) { *sign = -1; s = bws_iterator_inc(s, 1); } // This is '0', not '\0', do not change this while (iswdigit(bws_get_iter_value(s)) && (bws_get_iter_value(s) == L'0')) s = bws_iterator_inc(s, 1); while (bws_get_iter_value(s) && *main_len < MAX_NUM_SIZE) { if (iswdigit(bws_get_iter_value(s))) { smain[*main_len] = bws_get_iter_value(s); s = bws_iterator_inc(s, 1); *main_len += 1; } else if (symbol_thousands_sep && (bws_get_iter_value(s) == (wchar_t)symbol_thousands_sep)) s = bws_iterator_inc(s, 1); else break; } smain[*main_len] = 0; if (bws_get_iter_value(s) == (wchar_t)symbol_decimal_point) { s = bws_iterator_inc(s, 1); while (iswdigit(bws_get_iter_value(s)) && *frac_len < MAX_NUM_SIZE) { sfrac[*frac_len] = bws_get_iter_value(s); s = bws_iterator_inc(s, 1); *frac_len += 1; } sfrac[*frac_len] = 0; while (*frac_len > 0 && sfrac[*frac_len - 1] == L'0') { --(*frac_len); sfrac[*frac_len] = L'\0'; } } setsuffix(bws_get_iter_value(s),si); if ((*main_len + *frac_len) == 0) *sign = 0; return (0); }
Term Yap_StringToNumberTerm(char *s, encoding_t *encp) { CACHE_REGS int sno; Term t; sno = Yap_open_buf_read_stream(s, strlen(s), encp, MEM_BUF_USER); if (sno < 0) return FALSE; if (encp) GLOBAL_Stream[sno].encoding = *encp; else GLOBAL_Stream[sno].encoding = LOCAL_encoding; #ifdef __ANDROID__ while (*s && isblank(*s) && Yap_wide_chtype(*s) == BS) s++; #else while (*s && iswblank(*s++)) ; #endif t = Yap_scan_num(GLOBAL_Stream + sno); if (LOCAL_Error_TYPE == SYNTAX_ERROR) LOCAL_Error_TYPE = YAP_NO_ERROR; Yap_CloseStream(sno); UNLOCK(GLOBAL_Stream[sno].streamlock); return t; }
bool move_word_state_machine_t::consume_char_whitespace(wchar_t c) { enum { s_always_one = 0, s_blank, s_graph, s_end }; bool consumed = false; while (state != s_end && !consumed) { switch (state) { case s_always_one: { consumed = true; // always consume the first character state = s_blank; break; } case s_blank: { if (iswblank(c)) { consumed = true; // consumed whitespace } else { state = s_graph; } break; } case s_graph: { if (iswgraph(c)) { consumed = true; // consumed printable non-space } else { state = s_end; } break; } case s_end: default: { break; } } } return consumed; }
int iswctype(wint_t wc, wctype_t type) { switch (type) { case WCTYPE_ALNUM: return iswalnum(wc); case WCTYPE_ALPHA: return iswalpha(wc); case WCTYPE_BLANK: return iswblank(wc); case WCTYPE_CNTRL: return iswcntrl(wc); case WCTYPE_DIGIT: return iswdigit(wc); case WCTYPE_GRAPH: return iswgraph(wc); case WCTYPE_LOWER: return iswlower(wc); case WCTYPE_PRINT: return iswprint(wc); case WCTYPE_PUNCT: return iswpunct(wc); case WCTYPE_SPACE: return iswspace(wc); case WCTYPE_UPPER: return iswupper(wc); case WCTYPE_XDIGIT: return iswxdigit(wc); } return 0; }
long wcstol (const wchar_t * str, wchar_t ** end, int base) { int sign = 0; unsigned long val0; long val; wchar_t ch; // skip blank for (; iswblank (*str); str ++) { } for (ch = *str; (ch == '-') || (ch == '+'); str ++) { } // the sign if ('-' == ch) { sign = 1; str ++; } val0 = wcstoul (str, end, base); if (val0 >= LONG_MAX) { // overflow val = LONG_MAX; if (sign) { val = LONG_MIN; } } else { val = val0; if (sign) { val = -val0; } } return val; }
void test1() { int i; for (i = 0; i < 256; i++) { printf(" %02x: ", i); check_bool(isalnum(i), iswalnum(i), '1'); check_bool(isalpha(i), iswalpha(i), '2'); check_bool(isblank(i), iswblank(i), '3'); check_bool(iscntrl(i), iswcntrl(i), '4'); check_bool(isdigit(i), iswdigit(i), '5'); check_bool(isgraph(i), iswgraph(i), '6'); check_bool(islower(i), iswlower(i), '6'); check_bool(isprint(i), iswprint(i), '7'); check_bool(ispunct(i), iswpunct(i), '8'); check_bool(isspace(i), iswspace(i), '9'); check_bool(isupper(i), iswupper(i), 'a'); check_bool(isxdigit(i), iswxdigit(i), 'b'); check_value(tolower(i), towlower(i), 'c'); check_value(toupper(i), towupper(i), 'd'); if (i % 8 == 7) printf("\n"); } printf("%\n"); }
int main () { /* Check that the isw* functions exist as functions or as macros. */ (void) iswalnum (0); (void) iswalpha (0); #if 0 /* not portable: missing on mingw */ (void) iswblank (0); #endif (void) iswcntrl (0); (void) iswdigit (0); (void) iswgraph (0); (void) iswlower (0); (void) iswprint (0); (void) iswpunct (0); (void) iswspace (0); (void) iswupper (0); (void) iswxdigit (0); /* Check that the isw* functions map WEOF to 0. */ ASSERT (!iswalnum (e)); ASSERT (!iswalpha (e)); #if 0 /* not portable: missing on mingw */ ASSERT (!iswblank (e)); #endif ASSERT (!iswcntrl (e)); ASSERT (!iswdigit (e)); ASSERT (!iswgraph (e)); ASSERT (!iswlower (e)); ASSERT (!iswprint (e)); ASSERT (!iswpunct (e)); ASSERT (!iswspace (e)); ASSERT (!iswupper (e)); ASSERT (!iswxdigit (e)); /* Check that the tow* functions exist as functions or as macros. */ (void) towlower (0); (void) towupper (0); /* Check that the tow* functions map WEOF to WEOF. */ ASSERT (towlower (e) == e); ASSERT (towupper (e) == e); return 0; }
int iswblank_l(wint_t c, struct __locale_t *locale) { /* Silence warning */ _CRT_UNUSED(locale); /* We're using a locale-independent representation of upper/lower case based on Unicode data. Thus, the locale doesn't matter. */ return iswblank (c); }
/* * Rips out leading blanks (-b). */ struct bwstring * ignore_leading_blanks(struct bwstring *str) { if (MB_CUR_MAX == 1) { unsigned char *dst, *end, *src; src = str->data.cstr; dst = src; end = src + str->len; while (src < end && isblank(*src)) ++src; if (src != dst) { size_t newlen; newlen = BWSLEN(str) - (src - dst); while (src < end) { *dst = *src; ++dst; ++src; } bws_setlen(str, newlen); } } else { wchar_t *dst, *end, *src; src = str->data.wstr; dst = src; end = src + str->len; while (src < end && iswblank(*src)) ++src; if (src != dst) { size_t newlen = BWSLEN(str) - (src - dst); while (src < end) { *dst = *src; ++dst; ++src; } bws_setlen(str, newlen); } } return (str); }
/* * Correction of the system API */ double bwstod(struct bwstring *s0, bool *empty) { double ret = 0; if (MB_CUR_MAX == 1) { unsigned char *end, *s; char *ep; s = s0->data.cstr; end = s + s0->len; ep = NULL; while (isblank(*s) && s < end) ++s; if (!isprint(*s)) { *empty = true; return (0); } ret = strtod((char*)s, &ep); if ((unsigned char*) ep == s) { *empty = true; return (0); } } else { wchar_t *end, *ep, *s; s = s0->data.wstr; end = s + s0->len; ep = NULL; while (iswblank(*s) && s < end) ++s; if (!iswprint(*s)) { *empty = true; return (0); } ret = wcstod(s, &ep); if (ep == s) { *empty = true; return (0); } } *empty = false; return (ret); }
/* * Rips out any characters that are not alphanumeric characters * nor blanks (-d). */ struct bwstring * dictionary_order(struct bwstring *str) { size_t newlen = str->len; if (MB_CUR_MAX == 1) { unsigned char *dst, *end, *src; unsigned char c; src = str->data.cstr; dst = src; end = src + str->len; while (src < end) { c = *src; if (isalnum(c) || isblank(c)) { *dst = c; ++dst; ++src; } else { ++src; --newlen; } } } else { wchar_t *dst, *end, *src; wchar_t c; src = str->data.wstr; dst = src; end = src + str->len; while (src < end) { c = *src; if (iswalnum(c) || iswblank(c)) { *dst = c; ++dst; ++src; } else { ++src; --newlen; } } } bws_setlen(str, newlen); return (str); }
/* * Fold the contents of standard input to fit within WIDTH columns (or bytes) * and write to standard output. * * If sflag is set, split the line at the last space character on the line. * This flag necessitates storing the line in a buffer until the current * column > width, or a newline or EOF is read. * * The buffer can grow larger than WIDTH due to backspaces and carriage * returns embedded in the input stream. */ void fold(int width) { static wchar_t *buf; static int buf_max; int col, i, indx, space; wint_t ch; col = indx = 0; while ((ch = getwchar()) != WEOF) { if (ch == '\n') { wprintf(L"%.*ls\n", indx, buf); col = indx = 0; continue; } if ((col = newpos(col, ch)) > width) { if (sflag) { i = indx; while (--i >= 0 && !iswblank(buf[i])) ; space = i; } if (sflag && space != -1) { space++; wprintf(L"%.*ls\n", space, buf); wmemmove(buf, buf + space, indx - space); indx -= space; col = 0; for (i = 0; i < indx; i++) col = newpos(col, buf[i]); } else { wprintf(L"%.*ls\n", indx, buf); col = indx = 0; } col = newpos(col, ch); } if (indx + 1 > buf_max) { buf_max += LINE_MAX; buf = realloc(buf, sizeof(*buf) * buf_max); if (buf == NULL) err(1, "realloc()"); } buf[indx++] = ch; } if (indx != 0) wprintf(L"%.*ls", indx, buf); }
static char *readPath(const char *configFile, int lineNum, char *key, char **startPtr) { char oldchar; char *endtag, *chptr; char *start = *startPtr; char *path; wchar_t pwc; size_t len; if (!isolateValue(configFile, lineNum, key, &start, &endtag)) { oldchar = *endtag, *endtag = '\0'; chptr = start; while( (len = mbrtowc(&pwc, chptr, strlen(chptr), NULL)) != 0 ) { if( len == (size_t)(-1) || len == (size_t)(-2) || !iswprint(pwc) || iswblank(pwc) ) { message(MESS_ERROR, "%s:%d bad %s path %s\n", configFile, lineNum, key, start); return NULL; } chptr += len; } /* while (*chptr && isprint(*chptr) && *chptr != ' ') chptr++; if (*chptr) { message(MESS_ERROR, "%s:%d bad %s path %s\n", configFile, lineNum, key, start); return NULL; } */ path = strdup(start); *endtag = oldchar, start = endtag; *startPtr = start; return path; } else return NULL; }
/* Determine if the given character is of the specified type. */ _WCRTLINK int iswctype( wint_t wc, wctype_t desc ) { switch( desc ) { case WCTYPE_ALNUM: return( iswalnum( wc ) ); case WCTYPE_ALPHA: return( iswalpha( wc ) ); case WCTYPE_BLANK: return( iswblank( wc ) ); case WCTYPE_CNTRL: return( iswcntrl( wc ) ); case WCTYPE_DIGIT: return( iswdigit( wc ) ); case WCTYPE_GRAPH: return( iswgraph( wc ) ); case WCTYPE_LOWER: return( iswlower( wc ) ); case WCTYPE_PRINT: return( iswprint( wc ) ); case WCTYPE_PUNCT: return( iswpunct( wc ) ); case WCTYPE_SPACE: return( iswspace( wc ) ); case WCTYPE_UPPER: return( iswupper( wc ) ); case WCTYPE_XDIGIT: return( iswxdigit( wc ) ); default: return( 0 ); } }
/* This function is equivalent to isblank() for multibyte characters. */ bool is_blank_mbchar(const char *c) { assert(c != NULL); #ifdef ENABLE_UTF8 if (use_utf8) { wchar_t wc; if (mbtowc(&wc, c, MB_CUR_MAX) < 0) { mbtowc_reset(); wc = bad_wchar; } return iswblank(wc); } else #endif return isblank((unsigned char)*c); }
/* * Skip fields according to specs */ static size_t skip_fields_to_start(const struct bwstring *s, size_t fields, bool *empty_field) { if (fields < 2) { if (BWSLEN(s) == 0) *empty_field = true; return (0); } else if (!(sort_opts_vals.tflag)) { size_t cpos = 0; bool pb = true; while (cpos < BWSLEN(s)) { bool isblank; isblank = iswblank(BWS_GET(s, cpos)); if (isblank && !pb) { --fields; if (fields <= 1) return (cpos); } pb = isblank; ++cpos; } if (fields > 1) *empty_field = true; return (cpos); } else { size_t cpos = 0; while (cpos < BWSLEN(s)) { if (BWS_GET(s,cpos) == (wchar_t)sort_opts_vals.field_sep) { --fields; if (fields <= 1) return (cpos + 1); } ++cpos; } if (fields > 1) *empty_field = true; return (cpos); } }
int bws_month_score(const struct bwstring *s0) { if (MB_CUR_MAX == 1) { const unsigned char *end, *s; size_t len; s = s0->data.cstr; end = s + s0->len; while (isblank(*s) && s < end) ++s; len = strlen((const char*)s); for (int i = 11; i >= 0; --i) { if (cmonths[i] && (s == (unsigned char*)strstr((const char*)s, (char*)(cmonths[i])))) return (i); } } else { const wchar_t *end, *s; size_t len; s = s0->data.wstr; end = s + s0->len; while (iswblank(*s) && s < end) ++s; len = wcslen(s); for (int i = 11; i >= 0; --i) { if (wmonths[i] && (s == wcsstr(s, wmonths[i]))) return (i); } } return (-1); }
/* * Skip columns according to specs */ static size_t skip_cols_to_start(const struct bwstring *s, size_t cols, size_t start, bool skip_blanks, bool *empty_key) { if (cols < 1) return (BWSLEN(s) + 1); if (skip_blanks) while (start < BWSLEN(s) && iswblank(BWS_GET(s,start))) ++start; while (start < BWSLEN(s) && cols > 1) { --cols; ++start; } if (start >= BWSLEN(s)) *empty_key = true; return (start); }
int main () { /* Check that the isw* functions exist as functions or as macros. */ iswalnum (0); iswalpha (0); #if 0 /* not portable: missing on mingw */ iswblank (0); #endif iswcntrl (0); iswdigit (0); iswgraph (0); iswlower (0); iswprint (0); iswpunct (0); iswspace (0); iswupper (0); iswxdigit (0); return 0; }
static char *readPath(const char *configFile, int lineNum, char *key, char **startPtr, char **buf, size_t length) { char *chptr; char *start = *startPtr; char *path; wchar_t pwc; size_t len; if ((start = isolateValue(configFile, lineNum, key, startPtr, buf, length)) != NULL) { chptr = start; while( (len = mbrtowc(&pwc, chptr, strlen(chptr), NULL)) != 0 && strlen(chptr) != 0) { if( len == (size_t)(-1) || len == (size_t)(-2) || !iswprint(pwc) || iswblank(pwc) ) { message(MESS_ERROR, "%s:%d bad %s path %s\n", configFile, lineNum, key, start); return NULL; } chptr += len; } /* while (*chptr && isprint(*chptr) && *chptr != ' ') chptr++; if (*chptr) { message(MESS_ERROR, "%s:%d bad %s path %s\n", configFile, lineNum, key, start); return NULL; } */ path = strdup(start); free(start); return path; } else return NULL; }
void wctype_check_functions(wint_t i, wctype_t t, wctrans_t tr, locale_t l) { (void)iswalnum(i); (void)iswalnum_l(i, l); (void)iswalpha(i); (void)iswalpha_l(i, l); (void)iswblank(i); (void)iswblank_l(i, l); (void)iswcntrl(i); (void)iswcntrl_l(i, l); (void)iswctype(i, t); (void)iswctype_l(i, t, l); (void)iswdigit(i); (void)iswdigit_l(i, l); (void)iswgraph(i); (void)iswgraph_l(i, l); (void)iswlower(i); (void)iswlower_l(i, l); (void)iswprint(i); (void)iswprint_l(i, l); (void)iswpunct(i); (void)iswpunct_l(i, l); (void)iswspace(i); (void)iswspace_l(i, l); (void)iswupper(i); (void)iswupper_l(i, l); (void)iswxdigit(i); (void)iswxdigit_l(i, l); (void)towctrans(i, tr); (void)towctrans_l(i, tr, l); (void)towlower(i); (void)towlower_l(i, l); (void)towupper(i); (void)towupper_l(i, l); (void)wctrans((const char *)1234); (void)wctrans_l((const char *)1234, l); (void)wctype((const char *)1234); (void)wctype_l((const char *)1234, l); }
VimMByte::ChClass VimMByte::chclass(wchar_t c) { if (!ismulti(c)) { if (iswblank(c) || c == L'\n') { return VimMByte::BLANK_LF; } if (iswalnum(c) || c == L'_') { return VimMByte::ASCII_WORD; } return VimMByte::OTHER; } if (c == L'、' || c == L'。' || c == L',' || c == L'.') { return VimMByte::PUNCT; } // TODO: Support JA_KANJI etc. return VimMByte::OTHER; }
int __iswblank_l(wint_t c, locale_t l) { return iswblank(c); }