您当前的位置:首页 > IT编程 > C++
| C语言 | Java | VB | VC | python | Android | TensorFlow | C++ | oracle | 学术与代码 | cnn卷积神经网络 | gnn | 图像修复 | Keras | 数据集 | Neo4j | 自然语言处理 | 深度学习 | 医学CAD | 医学影像 | 超参数 | pointnet | pytorch | 异常检测 | Transformers | 情感分类 | 知识图谱 |

自学教程:C++ wcswidth函数代码示例

51自学网 2021-06-03 09:54:19
  C++
这篇教程C++ wcswidth函数代码示例写得很实用,希望能帮到您。

本文整理汇总了C++中wcswidth函数的典型用法代码示例。如果您正苦于以下问题:C++ wcswidth函数的具体用法?C++ wcswidth怎么用?C++ wcswidth使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。

在下文中一共展示了wcswidth函数的29个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: xwaddnstr

int xwaddnstr (WINDOW *win, const char *str, const int n){	int res, width, inv_char;	wchar_t *ucs;	char *mstr, *lstr;	size_t size, num_chars;	assert (n > 0);	assert (str != NULL);	mstr = iconv_str (iconv_desc, str);	size = xmbstowcs (NULL, mstr, -1, NULL) + 1;	ucs = (wchar_t *)xmalloc (sizeof(wchar_t) * size);	xmbstowcs (ucs, mstr, size, &inv_char);	width = wcswidth (ucs, WIDTH_MAX);	if (width == -1) {		size_t clidx;		for (clidx = 0; clidx < size - 1; clidx++) {			if (wcwidth (ucs[clidx]) == -1)				ucs[clidx] = L'?';		}		width = wcswidth (ucs, WIDTH_MAX);		inv_char = 1;	}	if (width > n) {		while (width > n)			width -= wcwidth (ucs[--size]);		ucs[size] = L'/0';	}	num_chars = wcstombs (NULL, ucs, 0);	lstr = (char *)xmalloc (num_chars + 1);	if (inv_char)		wcstombs (lstr, ucs, num_chars + 1);	else		snprintf (lstr, num_chars + 1, "%s", mstr);	res = waddstr (win, lstr);	free (ucs);	free (lstr);	free (mstr);	return res;}
开发者ID:console-tools,项目名称:moc,代码行数:48,


示例2: tst_wcswidth

inttst_wcswidth (FILE *fp, int debug_flg){  TST_DECL_VARS (int);  wchar_t *ws;  int n;  TST_DO_TEST (wcswidth)  {    TST_HEAD_LOCALE (wcswidth, S_WCSWIDTH);    TST_DO_REC (wcswidth)    {      TST_GET_ERRET (wcswidth);      ws = TST_INPUT (wcswidth).ws;      n = TST_INPUT (wcswidth).n;      ret = wcswidth (ws, n);      if (debug_flg)	{	  fprintf (stderr, "wcswidth: [ %d ] : ret = %d/n", rec + 1, ret);	}      TST_IF_RETURN (S_WCSWIDTH)      {      };    }  }  return err_count;}
开发者ID:AdvancedC,项目名称:glibc,代码行数:30,


示例3: ustrwid

int ustrwid(wchar_t const *s, int charset){    char buf[256];    int wid, len = ustrlen(s);    charset_state state = CHARSET_INIT_STATE;    wid = 0;    while (len > 0) {	int err;	wchar_t const *s_orig;	err = 0;	s_orig = s;        charset_from_unicode(&s, &len, buf, lenof(buf), charset, &state, &err);	wid += wcswidth(s_orig, s - s_orig);	if (err) {	    assert(len > 0 && *s);	    s++;	    len--;	}    }    return wid;}
开发者ID:mloar,项目名称:halibut,代码行数:25,


示例4: assert

