static void smf_setup(const enum eSM_Type t, struct STConf *f) { memset(f, 0, sizeof(*f)); switch (t) { case SM_U32U32: f->cmp = (st_cmp_t)cmp_u; break; case SM_I32I32: f->cmp = (st_cmp_t)cmp_i; break; case SM_IntInt: case SM_IntStr: case SM_IntPtr: f->cmp = (st_cmp_t)cmp_I; break; case SM_StrInt: case SM_StrStr: case SM_StrPtr: f->cmp = (st_cmp_t)cmp_s; break; default: break; } f->type = (unsigned)t; f->node_size = sm_elem_size(t); f->iaux1 = SINT_MIN; f->paux1 = (const void *)ss_empty(); }
/* Stores the first word in S into WORD and advances S past that word. Returns true if successful, false if no word remained in S to be extracted. A word is a sequence of digits, a letter possibly followed by a sequence of letters or digits, or one character of another type. Words may be delimited by spaces. */ static bool find_word (struct substring *s, struct substring *word) { size_t ofs; ucs4_t c; /* Skip whitespace. */ for (;;) { c = ss_first_mb (*s); if (c == UINT32_MAX) { *word = ss_empty (); return false; } else if (lex_uc_is_space (c)) ss_get_mb (s); else break; } ofs = ss_first_mblen (*s); if (lex_uc_is_id1 (c)) { while (lex_uc_is_idn (ss_at_mb (*s, ofs))) ofs += ss_at_mblen (*s, ofs); } else if (c_isdigit (c)) { while (c_isdigit (s->string[ofs])) ofs++; } ss_get_bytes (s, ofs, word); return true; }
const ss_t *sm_ss_at(const sm_t *m, const ss_t *k) { ASSERT_RETURN_IF(!m, ss_empty()); struct SMapSS n; n.x.k = (ss_t *)k; /* not going to be overwritten */ const struct SMapSS *nr = (const struct SMapSS *)st_locate(m, (const stn_t *)&n); return nr ? nr->v : (ss_t *)m->f.paux1; }
const ss_t *sm_is_at(const sm_t *m, const sint_t k) { ASSERT_RETURN_IF(!m, ss_empty()); struct SMapIS n; n.x.k = k; const struct SMapIS *nr = (const struct SMapIS *)st_locate(m, (const stn_t *)&n); return nr ? nr->v : (const ss_t *)m->f.paux1; }