예제 #1
0
파일: data.cpp 프로젝트: 5thAvenue/OpenApoc
std::string findInDir(std::string parent, std::list<std::string> remainingPath, const char DIR_SEP)
{
	Directory d(parent);
	std::string name = remainingPath.front();
	remainingPath.pop_front();
	//Strip out any excess blank entries (otherwise paths like "./directory//file" would break)
	while (name == "")
	{
		if (remainingPath.empty())
			return parent;
		name = remainingPath.front();
		remainingPath.pop_front();
	}
	struct dirent entry , *result = NULL;
	while (true)
	{
		int err = readdir_r(d.d, &entry, &result);
		if (err)
		{
			std::cerr << "Readdir() failed with \"" << err << "\"\n";
			return "";
		}
		if (!result)
		{
			break;
		}
		std::string entName(entry.d_name);
		if (Strings::CompareCaseInsensitive(name, entName) == 0)
		{
			std::string entPath = parent + DIR_SEP + entName;
			if (remainingPath.empty())
				return entPath;
			else
				return findInDir(entPath, remainingPath, DIR_SEP);
		}
	}
	return "";
}
예제 #2
0
/**
	Convert entity to xml dom document
   	\param preferAttrib - if true (default) generate attributes, else elements
	... <attr name="atrname" val="atrVal"/> ... vs <atrname>atrVal<atrname/>
	\param skipEmpty	- if true (default) skip empty values
	\param upperCase	- if true - uppercase all tags (default is false)
	\return Dom document reference
*/
QDomDocument& RecordBase::GetDom
(
	bool preferAttrib,
	bool skipEmpty,
	bool upperCase
)
{
	QString idTag(kTagID);
	QString attrTag(kTagAttr);
	QString nameTag(kTagName);
	QString valTag(kTagValue);
	QString entName(EntityName());

	if (upperCase) 
	{
		entName = entName.toUpper();
		idTag   = idTag.toUpper();
		attrTag = attrTag.toUpper();
		nameTag = nameTag.toUpper();
		valTag  = valTag.toUpper();
	}

	if (_xmlDoc)
		delete _xmlDoc;

	QDomElement root;

	_xmlDoc = new QDomDocument;
	
	root = _xmlDoc->createElement(entName);
    _xmlDoc->appendChild(root);
	// append id attrib to root

	root.setAttribute(idTag, Key());
	// enumerate fields
	for (quint32 i(1); i < Count(); i++) 
	{
		QString name = Field(i);
		QString v = Value(i).toString().trimmed();
		
		if (v.length() > 0 || (v.length() == 0 && !skipEmpty)) 
		{
			if (upperCase) 
				name = name.toUpper();

			if (preferAttrib) 
			{
				QDomElement elem = _xmlDoc->createElement(attrTag);
				elem.setAttribute(nameTag, name);
				elem.setAttribute(valTag , v);
				root.appendChild (elem);
			}
			else // use elements
			{
				
				QDomElement elem = _xmlDoc->createElement(name);
				QDomText txt  = _xmlDoc->createTextNode(v);
				elem.appendChild(txt);
				root.appendChild(elem);
			}
		}
	}

	return *_xmlDoc;
}