Esempio n. 1
0
VectorString UtilString::split(const string &str, const string &delim /* =  */, uint32_t maxSplits /* = 0 */)
{
	VectorString ret;

	uint32_t numSplits = 0;

	size_t start = 0;
	size_t pos = 0;
	do
	{
		pos = str.find_first_of(delim, start);
		if (pos == start)
		{
			ret.push_back("");
			start = pos + 1;
		}
		else if (pos == string::npos || (maxSplits && numSplits == maxSplits))
		{
			ret.push_back(str.substr(start));
			break;
		}
		else
		{
			ret.push_back(str.substr(start, pos - start));
			start = pos + 1;
		}

		++numSplits;

	} while (pos != string::npos);

	return ret;
}
Esempio n. 2
0
	const VectorString& Ogre2DataManager::getDataListNames(const std::string& _pattern, bool _fullpath)
	{
		static VectorString result;
		result.clear();

		VectorString search;
		if (mAllGroups)
		{
			Ogre::StringVector sp = Ogre::ResourceGroupManager::getSingleton().getResourceGroups();
			search.reserve(sp.size());
			for (size_t i = 0; i < sp.size(); i++)
				search.push_back(sp[i]);
		}
		else
			search.push_back(mGroup);

		std::vector<Ogre::FileInfoListPtr> pFileInfos;

		int resultSize = 0;
		for (size_t i = 0; i < search.size(); i++)
		{
			Ogre::FileInfoListPtr pFileInfo = Ogre::ResourceGroupManager::getSingleton().findResourceFileInfo(search[i], _pattern);
			resultSize += pFileInfo->size();
			if (!pFileInfo->empty())
				pFileInfos.push_back(pFileInfo);
			else
				pFileInfo.setNull();
		}

		result.reserve(resultSize);

		for (size_t i = 0; i < pFileInfos.size(); i++)
		{
			Ogre::FileInfoListPtr pFileInfo = pFileInfos[i];
			for (Ogre::FileInfoList::iterator fi = pFileInfo->begin(); fi != pFileInfo->end(); ++fi )
			{
				if (fi->path.empty())
				{
					bool found = false;
					for (VectorString::iterator iter = result.begin(); iter != result.end(); ++iter)
					{
						if (*iter == fi->filename)
						{
							found = true;
							break;
						}
					}
					if (!found)
					{
						result.push_back(_fullpath ? fi->archive->getName() + "/" + fi->filename : fi->filename);
					}
				}
			}

			pFileInfo.setNull();
		}

		return result;
	}
	const std::string& ExportDataManager::getDataPath(const std::string& _name)
	{
		static std::string path;
		VectorString result;
		common::VectorWString wresult;

		for (VectorArhivInfo::const_iterator item = mPaths.begin(); item != mPaths.end(); ++item)
		{
			common::scanFolder(wresult, (*item).name, (*item).recursive, MyGUI::UString(_name).asWStr(), true);
		}

		for (common::VectorWString::const_iterator item = wresult.begin(); item != wresult.end(); ++item)
		{
			result.push_back(MyGUI::UString(*item).asUTF8());
		}

		if (!result.empty())
		{
			path = result[0];
			if (result.size() > 1)
			{
				MYGUI_PLATFORM_LOG(Warning, "There are several files with name '" << _name << "'. '" << path << "' was used.");
				MYGUI_PLATFORM_LOG(Warning, "Other candidater are:");
				for (size_t index = 1; index < result.size(); index ++)
					MYGUI_PLATFORM_LOG(Warning, " - '" << result[index] << "'");
			}
		}

		return path;
	}
	const VectorString& OgreDataManager::getDataListNames(const std::string& _pattern, bool _fullpath)
	{
		static VectorString result;
		result.clear();

		Ogre::FileInfoListPtr pFileInfo = Ogre::ResourceGroupManager::getSingleton().findResourceFileInfo(mGroup, _pattern);

		result.reserve(pFileInfo->size());

		for (Ogre::FileInfoList::iterator fi = pFileInfo->begin(); fi != pFileInfo->end(); ++fi )
		{
			if (fi->path.empty())
			{
				bool found = false;
				for (VectorString::iterator iter = result.begin(); iter != result.end(); ++iter)
				{
					if (*iter == fi->filename)
					{
						found = true;
						break;
					}
				}
				if (!found)
				{
					result.push_back(_fullpath ? fi->archive->getName() + "/" + fi->filename : fi->filename);
				}

			}
		}

		pFileInfo.setNull();

		return result;
	}
	const VectorString& ExportDataManager::getDataListNames(const std::string& _pattern)
	{
		static VectorString result;
		common::VectorWString wresult;
		result.clear();

		for (VectorArhivInfo::const_iterator item = mPaths.begin(); item != mPaths.end(); ++item)
		{
			common::scanFolder(wresult, (*item).name, (*item).recursive, MyGUI::UString(_pattern).asWStr(), false);
		}

		for (common::VectorWString::const_iterator item = wresult.begin(); item != wresult.end(); ++item)
		{
			result.push_back(MyGUI::UString(*item).asUTF8());
		}

		return result;
	}
	const std::string& HGEDataManager::getDataPath(const std::string& _name)
	{
		static std::string path;
		VectorString result;
		common::VectorWString wresult;

		for (VectorArhivInfo::const_iterator item = mPaths.begin(); item != mPaths.end(); ++item)
		{
			common::scanFolder(wresult, (*item).name, (*item).recursive, MyGUI::UString(_name).asWStr(), true);
		}

		for (common::VectorWString::const_iterator item = wresult.begin(); item != wresult.end(); ++item)
		{
			result.push_back(MyGUI::UString(*item).asUTF8());
		}

		path = result.size() == 1 ? result[0] : "";
		return path;
	}
