当前位置: 首页>>代码示例>>C++>>正文


C++ xstrlen函数代码示例

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


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

示例1: bsubst

// bsubst rewites b to replace all occurrences of x with y.
void
bsubst(Buf *b, char *x, char *y)
{
	char *p;
	int nx, ny, pos;

	nx = xstrlen(x);
	ny = xstrlen(y);

	pos = 0;
	for(;;) {
		p = xstrstr(bstr(b)+pos, x);
		if(p == nil)
			break;
		if(nx != ny) {
			if(nx < ny) {
				pos = p - b->p;
				bgrow(b, ny-nx);
				p = b->p + pos;
			}
			xmemmove(p+ny, p+nx, (b->p+b->len)-(p+nx));
		}
		xmemmove(p, y, ny);
		pos = p+ny - b->p;
		b->len += ny - nx;
	}
}
开发者ID:29decibel,项目名称:golang,代码行数:28,代码来源:buf.c

示例2: n2a_event_host_check

int
n2a_event_host_check (int event_type __attribute__ ((__unused__)), void *data)
{
  //logger(LG_DEBUG, "Event: event_service_check");
  nebstruct_host_check_data *c = (nebstruct_host_check_data *) data;

  if (c->type == NEBTYPE_HOSTCHECK_PROCESSED)
    {
      //logger(LG_DEBUG, "HOSTCHECK_PROCESSED: %s", c->host_name);
      char *buffer = NULL, *key = NULL;

      size_t l = xstrlen(g_options.connector) + xstrlen(g_options.eventsource_name) + xstrlen(c->host_name) + 20; 

      nebstruct_host_check_data_to_json(&buffer, c); 

      // DO NOT FREE !!!
      xalloca(key, xmin(g_options.max_size, (int)l) * sizeof(char));

      snprintf(key, xmin(g_options.max_size, (int)l),
                 "%s.%s.check.component.%s", g_options.connector,
                 g_options.eventsource_name, c->host_name);

      if (c_size == -10000 || c_size / 2 == 0)
          amqp_publish(key, buffer);
      else
          n2a_record_cache (key, buffer);

      xfree(buffer);
    }

  return 0;
}
开发者ID:damirboss,项目名称:canopsis-nagios,代码行数:32,代码来源:events.c

示例3: mod_insert

static int mod_insert ( char *mod, int argc, char **argv )
{
	struct mod_list_t *tail = 0;
	struct mod_list_t *head = 0; 	
	int rc = 0;
	
	// get dep list for module mod
	check_dep ( mod, &head, &tail );
	
	if ( head && tail ) {
		int i;
		int l = 0;
	
		// append module args
		l = xstrlen ( head-> m_module );
		for ( i = 0; i < argc; i++ ) 
			l += ( xstrlen ( argv [i] ) + 1 );
		
		head-> m_module = xrealloc ( head-> m_module, l + 1 );
		
		for ( i = 0; i < argc; i++ ) {
			strcat ( head-> m_module, " " );
			strcat ( head-> m_module, argv [i] );
		}

		// process tail ---> head
		rc |= mod_process ( tail, 1 );
	}
	else
		rc = 1;
	
	return rc;
}
开发者ID:zipangotes,项目名称:DSL-G624T_GPL_code,代码行数:33,代码来源:modprobe.c

示例4: main

main(int argc, string argv[])
{
    int i;
    long lstr[32], *lcop;
    stream opt, ipt;

    for (i = 0; i < 32; i++)
        lstr[i] = (i < 21 ? 12345 + 512 * i : (int) NULL);
    printf("xstrlen(lstr, %d) == %d\n",
           sizeof(long), xstrlen(lstr, sizeof(long)));
    lcop = (long *) copxstr(lstr, sizeof(long));
    printf("xstrlen(lcop, %d) == %d\n",
           sizeof(long), xstrlen(lcop, sizeof(long)));
    printf("xstreq(lstr, lcop, %d) == %d\n",
           sizeof(long), xstreq(lstr, lcop, sizeof(long)));
    printf("changing *lcop\n");
    *lcop = -1;
    printf("xstreq(lstr, lcop, %d) == %d\n",
           sizeof(long), xstreq(lstr, lcop, sizeof(long)));
    opt = stropen("foobar.dat", "w!");
    printf("putxstr(opt, lstr, %d) == %d\n",
           sizeof(long), putxstr(opt, lstr, sizeof(long)));
    printf("putxstr(opt, lcop, %d) == %d\n",
           sizeof(long), putxstr(opt, lcop, sizeof(long)));
    fclose(opt);
    ipt = stropen("foobar.dat", "r");
    lcop = (long *) getxstr(ipt, sizeof(long));
    if (lcop == NULL)
        printf("getxstr(ipt, %d) failed\n", sizeof(long));
    printf("xstreq(lstr, lcop, %d) == %d\n",
           sizeof(long), xstreq(lstr, lcop, sizeof(long)));
}
开发者ID:jasminegrosso,项目名称:zeno,代码行数:32,代码来源:extstring.c

