Пример #1
0
std::wstring CSVPToolBox::getVideoFileBasename(std::wstring szVidPath, std::vector<std::wstring>* szaPathInfo = NULL)
{

  //CPath szTPath(szVidPath.c_str());
  int posDot    = szVidPath.find_last_of(L'.');
  int posSlash  = szVidPath.find_last_of(L'\\');
  int posSlash2 = szVidPath.find_last_of(L'/');
  if (posSlash2 > posSlash)
    posSlash = posSlash2;

  if(posDot > posSlash)
  {
    if (szaPathInfo != NULL)
    {
      std::wstring szBaseName = szVidPath.substr(0, posDot);
      std::wstring szExtName  = szVidPath.substr(posDot, szVidPath.size() - posDot);
      std::transform(szExtName.begin(), szExtName.end(), szExtName.begin(),::tolower);
      std::wstring szFileName = szVidPath.substr(posSlash+1, (posDot - posSlash - 1));
      std::wstring szDirName  = szVidPath.substr(0, posSlash + 1);
      szaPathInfo -> clear();
      szaPathInfo -> push_back(szBaseName); // Base Name
        

      szaPathInfo -> push_back(szExtName ); //ExtName
      szaPathInfo -> push_back(szDirName); //Dir Name ()
      szaPathInfo -> push_back(szFileName); // file name only
      
    }
    return szVidPath.substr(posDot);
  }
  return szVidPath;
}
bool ClientRecipient::parseNamedEmail(const std::wstring & namedEmail) {

    bool success = false;

    size_t npos = std::wstring::npos;
    size_t leftParen = namedEmail.find_last_of(L'(');
    size_t rightParen = namedEmail.find_last_of(L')');

    // If its not formatted in the way we expect, we cant handle it
    if (leftParen != npos && rightParen != npos && rightParen == namedEmail.size()-1) {
        name = namedEmail.substr(0, leftParen);
        email = namedEmail.substr(leftParen+1,rightParen-leftParen-1);
        success = true;
    } else {
        size_t leftParen = namedEmail.find_last_of(L'<');
        size_t rightParen = namedEmail.find_last_of(L'>');
        // If its not formatted in the way we expect, we cant handle it
        if (leftParen != npos && rightParen != npos && rightParen == namedEmail.size()-1) {
            name = namedEmail.substr(0, leftParen);
            email = namedEmail.substr(leftParen+1,rightParen-leftParen-1);
            success = true;
        }
    }

    return success;
}
Пример #3
0
Syncer::Syncer(FileEventLoop* files,
               std::wstring leader,
               std::wstring follower) : m_files(files), m_leader(leader)
{
	m_leaderSyncer = makeSyncLeaderHandler(leader, follower);
	m_leaderDir = leader.substr(0, leader.find_last_of('\\') + 1);
    files->watch(m_leaderDir, m_leaderSyncer);
	
	// Eventually, the leader and the follower syncers will use custom logic.
	m_followerSyncer = makeSyncFollowerHandler(leader, follower);
	m_followerDir = follower.substr(0, follower.find_last_of('\\') + 1);
    files->watch(m_followerDir, m_followerSyncer);
}
Пример #4
0
bool ObjectImporter::Import(std::wstring file, ImportedObjectData* rawData)
{
	size_t first = file.find_last_of('\\') + 1;
	size_t last = file.find_last_of('.');
	rawData->name = file.substr(first, last-first);
	

	std::wifstream in (file);
	if(!in.is_open())
	{
		std::wstring msg = L"Failed to open file: \n";
		msg.append(file);
		MessageBox(0, msg.c_str(), L"Import error", 0);
		return false;
	}
	else
	{
		std::wstring buff;

		while (!in.eof())
		{
			in >> buff;

			if(buff.size())
			{
				if(buff == ObjImpFormat::animationCount) 
				{ 
					int count = 0;
					if(!ParseInteger(in, count))
						return false;

					if(count)
					{
						rawData->animations.resize(count);
						if(!ParseAnimationFile(in, rawData))
							return false;
					}
					else		
						if(!ParseStandardFile(in, rawData))
							return false;
				}
				else { ParseLine(in, true); }
			}
		}

		in.close();
	}

	return true;
}
Пример #5
0
std::wstring GetFilePath( const std::wstring& wsFullName )
{
	std::wstring::size_type nIndex1 = wsFullName.find_last_of(L"\\");
	std::wstring::size_type nIndex2 = wsFullName.find_last_of(L"/");
	if (std::wstring::npos == nIndex1)
	{
		nIndex1 = 0;
	}
	if (std::wstring::npos == nIndex2)
	{
		nIndex2 = 0;
	}
	std::wstring::size_type nIndex = max(nIndex1, nIndex2);
	return wsFullName.substr(0, nIndex);
}
Пример #6
0
int _tmain(int argc, _TCHAR* argv[])
{
    dir = argv[0];
    dir.resize(dir.find_last_of(_T("\\")) + 1);
    ::testing::InitGoogleTest(&argc, argv);
    return RUN_ALL_TESTS();
}
Пример #7
0
std::wstring UrlHighlightHtml(const std::wstring& message, bool& isUrl)
{
	std::wstring ret;
	std::wstring htmlStop = L"\'\" []<>\r\n";
	std::wstring search = L"://";
	size_t start = 0;
	size_t find;
	while ((find = message.find(search, start)) < message.length()) {
		size_t urlStart = message.find_last_of(htmlStop, find);
		size_t urlEnd = message.find_first_of(htmlStop, find + 3);
		if (urlStart >= message.length())
			urlStart = -1;
		if (urlEnd >= message.length())
			urlEnd = message.length();
		if (((int)urlEnd - 3 - (int)find > 0) && ((int)find - (int)urlStart - 1 > 0)) {
			ret += message.substr(start, (urlStart + 1) - start);
			std::wstring url = message.substr(urlStart + 1, urlEnd - urlStart - 1);
			start = urlEnd;
			ret += L"<a class=url target=_blank href=\"";
			ret += url + L"\">" + url + L"</a>";
			isUrl = true;
		}
		else {
			ret += message.substr(start, (find + 3) - start);
			start = find + 3;
		}
	}

	ret += message.substr(start, message.length() - start);
	return ret;
}
Пример #8
0
	GUID Picture::PictureTypeParser(const std::wstring & path)
	{
		auto pos = path.find_last_of(L'.');
		auto posfix = std::wstring(path.begin() + pos + 1,
			path.begin()+path.find_first_of(L'\0'));
		for (auto& c : posfix) 
			c = std::tolower(c);
		if (posfix == L"png")
		{
			return GUID_ContainerFormatPng;
		}
		else if (posfix == L"gif")
		{
			return GUID_ContainerFormatGif;
		}
		if (posfix == L"jpeg")
		{
			return GUID_ContainerFormatJpeg;
		}
		if (posfix == L"BMP")
		{
			return GUID_ContainerFormatBmp;
		}
		else assert(0);
		//return GUID_ContainerFormatPng;
	}
