const char * atom_summary(atom_t name, unsigned int maxlen) { PL_chars_t txt; Buffer b; size_t i; if ( !get_atom_text(name, &txt) ) return NULL; if ( txt.encoding == ENC_ISO_LATIN_1 && txt.length < maxlen ) { const unsigned char *s = (const unsigned char*) txt.text.t; const unsigned char *e = &s[txt.length]; for( ; s<e; s++ ) { if ( *s >= 0x80 ) break; } if ( s == e ) return txt.text.t; } b = findBuffer(BUF_RING); for(i=0; i<txt.length; i++) { char buf[6]; char *e; e = utf8_put_char(buf, fetch_text(&txt, i)); addMultipleBuffer(b, buf, e-buf, char); if ( i == maxlen - 6 ) { addMultipleBuffer(b, "...", 3, char); i = txt.length - 4; maxlen = 0; /* make sure not to trap again */ } }
static int outchr(format_state *state, int chr) { if ( state->pending_rubber ) { if ( chr > 0x7f ) { char buf[8]; char *s, *e; e = utf8_put_char(buf, chr); for(s=buf; s<e; s++) addBuffer((Buffer)&state->buffer, *s, char); } else { char c = chr;
static int add_encoded_charbuf(charbuf *cb, int c, int flags) { if ( no_escape(c, flags) ) { add_charbuf(cb, c); } else { char tmp[6]; const char *end = utf8_put_char(tmp, c); const char *s; for(s=tmp; s<end; s++) { int b = s[0]&0xff; add_charbuf(cb, '%'); add_charbuf(cb, hexdigit(b>>4)); add_charbuf(cb, hexdigit(b&0xf)); } } return TRUE; }