示例5: xrealloc

char		*plv(char *msg, t_player *player)
{
  msg = xrealloc(msg, (xstrlen(msg) + 19) * sizeof(char));
  snprintf(msg + xstrlen(msg), 19, "plv %i %i\n", player->player_id,
	   player->level);
  return (msg);
}
开发者ID:Surogate,项目名称:epi-pizza,代码行数:7,代码来源:ppo_plv_pin.c

示例6: xststr

//int xstrstr(char *base,char *pattern)
int xststr()
{
int len1=xstrlen(base);
int len2=xstrlen(pattern);
if(len1<len2)
	return -1;
if(len1==0 || len2==0)
	return -1;
int index=0,i=0,j=0;
for(i=0;i<len1;i++)
{
 if(base[i]==pattern[0])
 {
 index=i;
 for(j=1;j<len2;j++)
 {
	if(base[i]!=pattern[j])
		break;
 }
 if(pattern[j]=='\0')
	return index;
 else
 {	i-=j;
	j=0;
 }
 }
 }
 return -1;
 }
开发者ID:kodingmach12,项目名称:MyCodes,代码行数:30,代码来源:strstr.c

示例7: tableSet

int tableSet(PTable t,const pchar Name,const pchar Value)
{
  PTablePage p=t->pFirst,q;
  int idx0,idx=0,res=0;
  p=tableFind(p,&idx,Name);
  if(p)
  {
    q=p;idx0=idx;
    while((p=tableFind(p,&idx,Name)))
    {
      if(t->iFlags&TABLE_FLAG_ALLOCNAME)xfree(p->Values[idx].szName);
      if(t->iFlags&TABLE_FLAG_ALLOCVALUE)xfree(p->Values[idx].szValue);
      if(idx!=p->iCount-1)memmove(&p->Values[idx],&p->Values[idx+1],sizeof(SAttr)*(p->iCount-idx-1));
      p->iCount--;
      t->iCount--;
      res++;
    }
    if(res)t->iHoles++;
    if(t->iFlags&TABLE_FLAG_ALLOCVALUE)xfree(q->Values[idx].szValue);
    if(xstrlen(q->Values[idx0].szValue)>=xstrlen(Value))
      xstrcpy(q->Values[idx0].szValue,Value);
    else
      q->Values[idx0].szValue=xstrdup(t->pPool,Value);
    return t->iCount;
  }else return tableAdd(t,Name,Value);
}
开发者ID:Maximus5,项目名称:evil-programmers,代码行数:26,代码来源:table.c

示例8: starts_with

static bool 
starts_with(const xmlChar *str, const xmlChar *prefix)
{
    size_t prefix_len = xstrlen(prefix),
           str_len = xstrlen(str);
    return str_len < prefix_len ? FALSE : 
              xstrncmp(prefix, str, prefix_len) == 0;
}
开发者ID:JATS4R,项目名称:xml.js,代码行数:8,代码来源:xpath_locator.c

示例9: add_tag

static void add_tag(ani_request_t *request)
{
    static int counter = 0;

    assert(NULL != request);
    (void)snprintf(request->tag, TAG_LEN, "tag%d", counter++);
    (void)strncat(request->msg, "&tag=", RAW_LEN - xstrlen(request->msg));
    (void)strncat(request->msg, request->tag, RAW_LEN - xstrlen(request->msg));
}
开发者ID:ameingast,项目名称:libanidb,代码行数:9,代码来源:request.c

示例10: xmlSetItemContent

void xmlSetItemContent(void *Pool,PXMLNode x,pchar Content)
{
  if(!x)return;
  if(xstrlen(x->szCont)>=xstrlen(Content))
    xstrcpy(x->szCont,Content);
  else
    x->szCont=xstrdup(Pool,Content);
  if(x->eType==xmlEmpty)x->eType=xmlLeaf;
}
开发者ID:Maximus5,项目名称:evil-programmers,代码行数:9,代码来源:xmlite.c

示例11: add_session

