Example #1
0
static string get_basename(const string& filename)
{
#if defined(_MSC_VER)
	char const dir_sep('\\');
#else
	char const dir_sep('/');
#endif

	string::size_type pos = filename.rfind(dir_sep);
	if(pos != string::npos)
		return filename.substr(pos+1);
	else
		return filename;
}
string Meme::getFileName(const string& s){
    char sep = '/';

    #ifdef _WIN32
       sep = '\\';
    #endif

   size_t i = s.rfind(sep, s.length());
   if (i != string::npos) {
      return(s.substr(i+1, s.length() - i));
   }

   return("");
}
//add by sherrypan
string base_string::MidStrExA(string strStart, string strEnd, string Buf, bool fgPre/* = true*/)
{//create by sherry
	string result = "";
	size_t nstart ;//= Buf.find(strStart);
	size_t nEnd ;//= Buf.find(strEnd, nstart + strStart.length());
	if (fgPre)
	{
		nstart = Buf.find(strStart);
		nEnd = Buf.find(strEnd, nstart + strStart.length());
	}
	else
	{
		nEnd = Buf.rfind(strEnd);
		nstart = Buf.rfind(strStart, nEnd);
	}

	if (nstart != std::string::npos && nEnd != std::string::npos)
	{
		result = Buf.substr(nstart + strStart.length(), nEnd - nstart - strStart.length());
	}

	return result;
}
Example #4
0
string getFext(const string& s) {
   string r("");
   //if (xpos!=NULL) *xpos=0;
   if (s.empty() || s=="-") return r;
   int slen=(int)s.length();
   int p=s.rfind('.');
   int d=s.rfind('/');
   if (p<=0 || p>slen-2 || p<slen-7 || p<d) return r;
   r=s.substr(p+1);
   //if (xpos!=NULL) *xpos=p+1;
   for(size_t i=0; i!=r.length(); i++)
        r[i] = std::tolower(r[i]);
   return r;
   }
Example #5
0
/// \brief Strips the extension from a file.
string CTask::StripExtension(string filename, vector<string> & valid_extensions)
{
	size_t lastindex = std::string::npos;

	for(auto extension : valid_extensions)
	{
		lastindex = filename.rfind("." + extension);

		if (lastindex != std::string::npos)
			return filename.substr(0, lastindex);
	}

	return filename;
}
Example #6
0
//return true if file is jpeg 2000 (jp2 or jpm)
bool DPIWriter::isJPEG2000(string fileName)
{
	int idx;
	idx = fileName.rfind('.');
	if(idx != std::string::npos)
	{
		string extension = fileName.substr(idx+1);
		return (stricmp(extension.c_str(), "jp2")==0 || stricmp(extension.c_str(), "jpm")==0);
	}
	else
	{
		return false;
	}
}
Example #7
0
void nsUtils::splitQualifiedName(const string& input,
                                 string& package, string& className)
{
    string::size_type pos(input.rfind("."));
    if (pos == string::npos) {
        package = "";
        className = input;
    }
    package = input.substr(0, pos);
    className = input.substr(pos + 1);
    DEBUG(2) << "Splitting qualified name \"" << input <<
                "\" into package \"" << package <<
                "\" and class \"" << className << "\"\n";
}
Example #8
0
const string& getExeFileName() {
	static string exeFn;
	if(exeFn.empty()) {
		char fileName[MAX_PATH];
		GetModuleFileNameA(NULL, fileName, MAX_PATH);
		exeFn = fileName;
		size_t pos = exeFn.rfind("\\");
		if(pos != string::npos) {
			exeFn = exeFn.substr(pos+1);
			pos = exeFn.rfind(".exe");
			if(pos == string::npos) pos = exeFn.rfind(".EXE");
			if(pos != string::npos) {
				exeFn = exeFn.substr(0, pos);
			} else {
				// Tales of Symphonia fix
				if(exeFn.find("sec") == 0) {
					exeFn = "Symphonia";
				}
			}
		}
	}
	return exeFn;
}
Example #9
0
FileIO::FileParts FileIO::GetFileParts(const string& s)
{
	FileIO::FileParts file;
	string path, name, extension;
	
    char sep = '/';

	#ifdef _WIN32
	   sep = '\\';
	#endif
	
   size_t i = s.rfind(sep, s.length());

	   path = s.substr(0, i + 1);
	   extension = s.substr(s.rfind("."), s.length() - s.rfind("."));
	   name = s.substr(i + 1, s.length() - (path.length() + extension.length()));
	  
	   file.path = path;
	   file.name = name;
	   file.extension = extension;
	   
	  return(file);
}
Example #10
0
Animal Zoo::StringToAnimal(string data) {
    string species_temp;
    string color_temp;
    string legs_temp;
    int firstDelimiter = data.find('|');
    int secondDelimiter = data.rfind('|');

    species_temp = data.substr(0,firstDelimiter);
    color_temp = data.substr(firstDelimiter+1,secondDelimiter-firstDelimiter-1);
    legs_temp = data.substr(secondDelimiter+1);

    Animal Animal_temp(species_temp, color_temp, atoi(legs_temp.c_str()));
    return Animal_temp;
}
Example #11
0
//! Gives extension of a file ignoring any trailing .gz
//! i.e. for 'foo.pdb.gz' it gives 'pdb', for 'foo.pdb' it gives 'pdb'
bool extensionIgnoringGz(const string& filename,string& ret,bool &endsWithGz,std::ostream& errorStream)
{
    size_t period=filename.rfind('.');
    endsWithGz=false;
    if(period==string::npos) {
        errorStream<<"Partio: No extension detected in filename"<<endl;
        return false;
    }
    string extension=filename.substr(period+1);
    if(extension=="gz") {
        endsWithGz=true;
        size_t period2=filename.rfind('.',period-1);
        if(period2==string::npos) {
            errorStream<<"Partio: No extension detected in filename"<<endl;
            return false;
        }
        string extension2=filename.substr(period2+1,period-period2-1);
        ret=extension2;
    } else {
        ret=extension;
    }
    return true;
}
	vector<string> removeStar(string p, int star_pos, int remain, vector<string> &vecStr)
	{
		if (star_pos == -1)
		{
			return vecStr;
		}
		if (star_pos == 0)
		{
			star_pos = p.rfind('*');
		}

		int pos; 
		if (string::npos == p.rfind('*', star_pos-1))
		{
			pos = -1;
		}
		else
		{
			pos = p.rfind('*', star_pos-1);	
		}

		vector<string> copyedVec;
		for (int k = 0; k <= remain; k++)
		{
			vecStr = removeStar(p, pos, remain-k, vecStr);
			//vecStr.clear();

			string replacedLetter(k, p[star_pos-1]);
			for (int i = 0; i < vecStr.size(); i++)
			{
				string clonedStr = vecStr[i];
				copyedVec.push_back(clonedStr.replace(star_pos, 1, replacedLetter));
			}
		}
		vecStr.swap(copyedVec);
		return vecStr;
	}
