Skip to content

Commit

Permalink
ncstrwidth() becomes static inline wrapper #1777
Browse files Browse the repository at this point in the history
  • Loading branch information
dankamongmen committed Oct 11, 2021
1 parent 1221312 commit 17267d1
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 35 deletions.
22 changes: 7 additions & 15 deletions include/notcurses/notcurses.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,18 +95,20 @@ typedef enum {
NCSCALE_SCALE_HIRES,
} ncscale_e;

// Returns the number of columns occupied by a multibyte (UTF-8) string, or
// -1 if a non-printable/illegal character is encountered.
// FIXME becomes a static inline in ABI3.
API int ncstrwidth(const char* mbs);

// Returns the number of columns occupied by a the valid prefix of a multibyte
// (UTF-8) string. If an invalid character is encountered, -1 will be returned,
// and the number of valid bytes and columns will be written into *|validbytes|
// and *|validwidth| (assuming them non-NULL). If the entire string is valid,
// *|validbytes| and *|validwidth| reflect the entire string.
API int ncstrwidth_valid(const char* egcs, int* validbytes, int* validwidth);

// Returns the number of columns occupied by a multibyte (UTF-8) string, or
// -1 if a non-printable/illegal character is encountered.
static inline int
ncstrwidth(const char* mbs){
return ncstrwidth_valid(mbs, NULL, NULL);
}

// Returns a heap-allocated copy of the user name under which we are running.
API ALLOC char* notcurses_accountname(void);

Expand Down Expand Up @@ -4133,19 +4135,9 @@ API __attribute__ ((deprecated)) int ncvisual_inflate(struct ncvisual* n, int sc
API void notcurses_debug_caps(const struct notcurses* nc, FILE* debugfp)
__attribute__ ((deprecated)) __attribute__ ((nonnull (1, 2)));

__attribute__ ((deprecated)) API int nccell_width(const struct ncplane* n, const nccell* c);

API ALLOC char* ncvisual_subtitle(const struct ncvisual* ncv)
__attribute__ ((nonnull (1))) __attribute__ ((deprecated));

API uint32_t notcurses_getc(struct notcurses* nc, const struct timespec* ts,
const void* unused, ncinput* ni)
__attribute__ ((nonnull (1))) __attribute__ ((deprecated));

API uint32_t ncdirect_getc(struct ncdirect* nc, const struct timespec *ts,
const void* unused, ncinput* ni)
__attribute__ ((nonnull (1))) __attribute__ ((deprecated));

#undef API
#undef ALLOC

Expand Down
12 changes: 0 additions & 12 deletions src/lib/in.c
Original file line number Diff line number Diff line change
Expand Up @@ -2136,18 +2136,6 @@ uint32_t ncdirect_get(ncdirect* n, const struct timespec* ts, ncinput* ni){
return internal_get(n->tcache.ictx, ts, ni);
}

uint32_t notcurses_getc(notcurses* nc, const struct timespec* ts,
const void* unused, ncinput* ni){
(void)unused; // FIXME remove for abi3
return notcurses_get(nc, ts, ni);
}

uint32_t ncdirect_getc(ncdirect* nc, const struct timespec *ts,
const void* unused, ncinput* ni){
(void)unused; // FIXME remove for abi3
return ncdirect_get(nc, ts, ni);
}

int get_cursor_location(inputctx* ictx, const char* u7, int* y, int* x){
pthread_mutex_lock(&ictx->clock);
while(ictx->cvalid == 0){
Expand Down
8 changes: 0 additions & 8 deletions src/lib/notcurses.c
Original file line number Diff line number Diff line change
Expand Up @@ -1600,10 +1600,6 @@ int ncplane_scrollup_child(ncplane* n, const ncplane* child){
return ret;
}

int nccell_width(const ncplane* n __attribute__ ((unused)), const nccell* c){
return nccell_cols(c);
}

int nccell_load(ncplane* n, nccell* c, const char* gcluster){
int cols;
int bytes = utf8_egc_len(gcluster, &cols);
Expand Down Expand Up @@ -3149,10 +3145,6 @@ int notcurses_ucs32_to_utf8(const uint32_t* ucs32, unsigned ucs32count,
return buflen;
}

int ncstrwidth(const char* mbs){
return ncstrwidth_valid(mbs, NULL, NULL);
}

int ncstrwidth_valid(const char* egcs, int* validbytes, int* validwidth){
int cols = 0; // number of columns consumed thus far
if(validwidth == NULL){
Expand Down

0 comments on commit 17267d1

Please sign in to comment.