本文整理汇总了C++中std::string::rfind方法的典型用法代码示例。如果您正苦于以下问题:C++ string::rfind方法的具体用法?C++ string::rfind怎么用?C++ string::rfind使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::string
的用法示例。
在下文中一共展示了string::rfind方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: clearURL
std::string URLData::clearURL(std::string str)
{
//clean php URLs
if (str.find("?")!=std::string::npos)
{
std::size_t found = str.find("?");
if (found!=std::string::npos)
str = str.substr(0, found);
}
//clean js URLs
if (str.rfind(";")!=std::string::npos)
{
std::size_t found = str.rfind(";");
if (found!=std::string::npos)
str = str.substr(0, found);
}
//delete the last /
if (str.back() == '/')
{
str.erase (str.end()-1, str.end());
}
//delete the root URL for insa-lyon.fr URLs
if (str.find("insa-lyon.fr")!=std::string::npos)
{
if (str.find(".fr:90")!=std::string::npos)
{
std::size_t found = str.find("90");
if (found!=std::string::npos)
str = str.substr(found+2, str.size());
}
else if (str.find(".fr")!=std::string::npos)
{
std::size_t found = str.find(".fr");
if (found!=std::string::npos)
str = str.substr(found+3, str.size());
}
}
//delete the root URL for intranet-if URLs
if (str.find("intranet-if")!=std::string::npos)
{
if (str.find("90")!=std::string::npos)
{
std::size_t found = str.find("90");
if (found!=std::string::npos)
str = str.substr(found+2, str.size());
}
}
//Clean and order URLs from google
if (str.find("google")!=std::string::npos)
{
str = "Google";
}
//Clean and order URLs from facebook
if (str.find("facebook")!=std::string::npos)
{
str = "Facebook";
}
return str;
}
示例2: searchDirectory
Strings searchDirectory( const std::string& directory,
const std::string& pattern )
{
Strings files;
#ifdef _MSC_VER
WIN32_FIND_DATA file;
const std::string search =
directory.empty() ? pattern : directory + '\\' + pattern;
HANDLE hSearch = FindFirstFile( search.c_str(), &file );
if( hSearch == INVALID_HANDLE_VALUE )
{
EQVERB << "Error finding the first file to match " << pattern << " in "
<< directory << std::endl;
FindClose( hSearch );
return files;
}
files.push_back( file.cFileName );
while( FindNextFile( hSearch, &file ))
files.push_back( file.cFileName );
FindClose( hSearch );
#else
const size_t findPos = pattern.find( '*' );
if( findPos == std::string::npos )
{
EQASSERTINFO( 0, "Unimplemented" );
return files;
}
const std::string first = pattern.substr( 0, findPos );
const std::string second = pattern.substr( findPos + 1 );
DIR* dir = opendir( directory.c_str() );
if( dir == 0 )
{
EQVERB << "Can't open directory " << directory << std::endl;
return files;
}
struct dirent* entry;
while(( entry = readdir( dir )) != 0 )
{
const std::string candidate( entry->d_name );
if( candidate.find( first ) != 0 )
continue; // doesn't start with filename
const size_t end = candidate.rfind( second );
if( end == std::string::npos || // not found
end + second.size() < candidate.size( )) // not at the end
{
continue;
}
files.push_back( entry->d_name );
}
closedir(dir);
#endif
return files;
}
示例3: ReadConfigFile
void
ColorTableManager::ImportColorTable(const std::string &ctFileName)
{
if(ctFileName.size() > 3 &&
ctFileName.substr(ctFileName.size() - 3) == ".ct")
{
//
// Read the color table from the XML file.
//
DataNode *node = ReadConfigFile(ctFileName.c_str());
if(node != 0)
{
std::string ctName;
std::string::size_type pos = ctFileName.rfind(VISIT_SLASH_STRING);
if(pos == std::string::npos)
ctName = ctFileName;
else
ctName = ctFileName.substr(pos + 1, ctFileName.size() - pos - 1 - 3);
// Look for the ColorTable node.
DataNode *node2 = node->SearchForNode("ColorTable");
if(node2 == 0)
return;
ColorControlPointList ccpl2;
ccpl2.SetFromNode(node2);
ccpl2.SetExternalFlag(true);
if (ccpl2.GetCategoryName() == std::string(""))
{
if (importingPersonal)
ccpl2.SetCategoryName("UserDefined");
else
ccpl2.SetCategoryName("Standard");
}
// Check for errors that would break code down the line
int ii;
bool broken = false;
for (ii = 0 ; ii < ccpl2.GetNumControlPoints() ; ii++)
{
float pos = ccpl2[ii].GetPosition();
if (pos < 0.0f || pos > 1.0)
{
broken = true;
break;
}
if (ii >= 1)
{
float prevPos = ccpl2[ii-1].GetPosition();
if (prevPos > pos)
{
broken = true;
break;
}
}
}
if (broken)
{
debug4 << "Could not read " << ctFileName.c_str() << "!" << endl;
}
else
{
ctAtts->AddColorTable(ctName, ccpl2);
debug4 << "Imported color table " << ctFileName.c_str()
<< " as " << ctName.c_str() << endl;
}
delete node;
}
else
debug4 << "Could not read " << ctFileName.c_str() << "!" << endl;
}
}
示例4: extractDomain
std::string LLViewerParcelMedia::extractDomain(std::string url)
{
static std::string last_region = "@";
if (url.empty())
{
return url;
}
LLStringUtil::toLower(url);
size_t pos = url.find("//");
if (pos != std::string::npos)
{
size_t count = url.size() - pos + 2;
url = url.substr(pos + 2, count);
}
// Check that there is at least one slash in the URL and add a trailing
// one if not (for media/audio URLs such as http://mydomain.net)
if (url.find('/') == std::string::npos)
{
url += '/';
}
// If there's a user:[email protected] part, remove it
pos = url.find('@');
if (pos != std::string::npos && pos < url.find('/')) // if '@' is not before the first '/', then it's not a user:password
{
size_t count = url.size() - pos + 1;
url = url.substr(pos + 1, count);
}
std::string current_region = gAgent.getRegion()->getHost().getHostName();
if (!current_region.size())
{
current_region = gAgent.getRegion()->getHost().getIPString();
}
if (url.find(current_region) == 0 || url.find(last_region) == 0)
{
// This must be a scripted object rezzed in the region:
// extend the concept of "domain" to encompass the
// scripted object server id and avoid blocking all other
// objects at once in this region...
// Get rid of any port number
pos = url.find('/'); // We earlier made sure that there's one
url = current_region + url.substr(pos);
pos = url.find('?');
if (pos != std::string::npos)
{
// Get rid of any parameter
url = url.substr(0, pos);
}
pos = url.rfind('/');
if (pos != std::string::npos)
{
// Get rid of the filename, if any, keeping only the server + path
url = url.substr(0, pos);
}
}
else
{
pos = url.find(':');
if (pos != std::string::npos && pos < url.find('/'))
{
// Keep anything before the port number and strip the rest off
url = url.substr(0, pos);
}
else
{
pos = url.find('/'); // We earlier made sure that there's one
url = url.substr(0, pos);
}
}
// Remember this region, so to cope with requests occuring just after a
// TP out of it.
last_region = gAgent.getRegion()->getHost().getHostName();
if (!last_region.size())
{
last_region = gAgent.getRegion()->getHost().getIPString();
}
return url;
}
示例5: getFolder
std::string Tfile::getFolder(std::string filePath)
{
return filePath.substr(0,filePath.rfind('/')+1);
}
示例6: saveOtbm
void Map::saveOtbm(const std::string& fileName, const UIWidgetPtr&/* pbar*/)
{
FileStreamPtr fin = g_resources.createFile(fileName);
if(!fin)
stdext::throw_exception(stdext::format("failed to open file '%s' for write", fileName));
fin->cache();
std::string dir;
if(fileName.find_last_of('/') == std::string::npos)
dir = g_resources.getWorkDir();
else
dir = fileName.substr(0, fileName.find_last_of('/'));
uint32 version = 0;
if(g_things.getOtbMajorVersion() < ClientVersion820)
version = 1;
else
version = 2;
/// Usually when a map has empty house/spawn file it means the map is new.
/// TODO: Ask the user for a map name instead of those ugly uses of substr
std::string::size_type sep_pos;
std::string houseFile = getHouseFile();
std::string spawnFile = getSpawnFile();
std::string cpyf;
if((sep_pos = fileName.rfind('.')) != std::string::npos && stdext::ends_with(fileName, ".otbm"))
cpyf = fileName.substr(0, sep_pos);
if(houseFile.empty())
houseFile = cpyf + "-houses.xml";
if(spawnFile.empty())
spawnFile = cpyf + "-spawns.xml";
/// we only need the filename to save to, the directory should be resolved by the OTBM loader not here
if((sep_pos = spawnFile.rfind('/')) != std::string::npos)
spawnFile = spawnFile.substr(sep_pos + 1);
if((sep_pos = houseFile.rfind('/')) != std::string::npos)
houseFile = houseFile.substr(sep_pos + 1);
fin->addU32(0); // file version
OutputBinaryTreePtr root(new OutputBinaryTree(fin));
{
root->addU32(version);
Size mapSize = getSize();
root->addU16(mapSize.width());
root->addU16(mapSize.height());
root->addU32(g_things.getOtbMajorVersion());
root->addU32(g_things.getOtbMinorVersion());
root->startNode(OTBM_MAP_DATA);
{
// own description.
for(const auto& desc : getDescriptions()) {
root->addU8(OTBM_ATTR_DESCRIPTION);
root->addString(desc);
}
// special one
root->addU8(OTBM_ATTR_DESCRIPTION);
root->addString(stdext::format("Saved with %s v%s", g_app.getName(), g_app.getVersion()));
// spawn file.
root->addU8(OTBM_ATTR_SPAWN_FILE);
root->addString(spawnFile);
// house file.
if(version > 1) {
root->addU8(OTBM_ATTR_HOUSE_FILE);
root->addString(houseFile);
}
int px = -1, py = -1, pz =-1;
bool firstNode = true;
for(uint8_t z = 0; z <= Otc::MAX_Z; ++z) {
for(const auto& it : m_tileBlocks[z]) {
const TileBlock& block = it.second;
for(const TilePtr& tile : block.getTiles()) {
if(!tile || tile->isEmpty())
continue;
const Position& pos = tile->getPosition();
if(!pos.isValid())
continue;
if(pos.x < px || pos.x >= px + 256
|| pos.y < py || pos.y >= py + 256
|| pos.z != pz) {
if(!firstNode)
root->endNode(); /// OTBM_TILE_AREA
firstNode = false;
root->startNode(OTBM_TILE_AREA);
px = pos.x & 0xFF00;
//.........这里部分代码省略.........
示例7: fileExtension
std::string fileExtension(const std::string &file) {
return file.substr(file.rfind(".")+1, file.length()-file.rfind(".")-1);
}
示例8: if
int
main(int argc, char *argv[])
{
std::ios::sync_with_stdio();
argv0 = argv[0];
{
size_t slash = argv0.rfind('/');
argv0 = slash==std::string::npos ? argv0 : argv0.substr(slash+1);
if (0==argv0.substr(0, 3).compare("lt-"))
argv0 = argv0.substr(3);
}
int argno = 1;
for (/*void*/; argno<argc && '-'==argv[argno][0]; ++argno) {
if (!strcmp(argv[argno], "--")) {
++argno;
break;
} else if (!strcmp(argv[argno], "--help") || !strcmp(argv[argno], "-h")) {
::usage(0);
} else if (!strcmp(argv[argno], "--delete")) {
opt.delete_old_data = true;
} else if (!strncmp(argv[argno], "--exclude-functions=", 20)) {
opt.exclude_functions_table = argv[argno]+20;
} else if (!strcmp(argv[argno], "--no-delete")) {
opt.delete_old_data = false;
} else if (!strncmp(argv[argno], "--relation=", 11)) {
opt.relation_id = strtol(argv[argno]+11, NULL, 0);
} else {
std::cerr <<argv0 <<": unknown switch: " <<argv[argno] <<"\n"
<<argv0 <<": see --help for more info\n";
exit(1);
}
};
if (argno+1!=argc)
::usage(1);
time_t start_time = time(NULL);
SqlDatabase::ConnectionPtr conn = SqlDatabase::Connection::create(argv[argno++]);
SqlDatabase::TransactionPtr tx = conn->transaction();
// Save ourself in the history if we're modifying the database.
int64_t cmd_id=-1;
if (opt.delete_old_data)
cmd_id = CloneDetection::start_command(tx, argc, argv, "clearing funcsim data for relation #"+
StringUtility::numberToString(opt.relation_id), start_time);
// The 32-func-similarity tool needs this index, so we might as well create it here when we're running serially. The
// semantic_outputvalues table can be HUGE depending on how the analysis is configured (i.e., whether it saves output
// values as a vector or set, whether it saves function calls and system calls, etc.). Since creating the index could take
// a few minutes, we'd rather not create it if it alread exists, but PostgreSQL v8 doesn't have a "CREATE INDEX IF NOT
// EXISTS" ability. Therefore, try to create the index right away before we make any other changes, and if creation fails
// then start a new transaction (because the current one is hosed).
std::cerr <<argv0 <<": creating output group index (could take a while)\n";
try {
SqlDatabase::TransactionPtr tx = conn->transaction();
tx->execute("create index idx_ogroups_hashkey on semantic_outputvalues(hashkey)");
tx->commit();
} catch (const SqlDatabase::Exception&) {
std::cerr <<argv0 <<": idx_ogroups_hashkey index already exists; NOT dropping and recreating\n";
}
// Delete old data.
if (opt.delete_old_data)
tx->statement("delete from semantic_funcsim where relation_id = ?")->bind(0, opt.relation_id)->execute();
// Get the list of functions that should appear in the worklist.
std::cerr <<argv0 <<": obtaining function list\n";
std::string stmt1 = "create temporary table tmp_tested_funcs as"
" select distinct fio.func_id as func_id"
" from semantic_fio as fio";
if (!opt.exclude_functions_table.empty()) {
std::vector<std::string> parts = StringUtility::split('.', opt.exclude_functions_table, 2, true);
if (parts.size()<2)
parts.push_back("func_id");
stmt1 += " left join " + parts.front() + " as exclude"
" on fio.func_id = exclude." + parts.back() +
" where exclude." + parts.back() + " is null";
}
tx->execute(stmt1);
// Create pairs of function IDs for those functions which have been tested and for which no similarity measurement has been
// computed. (FIXME: We should probably recompute similarity that might have changed due to rerunning tests or running the
// same function but with more input groups. [Robb P. Matzke 2013-06-19])
std::cerr <<argv0 <<": creating work list\n";
SqlDatabase::StatementPtr stmt2 = tx->statement("select distinct f1.func_id as func1_id, f2.func_id as func2_id"
" from tmp_tested_funcs as f1"
" join tmp_tested_funcs as f2 on f1.func_id < f2.func_id"
" except"
" select func1_id, func2_id from semantic_funcsim as sim"
" where sim.relation_id = ?");
stmt2->bind(0, opt.relation_id);
for (SqlDatabase::Statement::iterator row=stmt2->begin(); row!=stmt2->end(); ++row)
std::cout <<row.get<int>(0) <<"\t" <<row.get<int>(1) <<"\n";
if (cmd_id>=0)
CloneDetection::finish_command(tx, cmd_id, "cleared funcsim table for relation #"+
StringUtility::numberToString(opt.relation_id));
tx->commit();
return 0;
}
示例9: removeLastExtension
static inline const std::string removeLastExtension( const std::string & name ) {
std::string::size_type idx = name.rfind( '.' );
return ( ( idx < name.length() )? name.substr( 0,idx ) : name );
}
示例10: endsWith
bool StringUtils::endsWith(const std::string& input, const std::string& end)
{
return input.rfind(end) == (input.size() - end.size());
}
示例11: Read_CLNF
void CLNF::Read_CLNF(std::string clnf_location)
{
std::cout << "clnf_location = " << clnf_location << std::endl;
// Location of modules
std::ifstream locations(clnf_location.c_str(), std::ios_base::in);
if(!locations.is_open())
{
std::cout << "Couldn't open the CLNF model file aborting" << std::endl;
std::cout.flush();
return;
}
std::string line;
std::vector<std::string> intensity_expert_locations;
std::vector<std::string> depth_expert_locations;
std::vector<std::string> ccnf_expert_locations;
// The other module locations should be defined as relative paths from the main model
// boost::filesystem::path root = boost::filesystem::path(clnf_location).parent_path();
std::string root;
std::string temp("/");
std::size_t found = clnf_location.rfind(temp);
if (found!=std::string::npos)
root = clnf_location.substr(0, found);
// The main file contains the references to other files
while (!locations.eof())
{
getline(locations, line);
std::stringstream lineStream(line);
std::string module;
std::string location;
// figure out which module is to be read from which file
lineStream >> module;
getline(lineStream, location);
if(location.size() > 0)
location.erase(location.begin()); // remove the first space
// remove carriage return at the end for compatibility with unix systems
if(location.size() > 0 && location.at(location.size()-1) == '\r')
{
location = location.substr(0, location.size()-1);
}
// append the lovstion to root location (boost syntax)
// location = (root / location).string();
location = root + temp + location;
if (module.compare("PDM") == 0)
{
std::cout << "Reading the PDM module from: " << location << "....";
pdm.Read(location);
std::cout << "Done" << std::endl;
}
else if (module.compare("Triangulations") == 0)
{
std::cout << "Reading the Triangulations module from: " << location << "....";
std::ifstream triangulationFile(location.c_str(), std::ios_base::in);
LandmarkDetector::SkipComments(triangulationFile);
int numViews;
triangulationFile >> numViews;
// read in the triangulations
triangulations.resize(numViews);
for(int i = 0; i < numViews; ++i)
{
LandmarkDetector::SkipComments(triangulationFile);
LandmarkDetector::ReadMat(triangulationFile, triangulations[i]);
}
std::cout << "Done" << std::endl;
}
else if(module.compare("PatchesIntensity") == 0)
示例12: initialise
//----------------------------------------------------------------------------------------------------------------------
void Globals::initialise(const std::string& cfgFnm)
{
// Defaults
m_settings = 0;
m_fnm.clear();
// Current directory of the executable
bfs::path currentPath ( bfs::current_path() );
std::string currentPathStr = currentPath.string();
// Look for config file in current exe's directory or in subfolder specified in argument
std::string pathToConfig;
if(cfgFnm.empty())
{
#if DEBUGGING
std::cout << "No config file specified. Searching in local directory '" << currentPathStr << "'." << std::endl;
#endif
// No config file name given, so load first in base directory with xml ending.
bfs::directory_iterator end_itr;
for (bfs::directory_iterator itr(currentPath); itr != end_itr; ++itr)
{
// If it's not a directory ...
if (!is_directory(itr->status()))
{
// ... and the filename contains the xml ending
const std::string& fnm = itr->path().filename().string();
if(fnm.find(".xml") != std::string::npos)
{
m_fnm = fnm;
pathToConfig = itr->path().string();
#if DEBUGGING
std::cout << "Found config file '" << m_fnm << "'." << std::endl;
#endif
break;
}
}
}
}
else
{
std::string pathHomeExpanded = pathExpandHome(cfgFnm);
// Global paths start with a forward slash '/', local paths don't.
if (pathHomeExpanded[0] == '/' && bfs::exists(pathHomeExpanded))
{
m_fnm = pathHomeExpanded.substr(pathHomeExpanded.rfind('/') + 1);
pathToConfig = pathHomeExpanded;
#if 0
std::cout << "Found specified config file in ABSOLUTE path '" << pathToConfig << "'." << std::endl;
#endif
}
else
{
const std::string localPath = currentPathStr + "/" + pathHomeExpanded;
if(bfs::exists(localPath))
{
m_fnm = cfgFnm.substr(cfgFnm.rfind('/') + 1);
pathToConfig = localPath;
#if 0
std::cout << "Found specified config file in LOCAL path '" << pathToConfig << "'." << std::endl;
#endif
}
}
}
// If we have a valid config filename, load it
if(!pathToConfig.empty())
{
try
{
m_settings = new ci::XmlTree(ci::loadFile(pathToConfig));
}
catch (rapidxml::parse_error& e)
{
std::cout << "XML parse error trying to read config: '" << e.what() << "'. Aborting!" << std::endl;
}
}
else
{
#if DEBUGGING
std::cout << "No config file specified. Not loading any settings! '" << std::endl;
#endif
}
// Choose folder to save output file. It's either a hard-coded subfolder of current directory,
// or one specified in config file
std::string outputDir(currentPathStr + "/Output/");
if(m_settings && m_settings->hasChild("Config/Globals/OutputFolder"))
{
std::string dir = m_settings->getChild("Config/Globals/OutputFolder").getAttributeValue<std::string>("Name");
if(!dir.empty())
{
// Expand home directory: replaces '~' if appropriate
dir = pathExpandHome(dir);
// Absolute or relative path?
if(dir[0] != '/')
{
//.........这里部分代码省略.........
示例13: if
int
main(int argc, char *argv[])
{
std::ios::sync_with_stdio();
argv0 = argv[0];
{
size_t slash = argv0.rfind('/');
argv0 = slash==std::string::npos ? argv0 : argv0.substr(slash+1);
if (0==argv0.substr(0, 3).compare("lt-"))
argv0 = argv0.substr(3);
}
Switches opt;
int argno = 1;
for (/*void*/; argno<argc && '-'==argv[argno][0]; ++argno) {
if (!strcmp(argv[argno], "--")) {
++argno;
break;
} else if (!strcmp(argv[argno], "--help") || !strcmp(argv[argno], "-h")) {
::usage(0);
} else if (!strncmp(argv[argno], "--entry=", 8)) {
opt.entry_vas.insert(strtoull(argv[argno]+8, NULL, 0));
} else if (!strcmp(argv[argno], "--file=list") || !strcmp(argv[argno], "--files=list")) {
opt.list_files = true;
} else if (!strncmp(argv[argno], "--file=", 7) || !strncmp(argv[argno], "--files=", 8)) {
std::vector<std::string> ids = StringUtility::split(",", strchr(argv[argno], '=')+1, (size_t)-1, true);
for (size_t i=0; i<ids.size(); ++i) {
const char *s = ids[i].c_str();
char *rest;
errno = 0;
int id = strtoul(s, &rest, 0);
if (errno || rest==s || *rest) {
std::cerr <<argv0 <<": invalid file ID: " <<ids[i] <<"\n";
exit(1);
}
opt.files.insert(id);
}
} else if (!strncmp(argv[argno], "--function=", 11) || !strncmp(argv[argno], "--functions=", 12)) {
std::vector<std::string> ids = StringUtility::split(",", strchr(argv[argno], '=')+1, (size_t)-1, true);
if (ids.size()==1 && isalpha(ids[0][0]) && ids[0].find_first_of('.')!=std::string::npos) {
std::vector<std::string> words = StringUtility::split(".", ids[0]);
if (words.size()!=2 ||
!SqlDatabase::is_valid_table_name(words[0]) || !SqlDatabase::is_valid_table_name(words[1])) {
std::cerr <<argv0 <<": --function switch needs either IDs or a database TABLE.COLUMN\n";
exit(1);
}
opt.function_table = words[0];
opt.function_column = words[1];
} else {
for (size_t i=0; i<ids.size(); ++i) {
const char *s = ids[i].c_str();
char *rest;
errno = 0;
int id = strtoul(s, &rest, 0);
if (errno || rest==s || *rest) {
std::cerr <<argv0 <<": invalid function ID: " <<ids[i] <<"\n";
exit(1);
}
opt.functions.insert(id);
}
}
} else if (!strncmp(argv[argno], "--first-fuzz=", 13)) {
opt.first_fuzz = strtoul(argv[argno]+13, NULL, 0);
} else if (!strncmp(argv[argno], "--name=", 7)) {
opt.names.insert(argv[argno]+7);
} else if (!strncmp(argv[argno], "--nfuzz=", 8)) {
opt.nfuzz = strtoul(argv[argno]+8, NULL, 0);
opt.nfuzz_set = true;
} else if (!strncmp(argv[argno], "--size=", 7)) {
opt.ninsns = strtoul(argv[argno]+7, NULL, 0);
} else if (!strcmp(argv[argno], "--specimen=list") || !strcmp(argv[argno], "--specimens=list")) {
opt.list_specimens = true;
} else if (!strncmp(argv[argno], "--specimen=", 11) || !strncmp(argv[argno], "--specimens=", 12)) {
std::vector<std::string> ids = StringUtility::split(",", strchr(argv[argno], '=')+1, (size_t)-1, true);
for (size_t i=0; i<ids.size(); ++i) {
const char *s = ids[i].c_str();
char *rest;
errno = 0;
int id = strtoul(s, &rest, 0);
if (errno || rest==s || *rest) {
std::cerr <<argv0 <<": invalid specimen ID: " <<ids[i] <<"\n";
exit(1);
}
opt.specimens.insert(id);
}
} else {
std::cerr <<argv0 <<": unrecognized switch: " <<argv[argno] <<"\n"
<<"see \"" <<argv0 <<" --help\" for usage info.\n";
exit(1);
}
}
if (argno+1!=argc)
::usage(1);
SqlDatabase::TransactionPtr tx = SqlDatabase::Connection::create(argv[argno++])->transaction();
// List the ID numbers and names for all specimen files
if (opt.list_specimens) {
SqlDatabase::Table<int, std::string> specimens;
specimens.insert(tx->statement("select file.id, file.name"
" from (select distinct specimen_id as id from semantic_functions) as specimen"
//.........这里部分代码省略.........
示例14: GetDirectory
void Browser::GetDirectory(std::string dir, std::string subdir)
{
if (dir.empty())
dir = "/";
int highlightme = -1;
itsScrollBeginning = 0;
if (itsBrowsedDir != dir)
w->Reset();
itsBrowsedDir = dir;
locale_to_utf(dir);
for (size_t i = 0; i < w->Size(); ++i)
if (w->at(i).type == itSong)
delete w->at(i).song;
w->Clear();
if (dir != "/")
{
MPD::Item parent;
size_t slash = dir.rfind("/");
parent.song = reinterpret_cast<MPD::Song *>(1); // in that way we assume that's really parent dir
parent.name = slash != std::string::npos ? dir.substr(0, slash) : "/";
parent.type = itDirectory;
utf_to_locale(parent.name);
w->AddOption(parent);
}
MPD::ItemList list;
# ifndef WIN32
isLocal() ? GetLocalDirectory(list) : Mpd.GetDirectory(dir, list);
# else
Mpd.GetDirectory(dir, list);
# endif // !WIN32
if (!isLocal()) // local directory is already sorted
sort(list.begin(), list.end(), CaseInsensitiveSorting());
for (MPD::ItemList::iterator it = list.begin(); it != list.end(); ++it)
{
switch (it->type)
{
case itPlaylist:
{
utf_to_locale(it->name);
w->AddOption(*it);
break;
}
case itDirectory:
{
utf_to_locale(it->name);
if (it->name == subdir)
highlightme = w->Size();
w->AddOption(*it);
break;
}
case itSong:
{
bool bold = 0;
for (size_t i = 0; i < myPlaylist->Items->Size(); ++i)
{
if (myPlaylist->Items->at(i).GetHash() == it->song->GetHash())
{
bold = 1;
break;
}
}
w->AddOption(*it, bold);
break;
}
}
}
if (highlightme >= 0)
w->Highlight(highlightme);
}
示例15: removeFileExtension
std::string removeFileExtension(const std::string file) {
return file.substr(0,file.rfind("."));
}