本文整理汇总了C++中str类的典型用法代码示例。如果您正苦于以下问题:C++ str类的具体用法?C++ str怎么用?C++ str使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了str类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例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 ("&");
cp ++;
}
}
break;
case '#':
buf.add_cc ("#");
cp ++;
break;
case '"':
buf.add_cc (""");
cp ++;
default:
buf.add_ch (*cp++);
break;
}
}
return buf.to_str ();
}
示例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);
}
示例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);
}
示例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();
}
示例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;
}
}
示例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);
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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();
}
示例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;
}
示例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;
}
示例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_) );
}