本文整理汇总了C++中ustring::find_last_of方法的典型用法代码示例。如果您正苦于以下问题:C++ ustring::find_last_of方法的具体用法?C++ ustring::find_last_of怎么用?C++ ustring::find_last_of使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ustring
的用法示例。
在下文中一共展示了ustring::find_last_of方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: gw_mkdir_with_parents
void gw_mkdir_with_parents(const ustring & directory)
// Creates directory, with the parents, if need be.
// Function mkdir could be used (see man 2 mkdir), but this does not allow for
// the creation of the parent directories. The core utility mkdir provides
// this functionality, so is preferred, and used here.
// Later one g_mkdir_with_parents () was used, but this did not create
// directories properly. Hence we are stuck with mkdir.
{
#if 0
ustring s;
GwSpawn spawn (Directories->get_mkdir());
spawn.arg (Directories->get_mkdir_args());
spawn.arg (directory);
/* GwSpawn spawn("mkdir");
#ifndef WIN32
spawn.arg("-p");
#endif
spawn.arg(directory);
#ifdef WIN32
spawn.devnull();
#endif
*/ spawn.run();
#endif
#ifdef WIN32
// Use Windows system call to do this "right"
bool retval = CreateDirectory(directory.c_str(), NULL);
// Returns 0 if OK
// Returns non-zero if error, and GetLastError will tell us:
// ERROR_ALREADY_EXISTS The specified directory already exists.
// ERROR_PATH_NOT_FOUND One or more intermediate directories do not exist; this function will only create the final directory in the path.
if (retval == 0) {
int lasterr = GetLastError();
if (lasterr == ERROR_ALREADY_EXISTS) {
// Not really an error, just informative
mkdir_info("Already exists " + directory);
}
else if (lasterr == ERROR_PATH_NOT_FOUND) {
mkdir_info("Cannot create " + directory + " because intermediate directories don't exist.");
// Strip off last part of directory and try again recursively
Glib::ustring::size_type idx = directory.find_last_of("\\");
ustring newdir = directory.substr(0, idx);
gw_mkdir_with_parents(newdir);
// Now try the full path again
gw_mkdir_with_parents(directory);
}
}
else {
// Not really an error, just informative
mkdir_info("Created " + directory);
}
#else
GwSpawn spawn (Directories->get_mkdir());
spawn.arg (Directories->get_mkdir_args());
spawn.arg (directory);
spawn.run();
#endif
}
示例2: getFileType
filetype_t File::getFileType(ustring filename)
{
// Extract file extension (i.e. "stl")
ustring extension = filename.substr(filename.find_last_of(".")+1);
if(extension == "wrl" || extension == "WRL") {
return VRML;
}
if(extension == "amf" || extension == "AMF") {
return AMF;
}
if(extension != "stl" && extension != "STL") {
return NONE_STL;
}
ifstream file;
file.open(filename.c_str());
if(file.fail()) {
cerr << _("Error: Unable to open file - ") << filename << endl;
return NONE_STL;
}
// ASCII files start with "solid [Name_of_file]"
ustring first_word;
try {
file >> first_word;
// Find bad Solid Works STL header
// 'solid binary STL from Solid Edge, Unigraphics Solutions Inc.'
ustring second_word;
if(first_word == "solid")
file >> second_word;
file.close();
if(first_word == "solid" && second_word != "binary") { // ASCII
return ASCII_STL;
} else {
return BINARY_STL;
}
} catch (Glib::ConvertError& e) {
return BINARY_STL; // no keyword -> binary
}
}
示例3: extract
ustring extract(const ustring& path)
{
auto pos = path.find_last_of(PATH_SEPARATORS);
return (pos != ustring::npos) ? path.substr(++pos) : ustring();
}