Example #1
0
	Filepath::Filepath(const tstring & full_path)
		: m_Path(EMPTY_STRING)
		, m_File(EMPTY_STRING)
	{
		int32 dotCounter(0);
		for(uint32 i = 0; i < full_path.size(); ++i)
		{
			if(full_path[i] == _T('.'))
			{
				++dotCounter;
			}
		}
		if(dotCounter > 1)
		{
			Logger::GetInstance()->Log(LogLevel::Error, 
				_T("Please don't use . in your filename (except for the file extension)"));
		}

		auto index = full_path.find_last_of('/');
		if(index == tstring::npos)
		{
			index = full_path.find_last_of('\\');
		}
		if(index != tstring::npos)
		{
			index += 1;
			m_Path = full_path.substr(0,index);
			m_File = full_path.substr(index, full_path.length() - index);
		}
		else
		{
			m_File = full_path;
		}
	}
Example #2
0
File: Space.cpp Project: GMIS/GMIS
tstring GetFilePath(tstring FileName){
	tstring::size_type n = FileName.find_last_of(_T('\\'));
	if(n != tstring::npos){
		return FileName.substr(0,n);
	}
	n = FileName.find_last_of(_T('/'));
	if(n == tstring::npos){
		return FileName;
	}
	return FileName.substr(0,n);
};
Example #3
0
File: Space.cpp Project: GMIS/GMIS
tstring GetFileNoPathName(tstring s)
{
	tstring::size_type n = s.find_last_of(_T('\\'));
	if(n != tstring::npos){
		return s.substr(n+1);
	}
	n = s.find_last_of(_T('/'));
	if(n == tstring::npos){
		return s;
	}
	return s.substr(n);
}
Example #4
0
std::string remove_extension(tstring const& filename)
{
	const size_t last_slash = filename.find_last_of("\\/");
	const size_t last_dot = filename.find_last_of('.');
	if( ( last_slash != tstring::npos && last_dot < last_slash) || 
	    ( last_dot == tstring::npos) ||
		( last_dot == filename.size() - 1 )
		) 
	{
		return filename.str();
	} else {
		tstring result = filename.substr(0, last_dot);
		return result.str();
	}
}
Example #5
0
std::string extension(tstring const& filename)
{
    
    size_t last_dot = filename.find_last_of(".");
    if( last_dot == tstring::npos )
        return "";
    
    size_t last_slash = filename.find_last_of("\\/");
    if( last_slash != tstring::npos && last_slash > last_dot )
        // extension is somewhere in path component
        return "";
        
    return filename.substr(last_dot+1).str();
    
}
Example #6
0
CRegStdBase::CRegStdBase (const tstring& key, bool force, HKEY base, REGSAM sam)
    : CRegBaseCommon<tstring> (key, force, base, sam)
{
    tstring::size_type pos = key.find_last_of(_T('\\'));
    m_path = key.substr(0, pos);
    m_key = key.substr(pos + 1);
}
Example #7
0
tstring FileSystem::removeFileExtension( const tstring& fileName )
{
    size_t pos = fileName.find_last_of('.');
    if (pos != tstring::npos)
    {
        return fileName.substr(0, pos);
    }
    return fileName;
}
Example #8
0
std::string basename(tstring const& name)
{
    std::string::size_type p = name.find_last_of("/\\");
    if( p == tstring::npos ) {
        return name.str();
    } else {
        return std::string(name.data()+p+1, name.size()-p-1);
    }
}
Example #9
0
tstring FileSystem::getFileExtension( const tstring& fileName )
{
    size_t pos = fileName.find_last_of('.');
    if (pos != tstring::npos)
    {
        return fileName.substr(pos + 1, fileName.size() - pos - 1);
    }
    return TEXT("");
}
Example #10
0
    tstring ExtractFileExt(const tstring& path)
    {
        size_t pos = path.find_last_of(_T("\\/."));

        if (pos != tstring::npos && path[pos] == '.')
        {
            return path.substr(pos + 1);
        }
        return _T("");
    }
