• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ str类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: open_file

int
open_file (const str &nm, int flags)
{
  char *s = strdup (nm.cstr ());
  int rc = 0;

  rc = mkdir_p (s);
  if (rc == 0)
    rc = ::open (nm.cstr (), flags, 0666);

  if (s) free (s);
  return rc;
}
开发者ID:Sidnicious,项目名称:sfslite,代码行数:13,代码来源:util.C


示例2: while

str
html_filter_t::run (const str &in)
{
  if (!in) return in;

  const char *cp = in.cstr ();
  const char *ep = in.cstr () + in.len ();
  if (*ep != '\0') { return NULL; }

  buf_t buf;

  while (*cp) {
    
    str add;
    
    switch (*cp) {
    case '<':
      handle_tag (&buf, &cp, ep);
      break;
	
    case '&':
      {
	const char *inner = cp + 1;
	const char *etp = strchr (inner, ';');
	if (etp && is_safe_entity (inner, etp)) {
	  buf.add_s (str (cp, etp - cp + 1));
	  cp = etp + 1;
	} else {
	  buf.add_cc ("&amp;");
	  cp ++;
	}
      }
      break;
      
    case '#':
      buf.add_cc ("&#35;");
      cp ++;
      break;
      
    case '"':
      buf.add_cc ("&quot;");
      cp ++;
      
    default:
      buf.add_ch (*cp++);
      break;
      
    }
  }
  return buf.to_str ();
}
开发者ID:LeadsPlus,项目名称:okws,代码行数:51,代码来源:escape.C


示例3: UseActorWeapon

//
// Name:        UseActorWeapon()
// Parameters:  const str &weaponName
// Description: Sets the weapon to be active, and attaches it
//
void CombatSubsystem::UseActorWeapon(const str& weaponName, weaponhand_t hand)
{
  //First see if we just want to put our current item away
  if (!stricmp(weaponName.c_str(), "none"))
  {
    act->DeactivateWeapon(WEAPON_LEFT);
    act->DeactivateWeapon(WEAPON_RIGHT);
    act->DeactivateWeapon(WEAPON_DUAL);
    act->AddStateFlag(StateFlagChangedWeapon);
    act->ClearTorsoAnim();
    _activeWeapon.weapon = nullptr;

    return;
  }

  auto weapon = dynamic_cast<Weapon *>(act->FindItem(weaponName.c_str()));

  // Check to see if player has the weapon
  if (!weapon)
  {
    act->warning("CombatSubsystem::UseActorWeapon", "Actor does not have weapon %s", weaponName.c_str());
    return;
  }

  // If we don't already have an active weapon, just go ahead and make this one active
  if (!_activeWeapon.weapon)
  {
    _activeWeapon.weapon = weapon;
    _activeWeapon.hand = hand;
    _activeWeapon.weapon->SetOwner(act);
    act->ActivateWeapon(weapon, hand);
    act->AddStateFlag(StateFlagChangedWeapon);
    return;
  }

  // See if we are already using this weapon
  if (weapon == _activeWeapon.weapon && hand == _activeWeapon.hand)
    return;

  // Well, we have a weapon in the same hand, put away the weapon thats there.
  auto oldweapon = act->GetActiveWeapon(hand);
  if (oldweapon)
    act->DeactivateWeapon(hand);

  // Activate this weapon
  _activeWeapon.weapon = weapon;
  _activeWeapon.hand = hand;
  _activeWeapon.weapon->SetOwner(act);
  act->ActivateWeapon(weapon, hand);
  act->AddStateFlag(StateFlagChangedWeapon);
}
开发者ID:UberGames,项目名称:EF2GameSource,代码行数:56,代码来源:actor_combatsubsystem.cpp


示例4: start_logger

int
start_logger (const str &priority, const str &tag, const str &line, 
	      const str &logfile, int flags, mode_t mode)
{
  str logger;
#ifdef PATH_LOGGER
  logger = PATH_LOGGER;
#endif

  if (logger) {
    const char *av[] = { NULL, "-p", NULL, "-t", NULL, NULL, NULL };
    av[0] = const_cast<char *> (logger.cstr ());
    av[2] = const_cast<char *> (priority.cstr ());
  
    if (line)
      av[5] = const_cast<char *> (line.cstr ());
    else
      av[5] = "log started";
    
    if (tag)
      av[4] = const_cast<char *> (tag.cstr ());
    else 
      av[4] = "";
    
    pid_t pid;
    int status;
    if ((pid = spawn (av[0], av, 0, 0, errfd)) < 0) {
      warn ("%s: %m\n", logger.cstr ());
      return start_log_to_file (line, logfile, flags, mode);
    } 
    if (waitpid (pid, &status, 0) <= 0 || !WIFEXITED (status) || 
	WEXITSTATUS (status)) 
      return start_log_to_file (line, logfile, flags, mode);
    
    int fds[2];
    if (socketpair (AF_UNIX, SOCK_STREAM, 0, fds) < 0)
      fatal ("socketpair: %m\n");
    close_on_exec (fds[0]);
    if (fds[1] != 0)
      close_on_exec (fds[1]);
    
    av[5] = NULL;
    if (spawn (av[0], av, fds[1], 0, 0) >= 0) {
      close (fds[1]);
      return fds[0];
    } else {
      warn ("%s: %m\n", logger.cstr ());
    }
  } 
  return start_log_to_file (line, logfile, flags, mode);
}
开发者ID:maxtaco,项目名称:sfslite,代码行数:51,代码来源:daemonize.C