Пример #9
0
int archive_dump(std::wstring file, std::wstring application, std::wstring version, std::wstring date, std::wstring target) {
	try {
		if (!file_helpers::checks::exists(target)) {
			if (!boost::filesystem::create_directories(target)) {
				std::wcout << _T("Failed to create directory: ") << target << std::endl;
				return -1;
			}
			std::wcout << _T("Created folder: ") << target << std::endl;
		}
		if (!file_helpers::checks::is_directory(target)) {
			std::wcout << _T("Target is not a folder: ") << target << std::endl;
			return -1;
		}

		std::wstring fname = file.substr(file.find_last_of(_T("/\\")));
		boost::filesystem::copy_file(file, target + fname);
		std::wstring descfile = target + fname + _T(".txt");
		if (!write_desc(utf8::cvt<std::string>(descfile), utf8::cvt<std::string>(application), utf8::cvt<std::string>(version), utf8::cvt<std::string>(date))) {
			std::wcout << _T("Failed to write description: ") << target << fname << _T(".txt") << std::endl;
			return -1;
		}
		return 0;
	} catch (const std::exception &e) {
		std::cout << e.what() << std::endl;
		return -1;
	}
}
Пример #10
0
bool sspAudioFile::verifyValidExtension(const std::wstring& strFilename)
{
  if (s_extensions.empty()) {
    int nMajorCount;
	  sf_command (NULL, SFC_GET_FORMAT_MAJOR_COUNT, &nMajorCount, sizeof (int));

    SF_FORMAT_INFO info ;
    for (int i=0; i<nMajorCount; ++i) {
      info.format = i;
  		sf_command (NULL, SFC_GET_FORMAT_MAJOR, &info, sizeof (info));

			// Concert to Unibyte string
			size_t converted;
			wchar_t str[10];
			mbstowcs_s(&converted, str, 10, info.extension, _TRUNCATE);
      s_extensions.push_back(str);

      if (strcmp(info.extension, "aiff") == 0) s_extensions.push_back(_T("aif"));  // Hack to support Windows short form
    }
  }

  size_t nPos = strFilename.find_last_of(L".");
  std::wstring ext = strFilename.substr(nPos+1, strFilename.length() - nPos);
  std::vector<std::wstring>::iterator finder = find(s_extensions.begin(), s_extensions.end(), ext);
  return finder != s_extensions.end();
}
Пример #11
0
	std::wstring file_ext(const std::wstring& aPath)
	{
		std::wstring::size_type pos = aPath.find_last_of(L'.');
		if (pos != std::wstring::npos && pos != aPath.size() - 1)
			return aPath.substr(pos + 1);
		return L"";
	}
