libgrapheme

grapheme cluster utility library
git clone git://git.suckless.org/libgrapheme
Log | Files | Refs | LICENSE

util.c (704B)


      1 /* See LICENSE file for copyright and license details. */
      2 #include "util.h"
      3 
      4 int
      5 heisenstate_get(struct heisenstate *h, int slot)
      6 {
      7 	if (h == NULL || slot >= 16 || slot < 0 ||
      8 	    !(h->determined & (1 << slot))) {
      9 		/* no state given, slot out of range or undetermined */
     10 		return -1;
     11 	} else {
     12 		/* slot determined, return state (0 or 1) */
     13 		return (h->state & (1 << slot)) ? 1 : 0;
     14 	}
     15 }
     16 
     17 int
     18 heisenstate_set(struct heisenstate *h, int slot, int state)
     19 {
     20 	if (h == NULL || slot >= 16 || slot < 0) {
     21 		/* no state given or slot out of range */
     22 		return 1;
     23 	} else {
     24 		h->determined |= (1 << slot);
     25 		if (state) {
     26 			h->state |= (1 << slot);
     27 		} else {
     28 			h->state &= ~(1 << slot);
     29 		}
     30 	}
     31 
     32 	return 0;
     33 }