示例5: getConfigVersion

/**
 * Returns the config version of the cluster pointed at by the connection string.
 *
 * @return OK if version found successfully, error status if something bad happened.
 */
Status getConfigVersion(CatalogManager* catalogManager, VersionType* versionInfo) {
    try {
        versionInfo->clear();

        ScopedDbConnection conn(grid.shardRegistry()->getConfigServerConnectionString(), 30);

        unique_ptr<DBClientCursor> cursor(_safeCursor(conn->query("config.version", BSONObj())));

        bool hasConfigData = conn->count(ShardType::ConfigNS) ||
            conn->count(DatabaseType::ConfigNS) || conn->count(CollectionType::ConfigNS);

        if (!cursor->more()) {
            // Version is 1 if we have data, 0 if we're completely empty
            if (hasConfigData) {
                versionInfo->setMinCompatibleVersion(UpgradeHistory_UnreportedVersion);
                versionInfo->setCurrentVersion(UpgradeHistory_UnreportedVersion);
            } else {
                versionInfo->setMinCompatibleVersion(UpgradeHistory_EmptyVersion);
                versionInfo->setCurrentVersion(UpgradeHistory_EmptyVersion);
            }

            conn.done();
            return Status::OK();
        }

        BSONObj versionDoc = cursor->next();
        auto versionInfoResult = VersionType::fromBSON(versionDoc);
        if (!versionInfoResult.isOK()) {
            conn.done();

            return Status(ErrorCodes::UnsupportedFormat,
                          stream() << "invalid config version document " << versionDoc
                                   << versionInfoResult.getStatus().toString());
        }
        *versionInfo = versionInfoResult.getValue();

        if (cursor->more()) {
            conn.done();

            return Status(ErrorCodes::RemoteValidationError,
                          stream() << "should only have 1 document "
                                   << "in config.version collection");
        }
        conn.done();
    } catch (const DBException& e) {
        return e.toStatus();
    }

    return Status::OK();
}
开发者ID:Jonekee,项目名称:mongo,代码行数:55,代码来源:config_upgrade.cpp


示例6: fail

void
dhash_download::add_data (str sdata, int off)
{
    int len = sdata.len ();
    const char *data = sdata.cstr ();

    if ((unsigned)(off + len) > (u_int)buf_len)
        fail (strbuf ("bad chunk: off %d, len %d, block %ld",
                      off, len, buf_len));
    else {
        memcpy (buffer + off, data, len);
        bytes_read += len;
    }
}
开发者ID:vgslavov,项目名称:XGossip,代码行数:14,代码来源:download.C


示例7: dfs

void dfs(str& s, int u) {
   vis[u] = true;
   for (auto child: v[u]) if (!vis[child]) {
      str* cs = new(str);
      dfs(*cs, child);
      merge(s, *cs);
      delete(cs);
   }
   s.insert(c[u], 1);
   for (auto query: q[u]) {
      int pos = query.second, k = query.first;
      result[pos] = s.query(k);
   }
}
开发者ID:RobertRosolek,项目名称:programming_contests,代码行数:14,代码来源:D.cpp


示例8: load_lines

      std::vector<str> load_lines(const str& s)
        {
          std::vector<str> result;
          size_t curr = 0;
          for(size_t i = 0; i < s.length(); i++)
            {
              if (s[i] == '\n')
                {
                  result.push_back( s.substr(curr, i) );
                  curr = i;
                }
            }

          return result;
        }
开发者ID:xkp,项目名称:XKP,代码行数:15,代码来源:dsl_out.cpp


示例9: makehdrname

static str
makehdrname (str fname)
{
  strbuf hdr;
  const char *p;

  if ((p = strrchr (fname.cstr(), '/')))
    p++;
  else p = fname.cstr();

  hdr.buf (p, strlen (p) - 1);
  hdr.cat ("h");

  return hdr;
}
开发者ID:okws,项目名称:sfslite,代码行数:15,代码来源:gencfile.C


示例10: extract_delimited_text