Пример #12
0
std::wstring GetFileNameExt(const std::wstring& fileName)
{
	auto it = fileName.find_last_of('.');
	if (it == fileName.npos)
		return std::wstring();
	return fileName.substr(it + 1);
}
Пример #13
0
    std::wstring getFileExt(const std::wstring & fname)
    {
        size_t pos = fname.find_last_of(L'.');
        if(pos != fname.npos) return fname.substr(pos + 1);

        return L"";
    }
Пример #14
0
 std::wstring extractName(const std::wstring & pathname)
     {
     size_t pos = pathname.find_last_of(L'\\');
     if (pos == std::wstring::npos) { return pathname; }
     if (pos == pathname.length() - 1) { return L""; }
     return(pathname.substr(pos + 1, std::wstring::npos));
     }
Пример #15
0
BOOL CCommonInterface::GetPathFromPath(std::wstring strAllPath, std::wstring & strPath)
{
	int nPos = strAllPath.find_last_of('\\');
	if (nPos > 0)
	{
		strPath = strAllPath.substr(0, nPos);
	}
	else
	{
		nPos = strAllPath.find_last_of('/');
		if (nPos > 0)
		{
			strPath = strAllPath.substr(0, nPos);
		}
	}
	return TRUE;
}
Пример #16
0
std::wstring RemoveExt(const std::wstring &fileName)
{
	size_t find = fileName.find_last_of(L'.');
	if (find < fileName.length())
		return fileName.substr(0, find);

	return fileName;
}
Пример #17
0
std::wstring GetName(const std::wstring &path)
{
	size_t find = path.find_last_of(L"\\/");
	if (find < path.length())
		return path.substr(find + 1);

	return path;
}
Пример #18
0
static std::wstring wbasename(const std::wstring &s) {
    const auto i = s.find_last_not_of(L"/");
    if (i == std::wstring::npos) {
        return s.empty() ? L"." : L"/";
    }
    const auto from = 1 + s.find_last_of(L"/", i); /* 1 + std::wstring::npos == 0 */
    return s.substr(from, i - from + 1);
}
Пример #19
0
			Helper() 
			{
				wchar_t szFilePath[MAX_PATH] = {0};
				::GetModuleFileNameW(NULL, szFilePath, _countof(szFilePath));
				strPath = szFilePath;
				size_t pos = strPath.find_last_of('\\');
				strPath = strPath.substr(0, pos + 1);
			}