/* ComponentEvent protected methods */
void ComponentEvent::convertValue(const string& value)
{
  // Check if the type is an alarm or if it doesn't have units
  if (value == "UNAVAILABLE")
  {
    mValue = value;
  }
  else if (mIsTimeSeries || mDataItem->isCondition() || mDataItem->isAlarm() ||
           mDataItem->isMessage() || mDataItem->isAssetChanged())
  {
    string::size_type lastPipe = value.rfind('|');
    
    // Alarm data = CODE|NATIVECODE|SEVERITY|STATE
    // Conditon data: SEVERITY|NATIVE_CODE|[SUB_TYPE]
    // Asset changed: type|id
    mRest = value.substr(0, lastPipe);
    
    // sValue = DESCRIPTION
    if (mIsTimeSeries)
    {
      const char *cp = value.c_str();
      cp += lastPipe + 1;
      
      // Check if conversion is required...
      char *np;
      while (cp != NULL && *cp != '\0') 
      {
		float v = strtof(cp, &np);
		if (cp != np) {
		  mTimeSeries.push_back(mDataItem->convertValue(v));
		} else
		  np = NULL;
		cp = np;
      }
    }
    else
    {
      mValue = value.substr(lastPipe+1);
    }
  }
  else if (mDataItem->conversionRequired())
  {
    mValue = mDataItem->convertValue(value);
  }
  else
  {
    mValue = value;
  }
}
Example #14
0
void PageSize::resize (string name) {
	if (name.length() < 2)
		throw PageSizeException("unknown page format: "+name);

	name = util::tolower(name);
	// extract optional suffix
	size_t pos = name.rfind("-");
	bool landscape = false;
	if (pos != string::npos) {
		string suffix = name.substr(pos);
		name = name.substr(0, pos);
		if (suffix == "-l" || suffix == "-landscape")
			landscape = true;
		else if (suffix != "-p" && suffix != "-portrait")
			throw PageSizeException("invalid page format suffix: " + suffix);
	}

	if (name == "invoice") {
		_width = 140_mm;
		_height = 216_mm;
	}
	else if (name == "executive") {
		_width = 184_mm;
		_height = 267_mm;
	}
	else if (name == "legal") {
		_width = 216_mm;
		_height = 356_mm;;
	}
	else if (name == "letter") {
		_width = 216_mm;
		_height = 279_mm;
	}
	else if (name == "ledger") {
		_width = 279_mm;;
		_height = 432_mm;
	}
	else if (isdigit(name[1]) && name.length() < 5) {  // limit length of number to prevent arithmetic errors
		istringstream iss(name.substr(1));
		int n;
		iss >> n;
		switch (name[0]) {
			case 'a' : computeASize(n, _width, _height); break;
			case 'b' : computeBSize(n, _width, _height); break;
			case 'c' : computeCSize(n, _width, _height); break;
			case 'd' : computeDSize(n, _width, _height); break;
			default  : throw PageSizeException("invalid page format: "+name);
		}
	}
Example #15
0
/*!
 * make_filename takes the filename 's' and appends the number 'n'
 */
string make_filename(string s, int n)
{
  // if there is a dot, place the number n behind it (rfind searches from the end)
  int p = s.rfind('.');
  // otherwise put the number n at the end
  if(p<0)
    p = s.size();
  stringstream h;
  
  h << setfill('0') << setw(5) << n;
  
  s.insert(p, "_"+h.str());
  
  return s;
}
Example #16
0
FileDialog::FileDialog(
		GMenu2X *gmenu2x, Touchscreen &ts, const string &text,
		const string &filter, const string &file, const string &title)
	: BrowseDialog(gmenu2x, ts, title, text)
{
	string path(CARD_ROOT);
	if (!file.empty()) {
		string::size_type pos = file.rfind("/");
		if (pos != string::npos)
			path = file.substr(0, pos);
	}

	fl.setFilter(filter);
	setPath(path);
}
static string change_dir(const string &start_path, const string &cd)
{
    const unsigned last = start_path.length();

    if (cd == "..")
    {
        const unsigned up = start_path.rfind('/', last-2);
        return start_path.substr(0, up);
    }

    if (start_path[last] == '/')
        return start_path + cd;
    else
        return start_path + '/' + cd;
}
Example #18
0
string getFilePathPart( const string& fileName )
{
	string filePath;

	int lastSlash = fileName.rfind('/');
	if( lastSlash == string::npos )
	{
		filePath = string("./");
	}else
	{
		filePath = string( fileName, 0, lastSlash+1);
	}

	return filePath;
}
Example #19
0
string PackageGroup::CreateFileLocation(string directory, string file_path)
{
    // strip the directory path
    string filename = file_path;
    size_t sep_index;
#if defined(_WIN32)
    if ((sep_index = file_path.rfind("\\")) != string::npos ||
        (sep_index = file_path.rfind(":")) != string::npos)
#else
    if ((sep_index = file_path.rfind("/")) != string::npos)
#endif
    {
        filename = file_path.substr(sep_index + 1);
    }
    
    if (directory.empty())
        return filename;

#if defined(_WIN32)
    return directory + "\\" + filename;
#else
    return directory + "/" + filename;
#endif
}
Example #20
0
void Util::UnpackUrl(const string& url,string& host,UInt16& port,string& path,map<string,string>& properties) {
	try {
		URI uri(url);
		uri.normalize();
		path = uri.getPath();
		host = uri.getHost();
		port = uri.getPort();
		size_t found = path.rfind('/');
		if(found!= string::npos && found==(path.size()-1))
			path.erase(found);
		UnpackQuery(uri.getRawQuery(),properties);
	} catch(Exception& ex) {
		ERROR("Unpack url %s impossible : %s",url.c_str(),ex.displayText().c_str());
	}
}
Example #21
0
 string filename_shortname(const string& filename)
 {
     string::size_type pos1 = filename.rfind('/');
     string::size_type pos2 = filename.rfind('.');
     if (pos2 == string::npos) {
         return "";
     } else {
         if (pos1 == string::npos) {
             pos1 = 0;
         } else {
             pos1 += 1;
         }
         return filename.substr(pos1, pos2 - pos1);
     }
 }
Example #22
0
string fileUtils::GetFileName(const string& p_path, bool p_withExt)
{
	size_t index = p_path.find_last_of("/\\");
	string name = (index != string::npos ? p_path.substr(index + 1) : string());

	if (!p_withExt)
	{
		index = p_path.rfind('.');
		
		if (index != string::npos)
			name.erase(index);
	}

	return name;
}
Example #23
0
string DU_File::extractFileName(const string &sFullFileName)
{
    if(sFullFileName.length() <= 0)
    {
        return "";
    }

    string::size_type pos = sFullFileName.rfind('/');
    if(pos == string::npos)
    {
        return sFullFileName;
    }

    return sFullFileName.substr(pos + 1);
}
Example #24
0
// Checks if the SocketIO event has JSON data.
// If there is data the JSON object in string format will be returned,
// else the empty string "" will be returned.
string hasData(string s)
{
  auto found_null = s.find("null");
  auto b1 = s.find_first_of("[");
  auto b2 = s.rfind("}]");
  if (found_null != string::npos)
  {
    return "";
  }
  else if (b1 != string::npos && b2 != string::npos)
  {
    return s.substr(b1, b2 - b1 + 2);
  }
  return "";
}
Example #25
0
/************************************rename*****************************************
调用move,只要from_path和to_path只有文件名不一样时,就可以将from_path中的文件名改为to_path中的文件名
*/
void kp_api::rename(string path,string new_name)
{
	string first_path(path);
	int i = path.rfind("/");
	if(i==-1)
		path = new_name;
	else
	{
		int len = path.length() - i;
		//cout<<i<<"**"<<len<<endl;
		path.replace(i+1,len,new_name);		
	}
	//cout<<path<<endl;
	kp_api::move(first_path,path);	
}
Example #26
0
string findTestDir(string homeDir) {
    struct stat info;
    string sameDir = homeDir + "/tests";
    int ret = stat(sameDir.c_str(), &info);
    if (ret==0 && S_ISDIR(info.st_mode)) {
        return sameDir;
    } else {
        // search one level up
        string::size_type idx = homeDir.rfind("/");
        if (idx == string::npos) {
            throw runtime_error("can't find test directory");
        }
        return findTestDir(homeDir.substr(0,idx));
    }
}
Example #27
0
string fixHost( string url , string host , string port ) {
    //cout << "fixHost url: " << url << " host: " << host << " port: " << port << endl;

    if ( host.size() == 0 && port.size() == 0 ) {
        if ( url.find( "/" ) == string::npos ) {
            // check for ips
            if ( url.find( "." ) != string::npos )
                return url + "/test";

            if ( url.rfind( ":" ) != string::npos &&
                    isdigit( url[url.rfind(":")+1] ) )
                return url + "/test";
        }
        return url;
    }

    if ( url.find( "/" ) != string::npos ) {
        cerr << "url can't have host or port if you specify them individually" << endl;
        exit(-1);
    }

    if ( host.size() == 0 )
        host = "127.0.0.1";

    string newurl = host;
    if ( port.size() > 0 )
        newurl += ":" + port;
    else if ( host.find(':') == string::npos ) {
        // need to add port with IPv6 addresses
        newurl += ":27017";
    }

    newurl += "/" + url;

    return newurl;
}
void generate(int depth){
    if(depth<=0)return; 
    int found=lsystem.length()+1;
    int found_A=found;
    int found_B=found;
    do{
        found_A=lsystem.rfind(replaceA,found-1);
        found_B=lsystem.rfind(replaceB,found-1);
        //cout<<found_A<<" "<<found_B<<endl;
        found_A>found_B?found=found_A:found=found_B;
        lsystem.replace(found,1,found_A>found_B?patternA:patternB);
    }while(found!=string::npos&&found>0);//当查找到头的时候结束
    //这里查找应该由后往前,否则被替换的string会参与查找,进入死循环
    generate(depth-1);//生成深度

}
string Utilities::getFilePath(const string &path)
{
	string result = path;
	size_t i = path.rfind('\\', path.length());
	if (i != string::npos)
	{
		result = path.substr(0, i + 1);
	}
	i = result.rfind('/', result.length());
	if (i != string::npos)
	{
		result = (result.substr(0, i + 1));
	}

	return result;
}
Example #30
0
BTree::BTree(int order, string nombre, bool open):order(order), page_count(0), nombre(nombre){
	this->root = new node();
	is_up = false;
	size_t size = nombre.rfind(".OAR");
	if(size != string::npos)
		nombre = nombre.substr(0, nombre.size()-4);
	nombre += ".treeData";
	cout << "Tree directory: " << nombre << endl;
	if(open){
		input.open(nombre.c_str(), ios::in);
		output.open(nombre.c_str(), ios::in | ios::out);
		readTree(root);
	}else{
		output.open(nombre.c_str(), ios::out);
	}
}