str::size_type extract_delimited_text(const str& in, const str& d1, const str& d2, str& out, size_t pos)
{
	if(pos == str::npos)
		return pos;

	size_t end = pos;

	if((pos = in.find(d1, pos)) != str::npos)
		if((end = in.find(d2, (pos = pos + d1.size()))) != str::npos)
		{
			out = in.substr(pos, end - pos);
			return end + d2.size();
		}
	return str::npos;
}
开发者ID:sookee,项目名称:rconteam,代码行数:15,代码来源:str.cpp


示例11: Init

bool TFxSprite::Init(str particleSystem, TFxSpriteAnimTask * task, bool reset )
{
	TFxSpriteRef s = GetRef();

	if (reset)
	{
		mDrawnOnce = false;
		s->GetLPS()->NewScript();
	}

	if (particleSystem.has_data())
	{
		s->GetLPS()->RegisterDataSource("dLocus",&s->mEmitterLocus);
		s->GetLPS()->RegisterDataSource("dUp",&s->mEmitterUp);

		if( !s->GetLPS()->Load(particleSystem) )
		{
			return false;
		}
		s->mName = particleSystem ;
		if (!task)
		{
			task = ((TFxSpriteAnimTask*)GetAnimTask());
		}
		task->mSpriteList.insert( s );
	}
	return true;
}
开发者ID:janvanderkamp,项目名称:balloon_storm,代码行数:28,代码来源:fxsprite.cpp


示例12: NamespaceString

Status CatalogManagerReplicaSet::getChunks(const Query& query,
                                           int nToReturn,
                                           vector<ChunkType>* chunks) {
    chunks->clear();

    auto configShard = grid.shardRegistry()->getShard("config");
    auto readHostStatus = configShard->getTargeter()->findHost(kConfigReadSelector);
    if (!readHostStatus.isOK()) {
        return readHostStatus.getStatus();
    }

    auto findStatus = grid.shardRegistry()->exhaustiveFind(readHostStatus.getValue(),
                                                           NamespaceString(ChunkType::ConfigNS),
                                                           query.obj,
                                                           boost::none);  // no limit
    if (!findStatus.isOK()) {
        return findStatus.getStatus();
    }

    for (const BSONObj& obj : findStatus.getValue()) {
        auto chunkRes = ChunkType::fromBSON(obj);
        if (!chunkRes.isOK()) {
            chunks->clear();
            return {ErrorCodes::FailedToParse,
                    stream() << "Failed to parse chunk with id ("
                             << obj[ChunkType::name()].toString()
                             << "): " << chunkRes.getStatus().toString()};
        }

        chunks->push_back(chunkRes.getValue());
    }

    return Status::OK();
}
开发者ID:lebronhkh,项目名称:mongo,代码行数:34,代码来源:catalog_manager_replica_set.cpp


示例13: split

int
split (vec<str> *out, rxx pat, str expr, size_t lim, bool emptylast)
{
  const char *p = expr;
  const char *const e = p + expr.len ();
  size_t n;
  if (out)
    out->clear ();

  // check p < e to see that we're not dealing with an empty
  // string (especially since x? matches "").
  for (n = 0; p < e && n + 1 < lim; n++) {
    if (!pat._exec (p, e - p, 0)) {
      return 0;
    }
    if (!pat.success ())
      break;
    if (out)
      out->push_back (str (p, pat.start (0)));
    p += max (pat.end (0), 1);
  }

  if (lim && (p < e || emptylast)) {
    n++;
    if (out) {
      out->push_back (str (p, e - p));
    }
  }
  return n;
}
开发者ID:gildafnai82,项目名称:craq,代码行数:30,代码来源:rxx.C


示例14: isNumeric

bool isNumeric(const str& token)
{
    if(token == "")
        return false;

    for(uint i=0; i<token.length(); i++)
    {
        const char num = token.at(i);
        if(i == 0 && Util::toString(num) == kSubtract() && token.size() > 1) //token.size > 1 because "-" is not a number
            continue;
        if(isdigit(num) == false && Util::toString(num) != kDot())
            return false;
    }

    return true;
}
开发者ID:vis15,项目名称:fractions,代码行数:16,代码来源:util.cpp


示例15: TiXmlElement

Writer xml_writer::create_node(const str& name)
  {
    TiXmlElement* node = new TiXmlElement(name.c_str());
    node_->LinkEndChild( node );
    
    return Writer( new xml_writer(node, types_) );
  }
开发者ID:gcubar,项目名称:XKP,代码行数:7,代码来源:xml_archive.cpp


示例16:

 void
 dumpable_t::s_dump (dumper_t *d, str prfx, const dumpable_t *obj)
 {
   if (prfx) { d->dump (strbuf ("%s ", prfx.cstr ()), false); }
   if (obj) { obj->dump (d); }
   else { d->dump ("(null)", true); }
 }
