value_t fl_accum_julia_symbol(value_t *args, u_int32_t nargs) { argcount("accum-julia-symbol", nargs, 2); ios_t *s = fl_toiostream(args[1], "accum-julia-symbol"); if (!iscprim(args[0]) || ((cprim_t*)ptr(args[0]))->type != wchartype) type_error("accum-julia-symbol", "wchar", args[0]); uint32_t wc = *(uint32_t*)cp_data((cprim_t*)ptr(args[0])); ios_t str; ios_mem(&str, 0); while (jl_id_char(wc)) { ios_getutf8(s, &wc); if (wc == '!') { uint32_t nwc; ios_peekutf8(s, &nwc); // make sure != is always an operator if (nwc == '=') { ios_ungetc('!', s); break; } } ios_pututf8(&str, wc); if (ios_peekutf8(s, &wc) == IOS_EOF) break; } ios_pututf8(&str, 0); return symbol(normalize(str.buf)); }
value_t fl_accum_julia_symbol(fl_context_t *fl_ctx, value_t *args, uint32_t nargs) { argcount(fl_ctx, "accum-julia-symbol", nargs, 2); ios_t *s = fl_toiostream(fl_ctx, args[1], "accum-julia-symbol"); if (!iscprim(args[0]) || ((cprim_t*)ptr(args[0]))->type != fl_ctx->wchartype) type_error(fl_ctx, "accum-julia-symbol", "wchar", args[0]); uint32_t wc = *(uint32_t*)cp_data((cprim_t*)ptr(args[0])); ios_t str; int allascii=1; ios_mem(&str, 0); do { allascii &= (wc <= 0x7f); ios_getutf8(s, &wc); if (wc == '!') { uint32_t nwc; ios_peekutf8(s, &nwc); // make sure != is always an operator if (nwc == '=') { ios_ungetc('!', s); break; } } ios_pututf8(&str, wc); if (ios_peekutf8(s, &wc) == IOS_EOF) break; } while (jl_id_char(wc)); ios_pututf8(&str, 0); return symbol(fl_ctx, allascii ? str.buf : normalize(fl_ctx, str.buf)); }
value_t fl_skipws(value_t *args, u_int32_t nargs) { argcount("skip-ws", nargs, 2); ios_t *s = fl_toiostream(args[0], "skip-ws"); int newlines = (args[1]!=FL_F); uint32_t wc=0; if (ios_peekutf8(s, &wc) == IOS_EOF) return FL_EOF; value_t skipped = FL_F; while (!ios_eof(s) && (is_uws(wc) || is_bom(wc)) && (newlines || wc!=10)) { skipped = FL_T; ios_getutf8(s, &wc); ios_peekutf8(s, &wc); } return skipped; }
value_t fl_skipws(fl_context_t *fl_ctx, value_t *args, uint32_t nargs) { argcount(fl_ctx, "skip-ws", nargs, 2); ios_t *s = fl_toiostream(fl_ctx, args[0], "skip-ws"); int newlines = (args[1]!=fl_ctx->F); uint32_t wc=0; value_t skipped = fl_ctx->F; while (1) { if (ios_peekutf8(s, &wc) == IOS_EOF) { ios_getutf8(s, &wc); // to set EOF flag if this is a true EOF if (!ios_eof(s)) lerror(fl_ctx, symbol(fl_ctx, "error"), "incomplete character"); return fl_ctx->FL_EOF; } if (!ios_eof(s) && (is_uws(wc) || is_bom(wc)) && (newlines || wc!=10)) { skipped = fl_ctx->T; ios_getutf8(s, &wc); } else { break; } } return skipped; }