Example #11
0
    //--------------------------------------------------------------------------------------------
    //  Implementation
    //--------------------------------------------------------------------------------------------
    //return path like="xxx/xxx" , without "/" at last.
    tstring ExtractFilePath(const tstring& path)
    {
        size_t pos = path.find_last_of(_T("\\/"));

        if (pos != tstring::npos)
        {
            return path.substr(0, pos);
        }
        return path;
    }
Example #12
0
int FileAppender::append(const tstring &logMsg)
{
	if(_fs.is_open())
	{
		// need to create a new file?
		if( _multiFiles && _curSize > _maxSize )
		{
			// close current file
			_fs.close();
			ASSERT(!_fs.is_open());

			// make a new log file name: oldfile{time}_index.xx, eg. "mylog_20101229_235959_1.txt"
			__time64_t t;
			_time64( &t );
			struct tm *tt = _localtime64(&t);
			tchar tmString[TIME_BUF_SZIE + 1] = {0};
			_stprintf(tmString, _T("_%04d%02d%02d_%02d%02d%02d_%d"), tt->tm_year + 1900, tt->tm_mon + 1, tt->tm_mday, tt->tm_hour, tt->tm_min, tt->tm_sec, ++_fileIndex);
			//tstringstream tos;
			//tos << _T("_") << tt->tm_year + 1900 << tt->tm_mon << tt->tm_mday << _T("_") << tt->tm_hour << tt->tm_min << tt->tm_sec;

			tstring newFileName(_fileName);
			tstring::size_type indexDot = _fileName.find_last_of(_T('.'));
			if(tstring::npos == indexDot)
			{
				//newFileName += tos.str();
				newFileName += tmString;
			}
			else
			{
				// newFileName.insert(indexDot, tos.str());
				newFileName.insert(indexDot, tmString);
			}

			// open new log file
			_fs.open(newFileName.c_str(), std::ios::out);
			if(_fs.is_open())
			{
				_fs.imbue(_loc);
				_curSize = 0;
			}
			else
			{
				ASSERT(0);
			}
		}

		// write log message to file
		if(_fs.is_open()) 
		{
			_fs << logMsg << std::flush;
			_curSize = static_cast<unsigned long>(_fs.tellp());
		}
	}
	return 0;
}
bool
CLink::IsEqual(
	const tstring&	strLink ) const
{
	bool rc = false;

	switch ( m_urlType )
	{
		case urlType_LocalAbsolute:
		{
			rc = ( strLink == m_strLink );
		} break;

		case urlType_Relative:
		{
			tstring strRel=strLink;
			tstring::size_type p = strLink.find_last_of( _T('/') );
			if ( p != tstring::npos )
			{
				strRel = strLink.substr( p + 1, strLink.length() );
			}
			else
			{
				p = strLink.find_last_of( _T('\\') );
				if ( p != tstring::npos )
				{
					strRel = strLink.substr( p + 1, strLink.length() );
				}
			}
			if ( strRel == m_strLink )
			{
				rc = true;
			}
		} break;

		case urlType_Absolute:
		default:
		{
		} break;
	}
	return rc;
}
Example #14
0
std::string dirname(tstring const& name)
{
    if( name.size() == 0 ) return ".";
    tstring::size_type p = name.find_last_of("/\\");
    if( p == tstring::npos ) {
        return ".";
    } else if( p == 0 )  {
        return "/";
    } else {
        return std::string(name.data(), p);
    }
}
Example #15
0
bool has_extension(tstring const& filename)
{
    size_t find_start = filename.find_last_of("\\/");
    if( find_start == tstring::npos )
        find_start = 0;
    else
        find_start++;
    
    const size_t dot_pos = filename.find_first_of('.', find_start);
    const bool dot_exists =   (dot_pos != tstring::npos);
    const bool not_at_start = (dot_pos > find_start);
    return dot_exists && not_at_start;
}
Example #16
0
void PathX::GetDirectory(const tstring& path, tstring& outDirectory)
{
	tstring::size_type pos = path.find_last_of(separator);
	if (pos == tstring::size_type(-1))
	{
		outDirectory.clear();
		return;
	}
	else
	{
		outDirectory = path.substr(0, pos);
		return;
	}
}
Example #17
0
void PathX::GetExtension(const tstring& path, tstring& outExtension)
{
	tstring::size_type pos = path.find_last_of(extension);
	if (pos == tstring::size_type(-1))
	{
		outExtension.clear();
		return;
	}
	else if(pos == tstring::size_type(path.length()-1))
	{
		outExtension.clear();
		return;
	}
	else
	{
		outExtension = path.substr(pos+1, path.length());
		return;
	}
}
Example #18
0
void PathX::GetFileName(const tstring& path, tstring& outFileName)
{
	tstring::size_type pos = path.find_last_of(separator);
	if (pos == tstring::size_type(-1))
	{
		outFileName = path;
		return;
	}
	else if(pos == tstring::size_type(path.length()-1))
	{
		outFileName.clear();
		return;
	}
	else
	{
		outFileName = path.substr(pos+1, path.length());
		return;
	}
}
Example #19
0
tstring FileUtils::_getPathForFilename( const tstring& filename, const tstring& searchPath ) const
{
	tstring file = filename;
	tstring path = "";
	size_t pos = filename.find_last_of("/");
	if (pos != tstring::npos)
	{
		path = filename.substr(0, pos+1);
		file = filename.substr(pos+1);
	}

	// searchPath + path
	path = searchPath + path;

	path = _getFullPathForDirectoryAndFilename(path, file);

	//CCLOG("getPathForFilename, fullPath = %s", path.c_str());
	return path;
}
Example #20
0
BOOL checkModulePathName(tstring strModulePathName)
{
	size_t iStart = strModulePathName.find_last_of(_T('\\'));
	if (iStart == tstring::npos)
	{
		TRACE_PRINT1("checkModulePathName::find_last_of: error, strModulePathName = %s.", strModulePathName.c_str());
		return FALSE;
	}
	else
	{
		tstring strModuleName = strModulePathName.substr(iStart + 1, tstring::npos);
		if (strModuleName == _T("wpcap.dll") || strModuleName == _T("packet.dll"))
		{
			return TRUE;
		}
		else
		{
			return FALSE;
		}
	}
}
Example #21
0
void litehtml::css::parse_atrule( const tstring& text, const tchar_t* baseurl, document* doc, media_query_list::ptr& media )
{
	if(text.substr(0, 7) == _t("@import"))
	{
		int sPos = 7;
		tstring iStr;
		iStr = text.substr(sPos);
		if(iStr[iStr.length() - 1] == _t(';'))
		{
			iStr.erase(iStr.length() - 1);
		}
		trim(iStr);
		string_vector tokens;
		split_string(iStr, tokens, _t(" "), _t(""), _t("(\""));
		if(!tokens.empty())
		{
			tstring url;
			parse_css_url(tokens.front(), url);
			if(url.empty())
			{
				url = tokens.front();
			}
			tokens.erase(tokens.begin());
			if(doc)
			{
				document_container* doc_cont = doc->container();
				if(doc_cont)
				{
					tstring css_text;
					tstring css_baseurl;
					if(baseurl)
					{
						css_baseurl = baseurl;
					}
					doc_cont->import_css(css_text, url, css_baseurl);
					if(!css_text.empty())
					{
						media_query_list::ptr new_media = media;
						if(!tokens.empty())
						{
							tstring media_str;
							for(string_vector::iterator iter = tokens.begin(); iter != tokens.end(); iter++)
							{
								if(iter != tokens.begin())
								{
									media_str += _t(" ");
								}
								media_str += (*iter);
							}
							new_media = media_query_list::create_from_string(media_str, doc);
							if(!new_media)
							{
								new_media = media;
							}
						}
						parse_stylesheet(css_text.c_str(), css_baseurl.c_str(), doc, new_media);
					}
				}
			}
		}
	} else if(text.substr(0, 6) == _t("@media"))
	{
		tstring::size_type b1 = text.find_first_of(_t('{'));
		tstring::size_type b2 = text.find_last_of(_t('}'));
		if(b1 != tstring::npos)
		{
			tstring media_type = text.substr(6, b1 - 6);
			trim(media_type);
			media_query_list::ptr new_media = media_query_list::create_from_string(media_type, doc);

			tstring media_style;
			if(b2 != tstring::npos)
			{
				media_style = text.substr(b1 + 1, b2 - b1 - 1);
			} else
			{
				media_style = text.substr(b1 + 1);
			}

			parse_stylesheet(media_style.c_str(), baseurl, doc, new_media);
		}
	}
}
int CFulEditCtrl::FullTextMatch(ColorSettings* cs, CHARFORMAT2 &cf, const tstring &line, int pos, int &lineIndex) {
	int index = tstring::npos;
	tstring searchString;

	if( cs->getMyNick() ) {
		tstring::size_type p = cs->getMatch().find(_T("$mynick$"));
		if(p != tstring::npos) {
			searchString = cs->getMatch();
			searchString = searchString.replace(p, 8, nick);
		} 
	} else {
		searchString = cs->getMatch();
	}
	
	//we don't have any nick to search for
	//happens in pm's have to find a solution for this
	if(searchString.empty())
		return tstring::npos;


	//do we want to highlight the timestamps?
	if( cs->getTimestamps() ) {
		if( line[0] != _T('[') )
			return tstring::npos;
		index = 0;
	} else if( cs->getUsers() ) {
		if(timeStamps) {
			index = line.find(_T("] <"));
			// /me might cause this to happen
			if(index == tstring::npos)
				return tstring::npos;
			//compensate for "] "
			index += 2;
		} else if( line[0] == _T('<')) {
			index = 0;
		}
	}else{
		if( cs->getCaseSensitive() ) {
			index = line.find(searchString, pos);
		}else {
			index = Util::findSubString(line, searchString, pos);	
			//index = Text::toLower(line).find(Text::toLower(searchString), pos);
		}
	}
	//return if no matches where found
	if( index == tstring::npos )
		return tstring::npos;

	pos = index + searchString.length();
	
	//found the string, now make sure it matches
	//the way the user specified
	int length;
		
	if( !cs->getUsers() && !cs->getTimestamps() ) {
		length = searchString.length();
		int p = 0;
			
		switch(cs->getMatchType()){
			case 0: //Begins
				p = index-1;
                if(line[p] != _T(' ') && line[p] != _T('\r') &&	line[p] != _T('\t') )
					return tstring::npos;
				break;
			case 1: //Contains
				break;
			case 2: // Ends
				p = index+length;
				if(line[p] != _T(' ') && line[p] != _T('\r') &&	line[p] != _T('\t') )
					return tstring::npos;
				break;
			case 3: // Equals
				if( !( (index == 0 || line[index-1] == _T(' ') || line[index-1] == _T('\t')) && 
					(line[index+length] == _T(' ') || line[index+length] == _T('\r') || 
					line[index+length] == _T('\t')) ) )
					return tstring::npos;
				break;
		}
	}

	long begin, end;

	begin = lineIndex;
		
	if( cs->getTimestamps() ) {
		tstring::size_type pos = line.find(_T("]"));
		if( pos == tstring::npos ) 
			return tstring::npos;  //hmm no ]? this can't be right, return
		
		begin += index +1;
		end = begin + pos -1;
	} else if( cs->getUsers() ) {
		end = begin + line.find(_T(">"));
		begin += index +1;
	} else if( cs->getWholeLine() ) {
		end = begin + line.length();
	} else if( cs->getWholeWord() ) {
		int tmp;

		tmp = line.find_last_of(_T(" \t\r"), index);
		if(tmp != tstring::npos )
			begin += tmp+1;
		
		tmp = line.find_first_of(_T(" \t\r"), index);
		if(tmp != tstring::npos )
			end = lineIndex + tmp;
		else
			end = lineIndex + line.length();
	} else {
		begin += index;
		end = begin + searchString.length();
	}

	SetSel(begin, end);
		
	SetSelectionCharFormat(cf);

	SetSel(GetTextLength()-1, GetTextLength()-1);
	SetSelectionCharFormat(selFormat);

	CheckAction(cs, line);

	if( cs->getTimestamps() || cs->getUsers() )
		return tstring::npos;
	
	return pos;
}