开发者ID:aosmith,项目名称:okws,代码行数:7,代码来源:pub3debug.C


示例17: escape

 str escape(str t)
 {
     //обработка escape последовательностей в строке
    str  res="";
    t=t+" ";
         for(int i=1;i<=t.Length()-1;i++)
                  if(t[i]=='\\' && t[i+1]=='\\')
                          res=res+t[i++] ;
                  else
                  if(t[i]=='\\' && t[i+1]=='n')
                  {
                          res=res+'\n';
                          i++;
                  }
                  else
                   if(t[i]=='\\' && t[i+1]=='s')
                  {
                          res=res+' ';
                          i++;
                  }
                  else
                  if(t[i]=='\\')
                          res=res+t[++i];
                  else
                          res=res+t[i];

        return res;
 }
开发者ID:alhimik45,项目名称:diplom-nadip,代码行数:28,代码来源:interpreter.cpp


示例18: pathexpand

static str
pathexpand (str lookup, str *sch, int recdepth = 0)
{
  char readlinkbuf [PATH_MAX + 1];
  str s;

  struct stat sb;
  while (1) {
//     warn << print_indent (recdepth) << "looking up " << lookup << "\n";

    stat (lookup.cstr (), &sb);
    
    errno = 0;
    if ((s = slashsfs2sch (lookup))) {
//       warn << print_indent (recdepth) << "--------FOUND-----: " 
// 	   << s << "\n";
      *sch = s;
      return lookup;
    }
    else {
      int len = readlink (lookup, readlinkbuf, PATH_MAX);
      if (len < 0) {
// 	warn << print_indent (recdepth) << "readlink of " 
// 	     << lookup << " returned error: " << strerror (errno) << "\n";
	return lookup;
      }
      readlinkbuf[len] = 0;
//       warn << print_indent (recdepth) << "readlink of " << lookup 
// 	   << " returned " << readlinkbuf << "\n";
      lookup = mk_readlinkres_abs (readlinkbuf, lookup);
    }
  }
}
开发者ID:gildafnai82,项目名称:craq,代码行数:33,代码来源:pathexpand.C


示例19: path2sch

//for looking up self-certifying hostnames in certprog interface
int
path2sch (str path, str *sch)
{
  *sch = NULL;

  if (!path || !path.len ())
    return ENOENT;
  
  if (sfs_parsepath (path)) {
    *sch = path;
    return 0;
  }

  str lookup;
  if (path[0] == '/')
    lookup = path;
  else
    lookup = strbuf () << sfsroot << "/" << path;

  str result = pathiterate (lookup, sch, 0, true);
  //  warn << "RESULT: " << result << "\n";

  if (errno == EINVAL)
    errno = 0;
//   if (*sch)
//     warn << "RETURNING: " << *sch << "\n";
//   warn << "RETURNING ERROR CODE: " << strerror (errno) << "\n";
  return errno;
}
开发者ID:gildafnai82,项目名称:craq,代码行数:30,代码来源:pathexpand.C


示例20: BSON

StatusWith<string> CatalogManagerReplicaSet::getTagForChunk(const std::string& collectionNs,
                                                            const ChunkType& chunk) {
    auto configShard = grid.shardRegistry()->getShard("config");
    auto readHostStatus = configShard->getTargeter()->findHost(kConfigReadSelector);
    if (!readHostStatus.isOK()) {
        return readHostStatus.getStatus();
    }

    BSONObj query =
        BSON(TagsType::ns(collectionNs) << TagsType::min() << BSON("$lte" << chunk.getMin())
                                        << TagsType::max() << BSON("$gte" << chunk.getMax()));
    auto findStatus = grid.shardRegistry()->exhaustiveFind(
        readHostStatus.getValue(), NamespaceString(TagsType::ConfigNS), query, BSONObj(), 1);
    if (!findStatus.isOK()) {
        return findStatus.getStatus();
    }

    const auto& docs = findStatus.getValue();
    if (docs.empty()) {
        return string{};
    }

    invariant(docs.size() == 1);
    BSONObj tagsDoc = docs.front();

    const auto tagsResult = TagsType::fromBSON(tagsDoc);
    if (!tagsResult.isOK()) {
        return {ErrorCodes::FailedToParse,
                stream() << "error while parsing " << TagsType::ConfigNS << " document: " << tagsDoc
                         << " : " << tagsResult.getStatus().toString()};
    }
    return tagsResult.getValue().getTag();
}
开发者ID:rickyzyj,项目名称:mongo,代码行数:33,代码来源:catalog_manager_replica_set.cpp



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ strArray类代码示例发布时间:2022-05-31
下一篇:
C++ storage_type类代码示例发布时间:2022-05-31
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap