QStringList KStandardDirs::findAllResources( const char *type, const QString& filter, bool recursive, bool unique, QStringList &relList) const { QStringList list; QString filterPath; QString filterFile; if (filter.length()) { int slash = filter.findRev('/'); if (slash < 0) filterFile = filter; else { filterPath = filter.left(slash + 1); filterFile = filter.mid(slash + 1); } } checkConfig(); QStringList candidates; if (!QDir::isRelativePath(filter)) // absolute path { #ifdef Q_OS_WIN candidates << filterPath.left(3); //e.g. "C:\" filterPath = filterPath.mid(3); #else candidates << "/"; filterPath = filterPath.mid(1); #endif } else { if (d && d->restrictionsActive && (strcmp(type, "data")==0)) applyDataRestrictions(filter); candidates = resourceDirs(type); } if (filterFile.isEmpty()) filterFile = "*"; QRegExp regExp(filterFile, true, true); for (QStringList::ConstIterator it = candidates.begin(); it != candidates.end(); ++it) { lookupPrefix(*it, filterPath, "", regExp, list, relList, recursive, unique); } return list; }
static errorCode sample_startElement(QName qname, void* app_data) { struct appData* appD = (struct appData*) app_data; if(appD->outputFormat == OUT_EXI) { printf("SE "); printString(qname.uri); printf(" "); printString(qname.localName); printf("\n"); } else if(appD->outputFormat == OUT_XML) { char error = 0; unsigned char prefixIndex = 0; unsigned char prxHit = 1; int t; if(!isStringEmpty(qname.uri)) { error = lookupPrefix(appD, *qname.uri, &prxHit, &prefixIndex); if(error != 0) return EXIP_HANDLER_STOP; sprintf(appD->nameBuf, "p%d:", prefixIndex); t = strlen(appD->nameBuf); memcpy(appD->nameBuf + t, qname.localName->str, qname.localName->length); appD->nameBuf[t + qname.localName->length] = '\0'; } else { memcpy(appD->nameBuf, qname.localName->str, qname.localName->length); appD->nameBuf[qname.localName->length] = '\0'; } push(&(appD->stack), createElement(appD->nameBuf)); if(appD->unclosedElement) printf(">\n"); printf("<%s", appD->nameBuf); if(prxHit == 0) { sprintf(appD->nameBuf, " xmlns:p%d=\"", prefixIndex); printf("%s", appD->nameBuf); printString(qname.uri); printf("\""); } appD->unclosedElement = 1; } return ERR_OK; }
/** * @brief Callback called when the EXIP library has found the start of an element * @param qname The qualified name of the element * @param app_data Pointer to the struct appData passed to initParser() * @return EXIP_HANDLER_OK if success, or EXIP_HANDLER_STOP if need to stop the parser */ static errorCode sample_startElement(QName qname, void* app_data) { struct appData* appD = (struct appData*) app_data; char error = 0; unsigned char prefixIndex = 0; unsigned char prxHit = 1; int t = 0; PRINT ("SE "); writeQName(qname); PRINT ("\n"); // Check if we where in another element. If yes, calls cb_startElement checkCallback (appD, 0); if(!isStringEmpty(qname.uri)) { char uri[200]; char pfx[30]; error = lookupPrefix(appD, *qname.uri, &prxHit, &prefixIndex); if (error) { fprintf (stderr, "Prefix not found\n"); return EXIP_HANDLER_STOP; } copyString(*qname.uri, uri); strcpy (pfx, getPrefixByNamespace(uri)); strcpy (appD->nameBuf, pfx); strcat (appD->nameBuf, ":"); t = strlen(appD->nameBuf); if(prxHit == 0) { // Create xmlns: attribute t_ctxt *ctxt = &appD->ctxt; char tmp[30]; strcpy (tmp, "xmlns:"); strcat (tmp, pfx); ctxt->atname[ctxt->atcount] = strdup(tmp); ctxt->atvalue[ctxt->atcount] = StringStrdup(qname.uri); ctxt->atcount++; } } memcpy(appD->nameBuf + t, qname.localName->str, qname.localName->length); appD->nameBuf[t + qname.localName->length] = '\0'; push(&(appD->stack), createElement(appD->nameBuf)); appD->unclosedElement = 1; return ERR_OK; }
void runTests(){ //TODO const char* running = nullptr; unittest(Scope){ auto scope = new Scope(0); assert(!scope->lookupPrefix("foo")); assert(!scope->lookupPrefix("bar")); assert(!scope->lookupInfix("bar")); assert(!scope->lookupInfix("foo")); assert(!scope->containsPrefix("foo")); assert(!scope->containsPrefix("bar")); assert(!scope->containsInfix("bar")); assert(!scope->containsInfix("foo")); delete scope; } unittest(_theEndDummy); }
const XMLCh* DOMNodeImpl::lookupPrefix(const XMLCh* namespaceURI) const { // REVISIT: When Namespaces 1.1 comes out this may not be true // Prefix can't be bound to null namespace if (namespaceURI == 0) { return 0; } DOMNode *thisNode = castToNode(this); short type = thisNode->getNodeType(); switch (type) { case DOMNode::ELEMENT_NODE: { return lookupPrefix(namespaceURI, (DOMElement*)thisNode); } case DOMNode::DOCUMENT_NODE:{ return ((DOMDocument*)thisNode)->getDocumentElement()->lookupPrefix(namespaceURI); } case DOMNode::ENTITY_NODE : case DOMNode::NOTATION_NODE: case DOMNode::DOCUMENT_FRAGMENT_NODE: case DOMNode::DOCUMENT_TYPE_NODE: // type is unknown return 0; case DOMNode::ATTRIBUTE_NODE:{ if (fOwnerNode->getNodeType() == DOMNode::ELEMENT_NODE) { return fOwnerNode->lookupPrefix(namespaceURI); } return 0; } default:{ DOMNode *ancestor = getElementAncestor(thisNode); if (ancestor != 0) { return ancestor->lookupPrefix(namespaceURI); } return 0; } } }
static void lookupPrefix(const QString& prefix, const QString& relpath, const QString& relPart, const QRegExp ®exp, QStringList& list, QStringList& relList, bool recursive, bool unique) { if (relpath.isEmpty()) { lookupDirectory(prefix, relPart, regexp, list, relList, recursive, unique); return; } QString path; QString rest; if (relpath.length()) { int slash = relpath.find('/'); if (slash < 0) rest = relpath.left(relpath.length() - 1); else { path = relpath.left(slash); rest = relpath.mid(slash + 1); } } if (prefix.isEmpty()) //for sanity return; #ifdef Q_WS_WIN assert(prefix.at(prefix.length() - 1) == '/' || prefix.at(prefix.length() - 1) == '\\'); #else assert(prefix.at(prefix.length() - 1) == '/'); #endif KDE_struct_stat buff; if (path.contains('*') || path.contains('?')) { QRegExp pathExp(path, true, true); DIR *dp = opendir( QFile::encodeName(prefix) ); if (!dp) { return; } struct dirent *ep; QString _dot("."); QString _dotdot(".."); while( ( ep = readdir( dp ) ) != 0L ) { QString fn( QFile::decodeName(ep->d_name)); if (fn == _dot || fn == _dotdot || fn.at(fn.length() - 1) == '~') continue; if ( !pathExp.exactMatch(fn) ) continue; // No match QString rfn = relPart+fn; fn = prefix + fn; if ( KDE_stat( QFile::encodeName(fn), &buff ) != 0 ) { kdDebug() << "Error statting " << fn << " : " << perror << endl; continue; // Couldn't stat (e.g. no permissions) } if ( S_ISDIR( buff.st_mode )) lookupPrefix(fn + '/', rest, rfn + '/', regexp, list, relList, recursive, unique); } closedir( dp ); } else { // Don't stat, if the dir doesn't exist we will find out // when we try to open it. lookupPrefix(prefix + path + '/', rest, relPart + path + '/', regexp, list, relList, recursive, unique); } }