static void add_session(ani_request_t *request)
{
    const char *session = ani_session();

    assert(NULL != request);
    if (NULL != session && '\0' != *session)
    {
        (void)xstrncpy(request->session, session, SESSION_LEN);
        (void)strncat(request->msg, "&s=",
            RAW_LEN - xstrlen(request->msg));
        (void)strncat(request->msg, request->session,
            RAW_LEN - xstrlen(request->msg));
    }
}
开发者ID:ameingast,项目名称:libanidb,代码行数:14,代码来源:request.c

示例12: filtername

/*
 * return the full path to a filter based on a short name
 * or, if the shortname is the full path, return itself 
 */
string filtername(string shortname)
{
  int nsp;
  static char fullname[256];
  char line[MAX_LINELEN];
  string *sp, fpath;
  stream fstr;

  if (nemo_file_size(shortname) > 0) return shortname;

  fpath = getenv("NEMODAT");
  if (fpath == 0) error("NEMODAT does not exist");

  sprintf(fullname,"%s/filter/Fnames",fpath);
  dprintf(1,"Alias table %s\n",fullname);
  fstr = stropen(fullname,"r");
  while (fgets(line,MAX_LINELEN,fstr)) {
    if (line[0] == '#') continue;
    sp = burststring(line," \n");
    nsp = xstrlen(sp,sizeof(sp))-1;
    if (nsp > 1) {
      if (streq(shortname,sp[0])) {
	sprintf(fullname,"%s/filter/%s",fpath,sp[1]);
	dprintf(1,"Matching %s\n",fullname);
	freestrings(sp);
	return fullname;
      }
    }
    freestrings(sp);
  }
  return shortname;
}
开发者ID:Milkyway-at-home,项目名称:nemo,代码行数:36,代码来源:tabfilter.c

示例13: wrap_line

static int wrap_line(window_t *w, int width, char *str, fstr_attr_t *attr, int *last_space) {
	int i, j, eat, printed, len = xstrlen(str);

	if (len==0 || xmbswidth(str, len)<width || width < 1)
		return len;

	if (w->nowrap)
		return break_word(str, width);

	for (i=0, printed=0; printed <= width && i < len; printed += j, i += eat) {
		j = get_word_width(str+i, attr+i, &eat);

		if (printed + j <= width)
			continue;

		if (printed+j == width+1 && str[i+eat-1]==' ') {
			*last_space = 1;
			return i + eat - 1;
		} else if (i==0) {
			return break_word(str, width);
		} else if ((j > width) && (width-printed>8)) {
			return i + break_word(str+i, width-printed);
		}
		return i;
	}
	return len;
}
开发者ID:hiciu,项目名称:ekg2,代码行数:27,代码来源:backlog.c

示例14: break_word

static int break_word(gchar *str, int width) {
	size_t i;
	int len = xstrlen(str);
#if USE_UNICODE
	int sum = 0;

	mbtowc(NULL, NULL, 0);
	for (i = 0; i < len && sum<width; ) {
		wchar_t ch;
		int ch_len = mbtowc(&ch, &str[i], len - i);
		if (ch_len!=-1) {
			int wc_width = wcwidth(ch);

			if (wc_width == -1)
				wc_width = 1;

			if (sum + wc_width > width)
				break;
			sum += wc_width;
			i += ch_len;
		} else {
			i++;
			sum++;
		}
	}
#else
	i = (len>=width ? width : len);
#endif
	return i;
}
开发者ID:hiciu,项目名称:ekg2,代码行数:30,代码来源:backlog.c

示例15: IS_TRUE0

/*
Return VAR if there is already related to 's',
otherwise create a new VAR.
'var_name': name of the variable, it is optional.
's': string's content.
*/
VAR * VAR_MGR::register_str(CHAR const* var_name, SYM * s, UINT align)
{
	IS_TRUE0(s != NULL);
	VAR * v;
	if ((v = m_str_tab.get(s)) != NULL) {
		return v;
	}
	v = new_var();
	CHAR buf[64];
	if (var_name == NULL) {
		sprintf(buf, ".rodata_%zu", m_str_count++);
		VAR_name(v) = m_ru_mgr->add_to_symtab(buf);
	} else {
		VAR_name(v) = m_ru_mgr->add_to_symtab(var_name);
	}
	VAR_str(v) = s;
	VAR_data_type(v) = D_STR;
	VAR_elem_type(v) = D_UNDEF;
	IS_TRUE0(sizeof(CHAR) == 1);
	VAR_data_size(v) = xstrlen(SYM_name(s)) + 1;
	VAR_align(v) = align;
	VAR_is_global(v) = 1; //store in .data or .rodata

	assign_var_id(v);
	m_str_tab.set(s, v);
	return v;
}
开发者ID:Grainspring,项目名称:xoc,代码行数:33,代码来源:var.cpp


注:本文中的xstrlen函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。