static int lengthestimate(value_t v) { // get the width of an expression if we can do so cheaply if (issymbol(v)) return u8_strwidth(symbol_name(v)); return -1; }
static inline int tinyp(value_t v) { if (issymbol(v)) return (u8_strwidth(symbol_name(v)) < SMALL_STR_LEN); if (fl_isstring(v)) return (cv_len((cvalue_t*)ptr(v)) < SMALL_STR_LEN); return (isfixnum(v) || isbuiltin(v) || v==FL_F || v==FL_T || v==FL_NIL || v == FL_EOF); }
static inline int tinyp(fl_context_t *fl_ctx, value_t v) { if (issymbol(v)) return (u8_strwidth(symbol_name(fl_ctx, v)) < SMALL_STR_LEN); if (fl_isstring(fl_ctx, v)) return (cv_len((cvalue_t*)ptr(v)) < SMALL_STR_LEN); return (isfixnum(v) || isbuiltin(v) || v==fl_ctx->F || v==fl_ctx->T || v==fl_ctx->NIL || v == fl_ctx->FL_EOF); }
int main () { { static const uint8_t input[] = "Danilo \305\240egan"; /* "Danilo Šegan" */ ASSERT (u8_strwidth (input, "UTF-8") == 12); } { static const uint8_t input[] = "Danilo S\314\214egan"; /* "Danilo Šegan" decomposed */ ASSERT (u8_strwidth (input, "UTF-8") == 12); } { static const uint8_t input[] = /* "Данило Шеган" */ "\320\224\320\260\320\275\320\270\320\273\320\276 \320\250\320\265\320\263\320\260\320\275"; ASSERT (u8_strwidth (input, "UTF-8") == 12); ASSERT (u8_strwidth (input, "EUC-JP") == 23); } { static const uint8_t input[] = /* 刘军民 */ "\345\210\230\345\206\233\346\260\221"; ASSERT (u8_strwidth (input, "UTF-8") == 6); ASSERT (u8_strwidth (input, "GB2312") == 6); } return 0; }
static void outsn(char *s, ios_t *f, size_t n) { ios_write(f, s, n); HPOS += u8_strwidth(s); }
static void outs(char *s, ios_t *f) { ios_puts(s, f); HPOS += u8_strwidth(s); }
static void outsn(fl_context_t *fl_ctx, char *s, ios_t *f, size_t n) { ios_write(f, s, n); fl_ctx->HPOS += u8_strwidth(s); }
static void outs(fl_context_t *fl_ctx, char *s, ios_t *f) { ios_puts(s, f); fl_ctx->HPOS += u8_strwidth(s); }