本文整理汇总了C++中std::string::find方法的典型用法代码示例。如果您正苦于以下问题:C++ string::find方法的具体用法?C++ string::find怎么用?C++ string::find使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::string
的用法示例。
在下文中一共展示了string::find方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CheckGLSL
static bool CheckGLSL (bool vertex, bool gles, const std::string& testName, const char* prefix, const std::string& source)
{
#if !GOT_GFX
return true; // just assume it's ok
#else
#if !GOT_MORE_THAN_GLSL_120
if (source.find("#version 140") != std::string::npos)
return true;
#endif
const bool need3 =
(source.find("#version 150") != std::string::npos) ||
(source.find("#version 300") != std::string::npos);
# ifdef __APPLE__
// Mac core context does not accept any older shader versions, so need to switch to
// either legacy context or core one.
if (need3)
{
if (!s_GL3Active)
CGLSetCurrentContext(s_GLContext3);
s_GL3Active = true;
}
else
{
if (s_GL3Active)
CGLSetCurrentContext(s_GLContext);
s_GL3Active = false;
}
# endif // ifdef __APPLE__
std::string src;
if (gles)
{
src += "#define lowp\n";
src += "#define mediump\n";
src += "#define highp\n";
src += "#define texture2DLodEXT texture2DLod\n";
src += "#define texture2DProjLodEXT texture2DProjLod\n";
src += "#define texture2DGradEXT texture2DGradARB\n";
src += "#define textureCubeGradEXT textureCubeGradARB\n";
src += "#define gl_FragDepthEXT gl_FragDepth\n";
if (!need3)
{
src += "#define gl_LastFragData _glesLastFragData\n";
src += "varying lowp vec4 _glesLastFragData[4];\n";
}
if (!need3)
{
src += "float shadow2DEXT (sampler2DShadow s, vec3 p) { return shadow2D(s,p).r; }\n";
src += "float shadow2DProjEXT (sampler2DShadow s, vec4 p) { return shadow2DProj(s,p).r; }\n";
}
}
src += source;
if (gles)
{
replace_string (src, "GL_EXT_shader_texture_lod", "GL_ARB_shader_texture_lod", 0);
replace_string (src, "GL_EXT_draw_instanced", "GL_ARB_draw_instanced", 0);
replace_string (src, "gl_InstanceIDEXT", "gl_InstanceIDARB ", 0);
replace_string (src, "#extension GL_OES_standard_derivatives : require", "", 0);
replace_string (src, "#extension GL_EXT_shadow_samplers : require", "", 0);
replace_string (src, "#extension GL_EXT_frag_depth : require", "", 0);
replace_string (src, "#extension GL_OES_standard_derivatives : enable", "", 0);
replace_string (src, "#extension GL_EXT_shadow_samplers : enable", "", 0);
replace_string (src, "#extension GL_EXT_frag_depth : enable", "", 0);
replace_string (src, "#extension GL_EXT_draw_buffers : enable", "", 0);
replace_string (src, "#extension GL_EXT_draw_buffers : require", "", 0);
replace_string (src, "precision ", "// precision ", 0);
replace_string (src, "#version 300 es", "", 0);
}
// can't check FB fetch on PC
if (src.find("#extension GL_EXT_shader_framebuffer_fetch") != std::string::npos)
return true;
if (gles && need3)
{
src = "#version 330\n" + src;
}
const char* sourcePtr = src.c_str();
GLuint shader = glCreateShader (vertex ? GL_VERTEX_SHADER : GL_FRAGMENT_SHADER);
glShaderSource (shader, 1, &sourcePtr, NULL);
glCompileShader (shader);
GLint status;
glGetShaderiv (shader, GL_COMPILE_STATUS, &status);
bool res = true;
if (status != GL_TRUE)
{
char log[20000];
log[0] = 0;
GLsizei logLength;
glGetShaderInfoLog (shader, sizeof(log), &logLength, log);
printf ("\n %s: real glsl compiler error on %s:\n%s\n", testName.c_str(), prefix, log);
res = false;
}
//.........这里部分代码省略.........
示例2: process_impl
// virtual
LLIOPipe::EStatus LLHTTPResponder::process_impl(
const LLChannelDescriptors& channels,
buffer_ptr_t& buffer,
bool& eos,
LLSD& context,
LLPumpIO* pump)
{
PUMP_DEBUG;
LLMemType m1(LLMemType::MTYPE_IO_HTTP_SERVER);
LLIOPipe::EStatus status = STATUS_OK;
// parsing headers
if((STATE_NOTHING == mState) || (STATE_READING_HEADERS == mState))
{
PUMP_DEBUG;
status = STATUS_BREAK;
mState = STATE_READING_HEADERS;
const S32 HEADER_BUFFER_SIZE = 1024;
char buf[HEADER_BUFFER_SIZE + 1]; /*Flawfinder: ignore*/
S32 len = HEADER_BUFFER_SIZE;
#if 0
if(true)
{
LLBufferArray::segment_iterator_t seg_iter = buffer->beginSegment();
char buf[1024]; /*Flawfinder: ignore*/
while(seg_iter != buffer->endSegment())
{
memcpy(buf, (*seg_iter).data(), (*seg_iter).size()); /*Flawfinder: ignore*/
buf[(*seg_iter).size()] = '\0';
llinfos << (*seg_iter).getChannel() << ": " << buf
<< llendl;
++seg_iter;
}
}
#endif
PUMP_DEBUG;
if(readLine(channels, buffer, (U8*)buf, len))
{
bool read_next_line = false;
bool parse_all = true;
if(mVerb.empty())
{
read_next_line = true;
LLMemoryStream header((U8*)buf, len);
header >> mVerb;
if((HTTP_VERB_GET == mVerb)
|| (HTTP_VERB_POST == mVerb)
|| (HTTP_VERB_PUT == mVerb)
|| (HTTP_VERB_DELETE == mVerb)
|| (HTTP_VERB_OPTIONS == mVerb))
{
header >> mAbsPathAndQuery;
header >> mVersion;
lldebugs << "http request: "
<< mVerb
<< " " << mAbsPathAndQuery
<< " " << mVersion << llendl;
std::string::size_type delimiter
= mAbsPathAndQuery.find('?');
if (delimiter == std::string::npos)
{
mPath = mAbsPathAndQuery;
mQuery = "";
}
else
{
mPath = mAbsPathAndQuery.substr(0, delimiter);
mQuery = mAbsPathAndQuery.substr(delimiter+1);
}
if(!mAbsPathAndQuery.empty())
{
if(mVersion.empty())
{
// simple request.
parse_all = false;
mState = STATE_DONE;
mVersion.assign("HTTP/1.0");
}
}
}
示例3: handle
virtual void handle( OperationContext* txn,
const char *rq, const std::string& url, BSONObj params,
string& responseMsg, int& responseCode,
vector<string>& headers, const SockAddr &from ) {
string::size_type first = url.find( "/" , 1 );
if ( first == string::npos ) {
responseCode = 400;
return;
}
string method = MiniWebServer::parseMethod( rq );
string dbname = url.substr( 1 , first - 1 );
string coll = url.substr( first + 1 );
string action = "";
string::size_type last = coll.find_last_of( "/" );
if ( last == string::npos ) {
action = coll;
coll = "_defaultCollection";
}
else {
action = coll.substr( last + 1 );
coll = coll.substr( 0 , last );
}
for ( string::size_type i=0; i<coll.size(); i++ )
if ( coll[i] == '/' )
coll[i] = '.';
string fullns = MiniWebServer::urlDecode(dbname + "." + coll);
headers.push_back( (string)"x-action: " + action );
headers.push_back( (string)"x-ns: " + fullns );
bool html = false;
stringstream ss;
if ( method == "GET" ) {
responseCode = 200;
html = handleRESTQuery( fullns , action , params , responseCode , ss );
}
else if ( method == "POST" ) {
responseCode = 201;
handlePost( fullns , MiniWebServer::body( rq ) , params , responseCode , ss );
}
else {
responseCode = 400;
headers.push_back( "X_err: bad request" );
ss << "don't know how to handle a [" << method << "]";
log() << "don't know how to handle a [" << method << "]" << endl;
}
if( html )
headers.push_back("Content-Type: text/html;charset=utf-8");
else
headers.push_back("Content-Type: text/plain;charset=utf-8");
responseMsg = ss.str();
}
示例4: xml_compiler_runtime_error
void
xml_compiler::remapclasses_initialize_vector_loader::handle_autogen(const std::string& autogen,
const std::string& raw_autogen)
{
// ------------------------------------------------------------
// preprocess
//
// MODIFIERFLAG_EITHER_LEFT_OR_RIGHT_*
{
static const struct {
const std::string name;
const std::string flags[2];
} info[] = {
{ "MODIFIERFLAG_EITHER_LEFT_OR_RIGHT_COMMAND", { "ModifierFlag::COMMAND_L", "ModifierFlag::COMMAND_R" } },
{ "MODIFIERFLAG_EITHER_LEFT_OR_RIGHT_CONTROL", { "ModifierFlag::CONTROL_L", "ModifierFlag::CONTROL_R" } },
{ "MODIFIERFLAG_EITHER_LEFT_OR_RIGHT_SHIFT", { "ModifierFlag::SHIFT_L", "ModifierFlag::SHIFT_R" } },
{ "MODIFIERFLAG_EITHER_LEFT_OR_RIGHT_OPTION", { "ModifierFlag::OPTION_L", "ModifierFlag::OPTION_R" } },
// for backwards compatibility
{ "VK_COMMAND", { "ModifierFlag::COMMAND_L", "ModifierFlag::COMMAND_R" } },
{ "VK_CONTROL", { "ModifierFlag::CONTROL_L", "ModifierFlag::CONTROL_R" } },
{ "VK_SHIFT", { "ModifierFlag::SHIFT_L", "ModifierFlag::SHIFT_R" } },
{ "VK_OPTION", { "ModifierFlag::OPTION_L", "ModifierFlag::OPTION_R" } },
};
for (const auto& it : info) {
if (autogen.find(it.name) != std::string::npos) {
for (const auto& f : it.flags) {
handle_autogen(boost::replace_all_copy(autogen, it.name, f),
raw_autogen);
}
return;
}
}
}
// MODIFIERFLAGS_*
{
static const struct {
const std::string name;
const std::string flag;
} info[] = {
{ "MODIFIERFLAGS_CCOS_L",
"ModifierFlag::COMMAND_L|ModifierFlag::CONTROL_L|ModifierFlag::OPTION_L|ModifierFlag::SHIFT_L" },
{ "MODIFIERFLAGS_CCS_L",
"ModifierFlag::COMMAND_L|ModifierFlag::CONTROL_L|ModifierFlag::SHIFT_L" },
{ "MODIFIERFLAGS_CCO_L",
"ModifierFlag::COMMAND_L|ModifierFlag::CONTROL_L|ModifierFlag::OPTION_L" },
// for backwards compatibility
{ "VK_MOD_CCOS_L", "ModifierFlag::COMMAND_L|ModifierFlag::CONTROL_L|ModifierFlag::OPTION_L|ModifierFlag::SHIFT_L" },
{ "VK_MOD_CCS_L", "ModifierFlag::COMMAND_L|ModifierFlag::CONTROL_L|ModifierFlag::SHIFT_L" },
{ "VK_MOD_CCO_L", "ModifierFlag::COMMAND_L|ModifierFlag::CONTROL_L|ModifierFlag::OPTION_L" },
};
for (const auto& it : info) {
if (autogen.find(it.name) != std::string::npos) {
handle_autogen(boost::replace_all_copy(autogen, it.name, it.flag),
raw_autogen);
return;
}
}
}
// MODIFIERFLAGS_ANY
{
static const struct {
const std::string name;
} info[] = {
"MODIFIERFLAGS_ANY",
// for backwards compatibility
"VK_MOD_ANY",
};
for (const auto& it : info) {
if (autogen.find(it.name) != std::string::npos) {
// Making combination at the first time. (reuse it since 2nd time.)
static std::vector<std::shared_ptr<std::vector<std::string> > > combination;
if (combination.empty()) {
// to reduce combination, we ignore same modifier combination such as (COMMAND_L | COMMAND_R).
const char* seeds[] = { "MODIFIERFLAG_EITHER_LEFT_OR_RIGHT_COMMAND",
"MODIFIERFLAG_EITHER_LEFT_OR_RIGHT_CONTROL",
"ModifierFlag::FN",
"MODIFIERFLAG_EITHER_LEFT_OR_RIGHT_OPTION",
"MODIFIERFLAG_EITHER_LEFT_OR_RIGHT_SHIFT" };
pqrs::vector::make_combination(combination, seeds, sizeof(seeds) / sizeof(seeds[0]));
}
for (const auto& v : combination) {
handle_autogen(boost::replace_all_copy(autogen, it.name, boost::join(*v, "|") + "|ModifierFlag::NONE"),
raw_autogen);
}
return;
}
}
}
// FROMKEYCODE_HOME, FROMKEYCODE_END, ...
{
struct preprocess_info {
//.........这里部分代码省略.........
示例5:
bool ZLXMLReader::BrokenNamePredicate::accepts(const ZLXMLReader &reader, const std::string &name) const {
return myName == name.substr(name.find(':') + 1);
}
示例6:
bool Helper4::isType(const std::string& type, const std::string& entity_types)const
{
return (std::string::npos != entity_types.find(type));
}
示例7: input
double task4_6::solution::calculate_rpn( const std::string& rpn_expression )
{
std::stack< double > calc_stack;
std::istringstream input( rpn_expression );
std::string token;
vars_map::iterator it;
while( input >> token )
{
if( token.length() == 1 && operators.find( token[0] ) != token.npos )
{
// token is operator
double r = 0;
if( calc_stack.empty() )
{
throw std::logic_error( "not correct expression at %1% line" );
}
double y = calc_stack.top();
calc_stack.pop();
if( calc_stack.empty() )
{
throw std::logic_error( "not correct expression at %1% line" );
}
double x = calc_stack.top();
calc_stack.pop();
switch ( token[0] )
{
case '+': r = x + y; break;
case '-': r = x - y; break;
case '*': r = x * y; break;
case '/': r = x / y;
if ( y == 0 )
{
throw std::logic_error( "zero div (%1%)" );
}
break;
default:
throw std::logic_error( "not correct expression at %1% line" );
}
calc_stack.push( r );
}
else if( ( it = vars_.find( token ) ) != vars_.end() )
{
// token is var
calc_stack.push( it->second );
}
else
{
// maybe token is number
try
{
calc_stack.push( boost::lexical_cast<double>( token ) );
}
catch ( const boost::bad_lexical_cast& )
{
throw std::logic_error(
( boost::format( "'%1%' variable not defined at line %2%" )
% token % "%1%" ).str() );
}
}
}
if( calc_stack.empty() )
{
throw std::logic_error( "not correct expression at %1% line" );
}
return calc_stack.top();
}
示例8: openHttpConnection
int eServiceWebTS::openHttpConnection(std::string url)
{
std::string host;
int port = 80;
std::string uri;
int slash = url.find("/", 7);
if (slash > 0) {
host = url.substr(7, slash-7);
uri = url.substr(slash, url.length()-slash);
} else {
host = url.substr(7, url.length()-7);
uri = "";
}
int dp = host.find(":");
if (dp == 0) {
port = atoi(host.substr(1, host.length()-1).c_str());
host = "localhost";
} else if (dp > 0) {
port = atoi(host.substr(dp+1, host.length()-dp-1).c_str());
host = host.substr(0, dp);
}
struct hostent* h = gethostbyname(host.c_str());
if (h == NULL || h->h_addr_list == NULL)
return -1;
int fd = socket(PF_INET, SOCK_STREAM, 0);
if (fd == -1)
return -1;
struct sockaddr_in addr;
addr.sin_family = AF_INET;
addr.sin_addr.s_addr = *((in_addr_t*)h->h_addr_list[0]);
addr.sin_port = htons(port);
eDebug("connecting to %s", url.c_str());
if (connect(fd, (sockaddr*)&addr, sizeof(addr)) == -1) {
std::string msg = "connect failed for: " + url;
eDebug(msg.c_str());
return -1;
}
std::string request = "GET ";
request.append(uri).append(" HTTP/1.1\r\n");
request.append("Host: ").append(host).append("\r\n");
request.append("Accept: */*\r\n");
request.append("Connection: close\r\n");
request.append("\r\n");
//eDebug(request.c_str());
write(fd, request.c_str(), request.length());
int rc;
size_t buflen = 1000;
char* linebuf = (char*)malloc(1000);
rc = getline(&linebuf, &buflen, fd);
//eDebug("RECV(%d): %s", rc, linebuf);
if (rc <= 0)
{
close(fd);
free(linebuf);
return -1;
}
char proto[100];
int statuscode = 0;
char statusmsg[100];
rc = sscanf(linebuf, "%99s %d %99s", proto, &statuscode, statusmsg);
if (rc != 3 || statuscode != 200) {
eDebug("wrong response: \"200 OK\" expected.\n %d --- %d",rc,statuscode);
free(linebuf);
close(fd);
return -1;
}
eDebug("proto=%s, code=%d, msg=%s", proto, statuscode, statusmsg);
while (rc > 0)
{
rc = getline(&linebuf, &buflen, fd);
//eDebug("RECV(%d): %s", rc, linebuf);
}
free(linebuf);
return fd;
}
示例9: buildShaderInfo
bool ShaderInfoHelper::buildShaderInfo(const ImagineRendererInfo& iri, FnKat::GroupBuilder& rendererObjectInfo, const std::string& name,
const FnKat::GroupAttribute inputAttr)
{
std::vector<std::string> typeTags;
std::string location = name;
std::string fullPath;
FnKat::Attribute containerHintsAttribute;
typeTags.push_back("surface");
typeTags.push_back("op");
typeTags.push_back("texture");
typeTags.push_back("bump");
typeTags.push_back("medium");
typeTags.push_back("displacement");
typeTags.push_back("alpha");
typeTags.push_back("light");
Foundry::Katana::RendererInfo::RendererInfoBase::configureBasicRenderObjectInfo(rendererObjectInfo, kFnRendererObjectTypeShader,
typeTags, location, fullPath,
kFnRendererObjectValueTypeUnknown, containerHintsAttribute);
std::string buildName;
std::string typeName; // for network materials
if (name.find("/") == std::string::npos)
{
// just a single standard material
buildName = name;
}
else
{
// ImagineShadingNode item, so split out the two items from the name
size_t sepPos = name.find("/");
typeName = name.substr(0, sepPos);
buildName = name.substr(sepPos + 1);
}
if (buildName == "Standard")
{
buildStandardShaderParams(iri, rendererObjectInfo);
}
else if (buildName == "StandardImage")
{
buildStandardImageShaderParams(iri, rendererObjectInfo);
}
else if (buildName == "Glass")
{
buildGlassShaderParams(iri, rendererObjectInfo);
}
else if (buildName == "Metal")
{
buildMetalShaderParams(iri, rendererObjectInfo);
}
else if (buildName == "Plastic")
{
buildPlasticShaderParams(iri, rendererObjectInfo);
}
else if (buildName == "Brushed Metal")
{
buildBrushedMetalShaderParams(iri, rendererObjectInfo);
}
else if (buildName == "Metallic Paint")
{
buildMetallicPaintShaderParams(iri, rendererObjectInfo);
}
else if (buildName == "Translucent")
{
buildTranslucentShaderParams(iri, rendererObjectInfo);
}
else if (buildName == "Velvet")
{
buildVelvetShaderParams(iri, rendererObjectInfo);
}
else if (buildName == "Luminous")
{
buildLuminousShaderParams(iri, rendererObjectInfo);
}
// lights
else if (buildName == "Point")
{
buildPointLightShaderParams(iri, rendererObjectInfo);
}
else if (buildName == "Spot")
{
buildSpotLightShaderParams(iri, rendererObjectInfo);
}
else if (buildName == "Area")
{
buildAreaLightShaderParams(iri, rendererObjectInfo);
}
else if (buildName == "Distant")
{
buildDistantLightShaderParams(iri, rendererObjectInfo);
}
else if (buildName == "SkyDome")
{
buildSkydomeLightShaderParams(iri, rendererObjectInfo);
}
else if (buildName == "Environment")
{
//.........这里部分代码省略.........
示例10:
std::string
strip( const std::string & func )
{
size_t pos = func.find( "test" );
return func.substr( pos, func.length() - pos - 2 );
}
示例11: GetTerm
std::string GetTerm(std::string l)
{
size_t found=l.find("=");
if(found==string::npos) return l;
else return l.substr(0, found);
}
示例12: getIncomingVars
static void getIncomingVars(
std::unordered_multimap<std::string, std::string> ¶ms,
const std::string &uri
) {
const size_t start = uri.find('?');
if (std::string::npos == start) {
return;
}
const size_t finish = uri.find('#');
if (finish < start) {
return;
}
for (
size_t var_pos = start + 1, var_end = 0;
std::string::npos != var_end;
var_pos = var_end + 1
) {
var_end = uri.find('&', var_pos);
if (var_end > finish) {
var_end = std::string::npos;
}
size_t delimiter = uri.find('=', var_pos);
if (delimiter >= var_end) {
std::string var_name = Utils::urlDecode(
uri.substr(
var_pos,
std::string::npos != var_end
? var_end - var_pos
: std::string::npos
)
);
params.emplace(
std::move(var_name),
std::string()
);
} else {
std::string var_name = Utils::urlDecode(
uri.substr(
var_pos,
delimiter - var_pos
)
);
++delimiter;
std::string var_value = Utils::urlDecode(
uri.substr(
delimiter,
std::string::npos != var_end
? var_end - delimiter
: std::string::npos
)
);
params.emplace(
std::move(var_name),
std::move(var_value)
);
}
}
}
示例13: populateFolder
void SystemData::populateFolder(FileData* folder)
{
const fs::path& folderPath = folder->getPath();
if(!fs::is_directory(folderPath))
{
LOG(LogWarning) << "Error - folder with path \"" << folderPath << "\" is not a directory!";
return;
}
const std::string folderStr = folderPath.generic_string();
//make sure that this isn't a symlink to a thing we already have
if(fs::is_symlink(folderPath))
{
//if this symlink resolves to somewhere that's at the beginning of our path, it's gonna recurse
if(folderStr.find(fs::canonical(folderPath).generic_string()) == 0)
{
LOG(LogWarning) << "Skipping infinitely recursive symlink \"" << folderPath << "\"";
return;
}
}
fs::path filePath;
std::string extension;
bool isGame;
for(fs::directory_iterator end, dir(folderPath); dir != end; ++dir)
{
filePath = (*dir).path();
if(filePath.stem().empty())
continue;
//this is a little complicated because we allow a list of extensions to be defined (delimited with a space)
//we first get the extension of the file itself:
extension = filePath.extension().string();
//fyi, folders *can* also match the extension and be added as games - this is mostly just to support higan
//see issue #75: https://github.com/Aloshi/EmulationStation/issues/75
isGame = false;
if(std::find(mSearchExtensions.begin(), mSearchExtensions.end(), extension) != mSearchExtensions.end())
{
FileData* newGame = new FileData(GAME, filePath.generic_string(), this);
folder->addChild(newGame);
isGame = true;
}
//add directories that also do not match an extension as folders
if(!isGame && fs::is_directory(filePath))
{
FileData* newFolder = new FileData(FOLDER, filePath.generic_string(), this);
populateFolder(newFolder);
//ignore folders that do not contain games
if(newFolder->getChildren().size() == 0)
delete newFolder;
else
folder->addChild(newFolder);
}
}
}
示例14: Status
Status MMAPV1Engine::repairDatabase( OperationContext* txn,
const std::string& dbName,
bool preserveClonedFilesOnFailure,
bool backupOriginalFiles ) {
// We must hold some form of lock here
invariant(txn->lockState()->threadState());
invariant( dbName.find( '.' ) == string::npos );
scoped_ptr<RepairFileDeleter> repairFileDeleter;
doingRepair dr;
log() << "repairDatabase " << dbName << endl;
BackgroundOperation::assertNoBgOpInProgForDb(dbName);
txn->recoveryUnit()->syncDataAndTruncateJournal(); // Must be done before and after repair
intmax_t totalSize = dbSize( dbName );
intmax_t freeSize = File::freeSpace(storageGlobalParams.repairpath);
if ( freeSize > -1 && freeSize < totalSize ) {
return Status( ErrorCodes::OutOfDiskSpace,
str::stream() << "Cannot repair database " << dbName
<< " having size: " << totalSize
<< " (bytes) because free disk space is: " << freeSize << " (bytes)" );
}
txn->checkForInterrupt();
Path reservedPath =
uniqueReservedPath( ( preserveClonedFilesOnFailure || backupOriginalFiles ) ?
"backup" : "_tmp" );
MONGO_ASSERT_ON_EXCEPTION( boost::filesystem::create_directory( reservedPath ) );
string reservedPathString = reservedPath.string();
if ( !preserveClonedFilesOnFailure )
repairFileDeleter.reset( new RepairFileDeleter( txn,
dbName,
reservedPathString,
reservedPath ) );
{
Database* originalDatabase =
dbHolder().get(txn, dbName);
if (originalDatabase == NULL) {
return Status(ErrorCodes::NamespaceNotFound, "database does not exist to repair");
}
scoped_ptr<Database> tempDatabase;
{
MMAPV1DatabaseCatalogEntry* entry =
new MMAPV1DatabaseCatalogEntry( txn,
dbName,
reservedPathString,
storageGlobalParams.directoryperdb,
true );
invariant( !entry->exists() );
tempDatabase.reset( new Database( txn,
dbName,
entry ) );
}
map<string,CollectionOptions> namespacesToCopy;
{
string ns = dbName + ".system.namespaces";
Client::Context ctx(txn, ns );
Collection* coll = originalDatabase->getCollection( txn, ns );
if ( coll ) {
scoped_ptr<RecordIterator> it( coll->getIterator( DiskLoc(),
false,
CollectionScanParams::FORWARD ) );
while ( !it->isEOF() ) {
DiskLoc loc = it->getNext();
BSONObj obj = coll->docFor( loc );
string ns = obj["name"].String();
NamespaceString nss( ns );
if ( nss.isSystem() ) {
if ( nss.isSystemDotIndexes() )
continue;
if ( nss.coll() == "system.namespaces" )
continue;
}
if ( !nss.isNormal() )
continue;
CollectionOptions options;
if ( obj["options"].isABSONObj() ) {
Status status = options.parse( obj["options"].Obj() );
if ( !status.isOK() )
return status;
}
namespacesToCopy[ns] = options;
}
}
}
//.........这里部分代码省略.........
示例15: StrReplace
/****** Replace substring 'from' to 'to' in string 'str' ******/
bool StrReplace(std::string& str, const std::string& from, const std::string& to) {
size_t start_pos = str.find(from);
if(start_pos == std::string::npos) return false;
str.replace(start_pos, from.length(), to);
return true;
}