Esempio n. 7
0
bool DAOProxy::split(const string& str, VectorString& array)
{
    //ACS_TRACE("cdb::DAOProxy::split");

    // The string that will be added to the list next.
    string strCur; 
    // Tells us what kind of quote we are in.
    bool bQuote = 0;

    unsigned int iter = 0;
    unsigned int len = str.length();

    array.clear();

    while(iter < len)
	{
	// We got to a whitespace and we are not in a quote: push the currently
	// build substring at the end of the array.
	if(!bQuote && str[iter] == ',')
	    {
	    if(strCur.length()!=0)
		{
		array.push_back(strCur);
		strCur.erase(strCur.begin(), strCur.end());  // using erase because clear not supported on VxWorks
		}
	    }
	// Escape sequence.
	else if(str[iter] == '\\')      
	    {
	    ++iter;
	    // Whoops, escape ended before the new line.
	    if(iter == len) 
		{
		return false;
		}
	    switch(str[iter])
		{
		case 'n':
		    strCur += '\n';
		    break;
		case 'r':
		    strCur += '\r';
		    break;
		case ',':
		case '\\':
		case '\'':
		case '"':
		    // Treat next character verbatim, regardless what it may be.
		    strCur += str[iter];
		    break;
		default:
		    // An unrecognized escape!
		    return false;
		}
	    }
	// The quote ended.
	else if(bQuote && str[iter] == '"')
	    {
	    // Indicate that we are in the quote no longer.
	    bQuote = 0;
	    array.push_back(strCur);
	    strCur.erase(strCur.begin(), strCur.end());  // using erase because clear not supported on VxWorks
	    }
	// The quote begun.
	else if(str[iter] == '"')
	    {
	    if(strCur.length()!=0)
		{
		array.push_back(strCur);
		strCur.erase(strCur.begin(), strCur.end()); // using erase because clear not supported on VxWorks 
		}
	    bQuote = 1;
	    }
	else
	    {
	    // A regular character.
	    strCur += str[iter];
	    }
	++iter;
	}

    // Push the last string to the end of the array.
    if(strCur.length()!=0)
	{
	array.push_back(strCur);
	}

    return true;
}