static generic_string removeTrailingSlash(generic_string path)
{
	if (path.length() >= 1 && path[path.length() - 1] == '\\')
		return path.substr(0, path.length() - 1);
	else
		return path;
}
Beispiel #2
0
generic_string PathAppend(generic_string &strDest, const generic_string str2append)
{
    if (strDest == TEXT("") && str2append == TEXT("")) // "" + ""
    {
        strDest = TEXT("\\");
        return strDest;
    }

    if (strDest == TEXT("") && str2append != TEXT("")) // "" + titi
    {
        strDest = str2append;
        return strDest;
    }

    if (strDest[strDest.length() - 1] == '\\' && (str2append != TEXT("") && str2append[0] == '\\')) // toto\ + \titi
    {
        strDest.erase(strDest.length() - 1, 1);
        strDest += str2append;
        return strDest;
    }

    if ((strDest[strDest.length() - 1] == '\\' && (str2append != TEXT("") && str2append[0] != '\\')) // toto\ + titi
            || (strDest[strDest.length() - 1] != '\\' && (str2append != TEXT("") && str2append[0] == '\\'))) // toto + \titi
    {
        strDest += str2append;
        return strDest;
    }

    // toto + titi
    strDest += TEXT("\\");
    strDest += str2append;

    return strDest;
}
Beispiel #3
0
void filename::set_extension(const generic_string& name)
{
    // the extension in 'name' is the last
    // .suffix
    uint32 insertPos;
    // find the beginning of the current extension
    insertPos = _name.length()>0 ? _name.length()-1 : 0;
    while (insertPos>0 && _name[insertPos]!='.')
        --insertPos;
    if (insertPos<_name.length() && _name[insertPos]!='.')
        insertPos = _name.length();
    // remove the current extension
    _name.truncate(insertPos);
    // look at the specified extension
    if (name.length() > 0)
    {
        // find the beginning of the specified extension
        uint32 j = name.length()-1;
        while (j>0 && name[j]!='.')
            --j;
        if (name[j] == '.') // found extension
        {
            _name += '.';
            for (;j<name.length();j++) // apply specified extension
                _name.push_back( name[j] );
        }
    }
}
static generic_string addTrailingSlash(generic_string path)
{
	if (path.length() >=1 && path[path.length() - 1] == '\\')
		return path;
	else
		return path + L"\\";
}
generic_string stringReplace(generic_string subject, const generic_string& search, const generic_string& replace)
{
	size_t pos = 0;
	while ((pos = subject.find(search, pos)) != std::string::npos)
	{
		subject.replace(pos, search.length(), replace);
		pos += replace.length();
	}
	return subject;
}
void FileBrowser::addRootFolder(generic_string rootFolderPath)
{
	// make sure there's no '\' at the end
	if (rootFolderPath[rootFolderPath.length() - 1] == '\\')
	{
		rootFolderPath = rootFolderPath.substr(0, rootFolderPath.length() - 1);
	}

	size_t nbFolderUpdaters = _folderUpdaters.size();
	for (size_t i = 0; i < nbFolderUpdaters; ++i)
	{
		if (_folderUpdaters[i]->_rootFolder._rootPath == rootFolderPath)
			return;
		else
		{
			size_t pos = rootFolderPath.find(_folderUpdaters[i]->_rootFolder._rootPath);
			if (pos == 0)
			{
				//do nothing, go down to select the dir
				generic_string rootPath = _folderUpdaters[i]->_rootFolder._rootPath;
				generic_string pathSuffix = rootFolderPath.substr(rootPath.size() + 1, rootFolderPath.size() - rootPath.size());
				vector<generic_string> linarPathArray = split(pathSuffix, '\\');
				
				HTREEITEM foundItem = findInTree(rootPath, nullptr, linarPathArray);
				if (foundItem)
					_treeView.selectItem(foundItem);
				return;
			}
			
			pos = _folderUpdaters[i]->_rootFolder._rootPath.find(rootFolderPath);
			if (pos == 0)
			{
				::MessageBox(_hParent, TEXT("A sub-folder of the folder you want to open exists.\rPlease remove it from the panel before you add this one."), rootFolderPath.c_str(), MB_OK);
				return;
			}
		}
	}

	std::vector<generic_string> patterns2Match;
 	patterns2Match.push_back(TEXT("*.*"));

	TCHAR *label = ::PathFindFileName(rootFolderPath.c_str());
	TCHAR rootLabel[MAX_PATH];
	lstrcpy(rootLabel, label);
	size_t len = lstrlen(rootLabel);
	if (rootLabel[len - 1] == '\\')
		rootLabel[len - 1] = '\0';

	FolderInfo directoryStructure(rootLabel, nullptr);
	getDirectoryStructure(rootFolderPath.c_str(), patterns2Match, directoryStructure, true, false);
	HTREEITEM hRootItem = createFolderItemsFromDirStruct(nullptr, directoryStructure);
	_treeView.expand(hRootItem);
	_folderUpdaters.push_back(new FolderUpdater(directoryStructure, this));
	_folderUpdaters[_folderUpdaters.size() - 1]->startWatcher();
}
Beispiel #7
0
void filename::set_name(const generic_string& name,const generic_string& extension)
{
    // treat extension as a suffix
    uint32 start = 0;
    _name = name;
    // move past any dots before the extension
    while (start<extension.length() && extension[start]=='.')
        ++start;
    _name += '.';
    for (;start<extension.length();start++)
        _name += extension[start];
}
void FileBrowser::addRootFolder(generic_string rootFolderPath)
{
	// make sure there's no '\' at the end
	if (rootFolderPath[rootFolderPath.length() - 1] == '\\')
	{
		rootFolderPath = rootFolderPath.substr(0, rootFolderPath.length() - 1);
	}

	size_t nbFolderUpdaters = _folderUpdaters.size();
	for (size_t i = 0; i < nbFolderUpdaters; ++i)
	{
		if (_folderUpdaters[i]->_rootFolder._rootPath == rootFolderPath)
			return;
		else
		{
			size_t pos = rootFolderPath.find(_folderUpdaters[i]->_rootFolder._rootPath);
			if (pos == 0)
			{
				printStr(TEXT("do nothing, go down to select the dir."));
				
				return;
			}
			
			pos = _folderUpdaters[i]->_rootFolder._rootPath.find(rootFolderPath);
			if (pos == 0)
			{
				printStr(TEXT("remove old, add this one"));
				return;
			}
		}
	}

	std::vector<generic_string> patterns2Match;
 	patterns2Match.push_back(TEXT("*.*"));

	TCHAR *label = ::PathFindFileName(rootFolderPath.c_str());
	TCHAR rootLabel[MAX_PATH];
	lstrcpy(rootLabel, label);
	size_t len = lstrlen(rootLabel);
	if (rootLabel[len - 1] == '\\')
		rootLabel[len - 1] = '\0';

	FolderInfo directoryStructure(rootLabel, nullptr);
	getDirectoryStructure(rootFolderPath.c_str(), patterns2Match, directoryStructure, true, false);
	HTREEITEM hRootItem = createFolderItemsFromDirStruct(nullptr, directoryStructure);
	_treeView.expand(hRootItem);
	_folderUpdaters.push_back(new FolderUpdater(directoryStructure, this));
	_folderUpdaters[_folderUpdaters.size() - 1]->startWatcher();
}
Beispiel #9
0
static void replaceStr(generic_string & str, generic_string str2BeReplaced, generic_string replacement)
{
	size_t pos = str.find(str2BeReplaced);

	if (pos != generic_string::npos)
		str.replace(pos, str2BeReplaced.length(), replacement);
}
Beispiel #10
0
void path::append_before(const generic_string& n)
{
    str top = get_top_name();
    str par = get_parent_name();
    _parts[0] = top;
    _parts[1].clear();
    if (n.length()>0 && n[0]==PATH_SEP)
        (_parts[1] += par) += n;
    else
        ((_parts[1] += par) += PATH_SEP) += n;
    _checkParts();
}
Beispiel #11
0
void filename::set_namex(const generic_string& name)
{
    // set just the name part of 'name'
    // the extension is the last .suffix
    if (name.length() > 0)
    {
        uint32 i = name.length()-1;
        while (i>0 && name[i]!='.')
            --i;
        if (name[i] == '.')
        {
            // set name excluding extension
            _name.clear();
            for (uint32 j = 0;j<i;j++)
                _name.push_back( name[j] );
        }
        else // no extension was specified
            _name = name;
    }
    else // no name specified
        _name.clear();
}
Beispiel #12
0
static generic_string exts2Filters(generic_string exts)
{
	const TCHAR *extStr = exts.c_str();
	TCHAR aExt[MAX_PATH];
	generic_string filters(TEXT(""));

	int j = 0;
	bool stop = false;
	for (size_t i = 0 ; i < exts.length() ; i++)
	{
		if (extStr[i] == ' ')
		{
			if (!stop)
			{
				aExt[j] = '\0';
				stop = true;

				if (aExt[0])
				{
					filters += TEXT("*.");
					filters += aExt;
					filters += TEXT(";");
				}
				j = 0;
			}
		}
		else
		{
			aExt[j] = extStr[i];
			stop = false;
			j++;
		}
	}

	if (j > 0)
	{
		aExt[j] = '\0';
		if (aExt[0])
		{
			filters += TEXT("*.");
			filters += aExt;
			filters += TEXT(";");
		}
	}

	// remove the last ';'
	filters = filters.substr(0, filters.length()-1);
	return filters;
}
std::vector<generic_string> stringSplit(const generic_string& input, const generic_string& delimiter)
{
	auto start = 0U;
	auto end = input.find(delimiter);
	std::vector<generic_string> output;
	const size_t delimiterLength = delimiter.length();
	while (end != std::string::npos)
	{
		output.push_back(input.substr(start, end - start));
		start = end + delimiterLength;
		end = input.find(delimiter, start);
	}
	output.push_back(input.substr(start, end));
	return output;
}
vector<generic_string> split(const generic_string & string2split, TCHAR sep)
{
	vector<generic_string> splitedStrings;
	size_t len = string2split.length();
	size_t beginPos = 0;
	for (size_t i = 0; i < len + 1; ++i)
	{
		if (string2split[i] == sep || string2split[i] == '\0')
		{
			splitedStrings.push_back(string2split.substr(beginPos, i - beginPos));
			beginPos = i + 1;
		}
	}
	return splitedStrings;
};
Beispiel #15
0
// change string to lower-case variant
void rtypes::rutil_to_lower_ref(generic_string& sobj)
{
    for (size_type i = 0;i<sobj.length();i++)
        if (sobj[i]>='A' && sobj[i]<='Z')
            sobj[i] -= 'A', sobj[i] += 'a';
}