/* Return a malloc()ed string containing the tail of 'str' up to a * maximum of 'len' characters (in columns occupied on the screen). */char *xstrtail (const char *str, const int len){	wchar_t *ucs;	wchar_t *ucs_tail;	size_t size;	int width;	char *tail;	assert (str != NULL);	assert (len > 0);	size = xmbstowcs(NULL, str, -1, NULL) + 1;	ucs = (wchar_t *)xmalloc (sizeof(wchar_t) * size);	xmbstowcs (ucs, str, size, NULL);	ucs_tail = ucs;	width = wcswidth (ucs, WIDTH_MAX);	assert (width >= 0);	while (width > len)		width -= wcwidth (*ucs_tail++);	size = wcstombs (NULL, ucs_tail, 0) + 1;	tail = (char *)xmalloc (size);	wcstombs (tail, ucs_tail, size);	free (ucs);	return tail;}
开发者ID:console-tools,项目名称:moc,代码行数:32,


示例5: str2wstr

size_t utils::strwidth(const std::string& str) {	std::wstring wstr = str2wstr(str);	int width = wcswidth(wstr.c_str(), wstr.length());	if (width < 1) // a non-printable character found?		return wstr.length(); // return a sane width (which might be larger than necessary)	return width; // exact width}
开发者ID:2ion,项目名称:newsbeuter,代码行数:7,


示例6: utf8_strlen_screen

intutf8_strlen_screen (const char *string){    int length, num_char;    wchar_t *wstring;        if (!string)        return 0;        if (!local_utf8)        return utf8_strlen (string);        num_char = mbstowcs (NULL, string, 0) + 1;    wstring = malloc ((num_char + 1) * sizeof (wstring[0]));    if (!wstring)        return utf8_strlen (string);        if (mbstowcs (wstring, string, num_char) == (size_t)(-1))    {        free (wstring);        return utf8_strlen (string);    }        length = wcswidth (wstring, num_char);    free (wstring);    return length;}
开发者ID:matsuu,项目名称:weechat,代码行数:27,


示例7: sizeOfOneLineInTerm

/* * Return the cursor position of the cursor in the line. * Note 1: This function doesn't return the cursor position in the whole command line. * A line is every wide characters separated by L'/n' or L'/0'. * Note 2 : This function return the number of column used. * It may not correspond to the number of characters. */static int sizeOfOneLineInTerm(wchar_t * CommandLine, unsigned int cursorLocation){    unsigned int beginningOfLine = cursorLocation;    int sizeOfLineInTerm = 0;    wchar_t saveLastWChar = 0;    /* Character under cursor saved */    saveLastWChar = CommandLine[cursorLocation];    /* Set the end of the line to the cursor position */    CommandLine[cursorLocation] = L'/0';    /* Looking for the beginning of the line (L'/n' or beginning of the command line) */    while (CommandLine[beginningOfLine] != L'/n' && beginningOfLine)    {        beginningOfLine--;    }    /* If the line is the first of the command, prompt size must be added */    if (!beginningOfLine)    {        sizeOfLineInTerm += printPrompt(NOWRITE_PROMPT);    }    /* If L'/n' is found, the line start to the next character */    if (CommandLine[beginningOfLine] == L'/n')    {        beginningOfLine++;    }    /* Set the beginning of the line */    CommandLine += beginningOfLine;    /* Get the number of column used by the line */    sizeOfLineInTerm += wcswidth(CommandLine, wcslen(CommandLine));    /* Previously saved character put back in the command line */    CommandLine[cursorLocation - beginningOfLine] = saveLastWChar;    return sizeOfLineInTerm;}
开发者ID:ASP1234,项目名称:Scilabv5.5.2,代码行数:42,


示例8: cmd_end

/* Moves cursor to the end of command-line on Ctrl+E and End. */static voidcmd_end(key_info_t key_info, keys_info_t *keys_info){	input_stat.index = input_stat.len;	input_stat.curs_pos = input_stat.prompt_wid +			wcswidth(input_stat.line, (size_t)-1);	update_cursor();}
开发者ID:ackeack,项目名称:workenv,代码行数:9,


示例9: wideLength

size_t wideLength(const std::wstring &ws){	int len = wcswidth(ws.c_str(), -1);	if (len < 0)		return ws.length();	else		return len;}
开发者ID:mineman117,项目名称:ncmpcpp,代码行数:8,


示例10: wis_2cols

static int wis_2cols(wchar_t c){    wchar_t buf[256];    buf[0] = c;    buf[1] = 0;    return wcswidth(buf, 10) == 2;}
开发者ID:ab25cq,项目名称:xyzsh,代码行数:9,


示例11: gcc_gettext_width

size_tgcc_gettext_width (const char *msgstr){  size_t nwcs = mbstowcs (0, msgstr, 0);  wchar_t *wmsgstr = alloca ((nwcs + 1) * sizeof (wchar_t));  mbstowcs (wmsgstr, msgstr, nwcs + 1);  return wcswidth (wmsgstr, nwcs);}
开发者ID:applesnake,项目名称:cocotron-tools-gpl3,代码行数:9,


示例12: getpadding

int getpadding(int len, char *str){	wchar_t wbuffer[64];	if (!cfg.utflocale) {		return len;	}	if ((int)mbstowcs(wbuffer, str, 64) < 0) {		return len;	}	return len + ((int)strlen(str) - wcswidth(wbuffer, 64));}
开发者ID:ItTakesTwo,项目名称:vnstat,代码行数:11,


示例13: stfl_print_richtext

unsigned int stfl_print_richtext(struct stfl_widget *w, WINDOW *win, unsigned int y, unsigned int x, const wchar_t * text, unsigned int width, const wchar_t * style_normal, int has_focus){	const wchar_t *p = text;	unsigned int retval = 0;	unsigned int end_col = x + width;	while (*p) {		unsigned int len = compute_len_from_width(p, end_col - x);		const wchar_t *p1 = wcschr(p, L'<');		if (NULL == p1) {			mvwaddnwstr(win, y, x, p, len);			retval += len;			break;		} else {			const wchar_t *p2 = wcschr(p1 + 1, L'>');			if (len > (p1 - p))				len = p1 - p;			mvwaddnwstr(win, y, x, p, len);			retval += len;			x += wcswidth(p, len);			if (p2) {				wchar_t stylename[p2 - p1];				wmemcpy(stylename, p1 + 1, p2 - p1 - 1);				stylename[p2 - p1 - 1] = L'/0';				if (wcscmp(stylename,L"")==0) {					mvwaddnwstr(win, y, x, L"<", 1);					retval += 1;					++x;				} else if (wcscmp(stylename, L"/")==0) {					stfl_style(win, style_normal);				} else {					wchar_t lookup_stylename[128];					const wchar_t * style;					if (has_focus)						swprintf(lookup_stylename, sizeof(lookup_stylename)/sizeof(*lookup_stylename), L"style_%ls_focus", stylename);					else						swprintf(lookup_stylename, sizeof(lookup_stylename)/sizeof(*lookup_stylename), L"style_%ls_normal", stylename);					style = stfl_widget_getkv_str(w, lookup_stylename, L"");					stfl_style(win, style);				}				p = p2 + 1;			} else {				break;			}		}	}	return retval;}
开发者ID:chazu,项目名称:stfl,代码行数:51,


示例14: init_hdr_cols

static voidinit_hdr_cols(enum be_fmt be_fmt, struct hdr_info *hdr){	struct col_info *col = hdr->cols;	size_t i;	col[1].col_name = _("Active");	col[2].col_name = _("Mountpoint");	col[3].col_name = _("Space");	col[4].col_name = _("Policy");	col[5].col_name = _("Created");	col[6].col_name = NULL;	switch (be_fmt) {	case BE_FMT_ALL:		col[0].col_name = _("BE/Dataset/Snapshot");		break;	case BE_FMT_DATASET:		col[0].col_name = _("BE/Dataset");		break;	case BE_FMT_SNAPSHOT:		col[0].col_name = _("BE/Snapshot");		col[1].col_name = NULL;		col[2].col_name = NULL;		break;	case BE_FMT_DEFAULT:	default:		col[0].col_name = _("BE");	}	for (i = 0; i < NUM_COLS; i++) {		const char *name = col[i].col_name;		col[i].width = 0;		if (name != NULL) {			wchar_t wname[128];			size_t sz = mbstowcs(wname, name, sizeof (wname) /			    sizeof (wchar_t));			if (sz > 0) {				int wcsw = wcswidth(wname, sz);				if (wcsw > 0)					col[i].width = wcsw;				else					col[i].width = sz;			} else {				col[i].width = strlen(name);			}		}	}}
开发者ID:allanjude,项目名称:illumos-gate,代码行数:50,


示例15: table_render_row

/* render a row */static void table_render_row (Table* t, int rownum, int ncols, wchar_t** s){        wchar_t** row = t->rows[rownum];        size_t len = 1, i;        size_t newsize;        assert(t);        assert(s != NULL);        for (i = 0; i < ncols; ++i)                len += t->widths[i] + wcslen(DELIMITER);        len += wcslen(COLSUFFIX);        newsize = (wcslen(*s) + len + 1) * sizeof(wchar_t);        *s = xrealloc (*s, newsize);        for (i = 0; i < ncols; ++i)        {                wcscat (*s, row[i]);                if (ncols <= i + 1)                        break;                int j;                int nspaces = max(t->widths[i] - wcswidth(row[i], MAX_WIDTH),                                  0);                wchar_t* pad = xmalloc ((nspaces + 1) * sizeof(*pad));                for (j = 0; j < nspaces; ++j)                       pad[j] = L' ';                pad[nspaces] = L_('/0');                wcscat (*s, pad);                if (i + 1 < ncols)                        wcscat (*s, DELIMITER);                free (pad);        }        /* Remove any trailing blanks.  */        wchar_t *p = *s;        size_t k = wcslen (p);        while (k && p[k-1] == L_(' '))                --k;        p[k] = L_('/0');        wcscat (*s, COLSUFFIX);}
开发者ID:unsound,项目名称:parted-freebsd,代码行数:51,


示例16: set_searching_status

static voidset_searching_status (action_find_res_wnd_t *__res_wnd,                      const wchar_t *__action, const wchar_t *__path){  wchar_t format[1024], path[1024];  size_t width;  swprintf (format, BUF_LEN (format), L"%ls: %%ls", __action);  width = wcswidth (format, wcslen (format));  fit_dirname (__path,               __res_wnd->window->position.width - 6 - width, path);  set_status (__res_wnd, _(format), path);}
开发者ID:Nazg-Gul,项目名称:fm,代码行数:15,


示例17: byte2width2

static int byte2width2(char *str, int n){  int width;  int str_byte;  char save_char;  char *save_str;  wchar_t *wcstr;  int nr_wchars;    assert(str != NULL);  if (n <= 0) {    return 0;  }  str_byte = strlen(str);  if (str_byte == 0) {    return 0;  }  if (n > str_byte) {    n = str_byte;  }  wcstr = uim_malloc(sizeof(wchar_t) * str_byte);  save_str = str;  save_char = str[n];  str[n] = '/0';  nr_wchars = mbsrtowcs(wcstr, (const char **)&str, str_byte, NULL);  save_str[n] = save_char;  if ((size_t)nr_wchars != (size_t)(-1)) {    width = wcswidth(wcstr, nr_wchars);  } else {    mbsrtowcs(wcstr, (const char **)&str, 1, NULL);    /* strを最後まで
C++ wctomb函数代码示例
C++ wcstring函数代码示例
万事OK自学网:51自学网_软件自学网_CAD自学网自学excel、自学PS、自学CAD、自学C语言、自学css3实例,是一个通过网络自主学习工作技能的自学平台,网友喜欢的软件自学网站。