Пример #20
0
static std::wstring suffix_of(const std::wstring &name)
{
    const size_t ldot = name.find_last_of(L'.');
    if (ldot != name.npos)
        return name.substr(ldot);

    return name;
}
Пример #21
0
void IfcPPReaderSTEP::loadModelFromFile( const std::wstring& file_path, shared_ptr<IfcPPModel>& target_model )
{
	// if file content needs to be loaded into a plain model, call resetModel() before loadModelFromFile
	
	std::wstring ext = file_path.substr( file_path.find_last_of( L"." ) + 1 );
	
	if( boost::iequals( ext, "ifc" ) )
	{
		// ok, nothing to do here
	}
	else if( boost::iequals( ext, "ifcXML" ) )
	{
		// TODO: implement xml reader
		messageCallback( "ifcXML not yet implemented", StatusCallback::MESSAGE_TYPE_ERROR, __FUNC__ );
		return;
	}
	else if( boost::iequals( ext, "ifcZIP" ) )
	{
		// TODO: implement zip uncompress
		messageCallback( "ifcZIP not yet implemented", StatusCallback::MESSAGE_TYPE_ERROR, __FUNC__ );
		return;
	}
	else
	{
		std::wstringstream strs;
		strs << "Unsupported file type: " << ext;
		messageCallback( strs.str().c_str(), StatusCallback::MESSAGE_TYPE_ERROR, __FUNC__ );
		return;
	}

	// open file
#ifdef _MSC_VER
	std::ifstream infile(file_path.c_str(), std::ifstream::in );
#else
	std::string file_path_str( file_path.begin(), file_path.end() );
	std::ifstream infile(file_path_str.c_str(), std::ifstream::in );
#endif
	if( !infile.is_open() )
	{
		std::wstringstream strs;
		strs << "Could not open file: " << file_path.c_str();
		messageCallback( strs.str().c_str(), StatusCallback::MESSAGE_TYPE_ERROR, __FUNC__ );
		return;
	}

	// get length of file content
	std::streampos file_size = infile.tellg();
	infile.seekg( 0, std::ios::end );
	file_size = infile.tellg() - file_size;
	infile.seekg( 0, std::ios::beg );

	// read file content into string
	std::string buffer( (int)file_size, '\0' );
	infile.read( &buffer[0], file_size );
	infile.close();

	loadModelFromString( buffer, target_model );
}
Пример #22
0
std::wstring PakReader::getFileNameByPakNumber(std::wstring& fileName, long pakNumber) {
	if (pakNumber == 0) {
		return fileName;
	}
	long lastDot = fileName.find_last_of(L".");
	std::wstringstream result;
	result<<fileName.substr(0, lastDot)<<L"_"<<pakNumber<<L".pak";
	return result.str();
}
Пример #23
0
std::wstring GetFilePart(const std::wstring& path)
{
	UIETWASSERT(path.size() > 0);
	const size_t lastSlash = path.find_last_of(L'\\');
	if (lastSlash != std::wstring::npos)
		return path.substr(lastSlash);
	// If there's no slash then the file part is the entire string.
	return path;
}
Пример #24
0
std::wstring GetFileExt(const std::wstring& path)
{
	const std::wstring filePart = GetFilePart(path);
	const size_t lastPeriod = filePart.find_last_of(L'.');
	if (lastPeriod != std::wstring::npos)
		return filePart.substr(lastPeriod);
	// If there's no period then there's no extension.
	return L"";
}
Пример #25
0
static std::wstring trim_prefix(const std::wstring &devicename)
{
	// remove anything prior to the final semicolon
	auto semicolon_index = devicename.find_last_of(';');
	if (semicolon_index != std::wstring::npos)
		return devicename.substr(semicolon_index + 1);

	return devicename;
}
Пример #26
0
std::wstring Enviroment::getPath(const std::wstring& Filepath)
{
	if (Filepath.length() == 0)
	{
		return L"";
	}

	auto found = Filepath.find_last_of(L"/\\");
	return Filepath.substr(0, found);
}
Пример #27
0
//----------------------------------------------------------------------------------------------
std::wstring getPathFileName(const std::wstring &fullString)
{
	size_t idx_find = fullString.find_last_of(L"/\\");

	if (idx_find != std::wstring::npos)
	{
		return fullString.substr(idx_find + 1);
	}
	return fullString;
}
Пример #28
0
/*
** Returns path without filename.
**
*/
std::wstring CCover::GetFileFolder(const std::wstring& file)
{
	std::wstring::size_type pos = file.find_last_of(L'\\');
	if (pos != std::wstring::npos)
	{
		return file.substr(0, ++pos);
	}

	return file;
}
Пример #29
0
std::wstring GetMimeType2(const std::wstring& url_without_query) {
	std::wstring mime_type;
	size_t sep = url_without_query.find_last_of(L".");
	if (sep != std::wstring::npos) {
		mime_type = CefGetMimeType(url_without_query.substr(sep + 1));
		if (!mime_type.empty())
			return mime_type;
	}
	return L"text/html";
}
Пример #30
0
void http_request_simple::push_post_form_filedata(const std::wstring& name, const std::wstring& file_name)
{
    assert(!name.empty());
    assert(!file_name.empty());
    file_binary_stream file_data;
    file_data.file_name_ = file_name.substr(file_name.find_last_of(L"\\/") + 1);
    file_data.file_stream_.load_from_file(file_name);
    if (file_data.file_stream_.available())
        post_form_filedatas_.insert(std::make_pair(tools::from_utf16(name), file_data));
}