// construct an ebucore skeleton ebucoreParser::ElementStruct ebucoreParser::constructSchema(xercesc::DOMElement * el) { // prepare the element information std::string str (xercesc::XMLString::transcode(el->getAttribute (xercesc::XMLString::transcode("name")))); std::string type (xercesc::XMLString::transcode(el->getAttribute (xercesc::XMLString::transcode("type")))); std::string ref (xercesc::XMLString::transcode(el->getAttribute (xercesc::XMLString::transcode("ref")))); std::string minimum (xercesc::XMLString::transcode(el->getAttribute (xercesc::XMLString::transcode("minOccurs")))); std::string maximum (xercesc::XMLString::transcode(el->getAttribute (xercesc::XMLString::transcode("maxOccurs")))); // instantiate a new root ebucoreParser::ElementStruct root; // grab the name, the cardinalities, the type, attributes and children root.name = (str.size()>0)?str:ref; root.minCardinality = ((minimum.size()>0)?atoi(minimum.c_str()):1); root.maxCardinality = ((maximum.size()>0)?isUnbounded(maximum):1); root.type = ((type.size()>0)?type:"undefined"); // store the current element type inside the stack to avoid infinite loops ebucoreStack.push_back(root.type); // generate the attributes of the current element root.attribute = ebucoreParser::generateAttributes(removePrefix (type, ":"), el); // generate the children of the current element root.children = generateChildren(removePrefix (type, ":"), el,1); // pop the current element type outside of the stack ebucoreStack.pop_back(); return root; }
bool Popt::extractPackageAndVersionFromString(std::string &pname, Version &v) const { removePrefix(pname, _tp.getMainPackageDir().string()); removePrefix(pname, "/usr/src/"); removePrefix(pname, "/"); const size_t i = pname.find(':'); if(i == std::string::npos) { return false; } // Package string contains the version: <pkg>:<version> v = Version(pname.substr(i + 1)); pname.erase(i, pname.length() - i); return true; }
std::string abbreviateFile(const std::string& filePath) { std::string f = filePath; #if LL_WINDOWS replaceChar(f, '\\', '/'); #endif static std::string indra_prefix = "indra/"; f = removePrefix(f, indra_prefix); #if LL_DARWIN static std::string newview_prefix = "newview/../"; f = removePrefix(f, newview_prefix); #endif return f; }
QString GeneratorNG::generateStreamWriteOperatorDefinition(const TLType &type) { QString code; QString argName = removePrefix(type.name); argName[0] = argName.at(0).toLower(); code.append(QString("%1 &%1::operator<<(const %2 &%3)\n{\n").arg(streamClassName).arg(type.name).arg(argName)); code.append(QString("%1*this << %2.tlType;\n\n%1switch (%2.tlType) {\n").arg(spacing).arg(argName)); foreach (const TLSubType &subType, type.subTypes) { code.append(QString("%1case %2::%3:\n").arg(spacing).arg(tlValueName).arg(subType.name)); foreach (const TLParam &member, subType.members) { code.append(doubleSpacing + QString("*this << %1.%2;\n").arg(argName).arg(member.name)); } code.append(QString("%1break;\n").arg(doubleSpacing)); } code.append(QString("%1default:\n%1%1break;\n%1}\n\n").arg(spacing)); code.append(spacing + QString("return *this;\n}\n\n")); return code; }
AccessLogFileData::AccessLogFileData(const std::string& fil, const std::string& lnk, const std::string& fmt, int mpl) : file(fil) , symLink(lnk) , format(fmt) , periodMultiplier(mpl) { /* * a LogWriter with it's format can be selected between colons like: * Format = :thrift: [["%{%s}t", "out-name", "STRING"], ...] */ m_logOutputType = ClassicWriter::handle; auto fmt_ = folly::StringPiece(fmt); while (!fmt_.empty() && std::isspace(fmt_.front())) fmt_.pop_front(); if (fmt_.removePrefix(':')) { size_t close = fmt_.find(':'); if (close != fmt_.npos) { m_logOutputType = fmt_.subpiece(0, close).str(); fmt_.advance(close + 1); format = folly::trimWhitespace(fmt_).str(); } } }
uint_least64_t vc_text2nflag(char const *str, size_t len) { char const * tmp = removePrefix(str, &len); ssize_t idx = utilvserver_value2text_uint64(tmp, len, VALUES, DIM_OF(VALUES)); if (idx==-1) return 0; else return VALUES[idx].val; }
bool Path::replacePrefix(const Path &old_prefix, const Path &new_prefix) { if (hasPrefix(old_prefix)) { removePrefix(old_prefix); _components.insert(_components.begin(), new_prefix.begin(), new_prefix.end()); return true; } return false; }
folly::SocketAddress MessageHeader::getPeerAddress() { folly::SocketAddress address; if (peerAddress()[0] == '\0') { return address; } try { if (isUnixDomainSocket()) { auto sp = folly::StringPiece(peerAddress(), kAddressMaxSize); sp.removePrefix(kUnixSocketPrefix); if (!sp.empty()) { address.setFromPath(sp); } } else { address.setFromIpPort(peerAddress(), peerPort()); } } catch (const std::exception& ex) { VLOG(2) << "Error parsing address: " << ex.what(); } return address; }
// include external elements (from groups) void ebucoreParser::generateGroupChildren(std::list<ElementStruct> children, std::string father, xercesc::DOMElement * el) { // store the current position of xercesc pointer xercesc::DOMElement * tmpEl = el; // looking for the group who contains the other elements with the father name while (tmpEl != 0 && !((std::string)(xercesc::XMLString::transcode(tmpEl->getTagName())) == "group" && xercesc::XMLString::transcode(tmpEl->getAttribute (xercesc::XMLString::transcode("name"))) == removePrefix(father,":") )) { tmpEl = tmpEl->getNextElementSibling(); } // enter inside the group tmpEl=tmpEl->getFirstElementChild(); // looking for the sequence while (tmpEl != 0 && (std::string)(xercesc::XMLString::transcode(tmpEl->getTagName())) != "sequence") { tmpEl = tmpEl->getNextElementSibling(); } // if pointer not null, grab the first child if (tmpEl != 0) { tmpEl=tmpEl->getFirstElementChild(); } // while xerces pointer not null, while (tmpEl != 0) { // if it's an element if ((std::string)(xercesc::XMLString::transcode(tmpEl->getTagName())) == "element") { // prepare the element informations std::string name (xercesc::XMLString::transcode(tmpEl->getAttribute (xercesc::XMLString::transcode("name")))); std::string type (xercesc::XMLString::transcode(tmpEl->getAttribute (xercesc::XMLString::transcode("type")))); std::string ref (xercesc::XMLString::transcode(tmpEl->getAttribute (xercesc::XMLString::transcode("ref")))); std::string minimum (xercesc::XMLString::transcode(tmpEl->getAttribute (xercesc::XMLString::transcode("minOccurs")))); std::string maximum (xercesc::XMLString::transcode(tmpEl->getAttribute (xercesc::XMLString::transcode("maxOccurs")))); // instantiate the list of children ebucoreParser::ElementStruct internalChildren; // identify the element name internalChildren.name = (name.size()>0)?name:ref; // identify the cardinality and type internalChildren.minCardinality = ((minimum.size()>0)?atoi(minimum.c_str()):1); internalChildren.maxCardinality = ((maximum.size()>0)?isUnbounded(maximum):1); internalChildren.type = ( (type.size()>0) ? type : "" ); // if it is not a standard type if (!isStandardType(type)) { // and if type is not null if (type.size()>0) { // generate attributes internalChildren.attribute = (isDCSimpleType(type)) ? DCAttr : generateAttributes(removePrefix(internalChildren.type, ":"), tmpEl); // and correct the type is required internalChildren.type = ( (isDCSimpleType(type)) ? DCType() : internalChildren.type ); } else { // generate attributes and correct the type is required internalChildren.attribute = (isDCSimpleType(internalChildren.name))? DCAttr : generateAttributes("", tmpEl); internalChildren.type = ( (isDCSimpleType(internalChildren.name)) ? DCType() : "") ; } } // if it is an ebucore element and the type of this element is not present in the element type stack if (isEBUCoreType(internalChildren.type) && !groupExist(internalChildren.type)) { // push the type ebucoreStack.push_back(internalChildren.type); // generate children internalChildren.children = generateChildren(removePrefix(internalChildren.type,":"), el, 1); // pop the type ebucoreStack.pop_back(); } //push the internal child children.push_back(internalChildren); } // next tmpEl = tmpEl->getNextElementSibling(); } }
// generate the children of an elements std::list<ebucoreParser::ElementStruct> ebucoreParser::generateChildren(std::string father, xercesc::DOMElement * el, int level) { // instantiate the children list std::list<ebucoreParser::ElementStruct> children; // copy the current position of xercesc pointer xercesc::DOMElement * tmpEl = el; // while xercesc pointer not null, element different of complexType with the proper name while (tmpEl != 0 && ((std::string)(xercesc::XMLString::transcode(tmpEl->getTagName())) != "complexType" || xercesc::XMLString::transcode(tmpEl->getAttribute (xercesc::XMLString::transcode("name"))) != father )) { tmpEl = tmpEl->getNextElementSibling();// next } // grab the first child of proper element tmpEl=tmpEl->getFirstElementChild(); // looking for the sequence of elements while (tmpEl != 0 && (std::string)(xercesc::XMLString::transcode(tmpEl->getTagName())) != "sequence") { tmpEl = tmpEl->getNextElementSibling(); // next } // if pointer not null, grab the first child of the current element if (tmpEl != 0) { tmpEl=tmpEl->getFirstElementChild(); } // while xerces point not null, loop while (tmpEl != 0) { // if current tag kind is element if ((std::string)(xercesc::XMLString::transcode(tmpEl->getTagName())) == "element") { // prepare the element information std::string name (xercesc::XMLString::transcode(tmpEl->getAttribute (xercesc::XMLString::transcode("name")))); std::string type (xercesc::XMLString::transcode(tmpEl->getAttribute (xercesc::XMLString::transcode("type")))); std::string ref (xercesc::XMLString::transcode(tmpEl->getAttribute (xercesc::XMLString::transcode("ref")))); std::string minimum (xercesc::XMLString::transcode(tmpEl->getAttribute (xercesc::XMLString::transcode("minOccurs")))); std::string maximum (xercesc::XMLString::transcode(tmpEl->getAttribute (xercesc::XMLString::transcode("maxOccurs")))); // instantiate the children struct ebucoreParser::ElementStruct internalChildren; // grab the right name/references internalChildren.name = (name.size()>0)?name:ref; // identify the cardinality and the type of element internalChildren.minCardinality = ((minimum.size()>0)?atoi(minimum.c_str()):1); internalChildren.maxCardinality = ((maximum.size()>0)?isUnbounded(maximum):1); internalChildren.type = ( (type.size()>0) ? type : "" ); // if type is not standard if (!isStandardType(type)) { // if type is not null if (type.size()>0) { //generate the attribute list of the current element internalChildren.attribute = (isDCSimpleType(type)) ? DCAttr : generateAttributes(removePrefix(internalChildren.type, ":"), tmpEl); // and correct his type if required internalChildren.type = ( (isDCSimpleType(type)) ? DCType() : internalChildren.type ); } else { // generate the attribute list of the current element and correct his type if required internalChildren.attribute = (isDCSimpleType(internalChildren.name))? DCAttr : generateAttributes("", tmpEl); internalChildren.type = ( (isDCSimpleType(internalChildren.name)) ? DCType() : "") ; } } // if element type is ebucore and the type not present in the stack, then if (isEBUCoreType(internalChildren.type) && !groupExist(internalChildren.type)) { ebucoreStack.push_back(internalChildren.type); // push the type // generate the children internalChildren.children = generateChildren(removePrefix(internalChildren.type,":"), el, level+1); ebucoreStack.pop_back(); // pop the type } // push the children list children.push_back(internalChildren); // if the current tag king is group, then } else if ((std::string)(xercesc::XMLString::transcode(tmpEl->getTagName())) == "group") { // generate the children of this group and then add it to current list of children generateGroupChildren(children, xercesc::XMLString::transcode(tmpEl->getAttribute (xercesc::XMLString::transcode("ref"))), el); } tmpEl = tmpEl->getNextElementSibling(); // next } return children; }
// generate the attributes of an element std::list<ebucoreParser::AttributeStruct> ebucoreParser::generateAttributes(std::string father, xercesc::DOMElement * el) { // groupName to store the attributeGroups std::vector<std::string> groupName; // attributes list std::list<ebucoreParser::AttributeStruct> attributes; // when father type hasn't a name, that means the type is implicit if (father =="") { // we must save the current position xercesc::DOMElement * tmp = el->getFirstElementChild(); // and looking for the implicit father complexType (without name) if ((std::string)(xercesc::XMLString::transcode(tmp->getTagName())) == "complexType" ) { // when the complexType is identified, put the cursor inside the first child tmp = tmp->getFirstElementChild(); // while xercesc pointer not null while (tmp != 0) { // if attribute is a simpleContent if ((std::string)(xercesc::XMLString::transcode(tmp->getTagName())) == "simpleContent") { // grab the first child of the first child of the current element xercesc::DOMElement * localTmp = tmp->getFirstElementChild()->getFirstElementChild(); // if xercersc pointer not null while (localTmp != 0) { // if attribute is a simple attribute if ((std::string)(xercesc::XMLString::transcode(localTmp->getTagName())) == "attribute" ) { // wrap and push the attribute attributes.push_back(packAttribute(localTmp)); // if attribute is an attributeGroup } else if ((std::string)(xercesc::XMLString::transcode(localTmp->getTagName())) == "attributeGroup" ) { // push the attributeGroup name inside the attributeGroup stack groupName.push_back(removePrefix ((std::string)(xercesc::XMLString::transcode(localTmp->getAttribute (xercesc::XMLString::transcode("ref")))),":" )); } // next element... localTmp = localTmp->getNextElementSibling(); } // if attribute is a complexContent } else if ((std::string)(xercesc::XMLString::transcode(tmp->getTagName())) == "complexContent") { // grab the first child of the current element xercesc::DOMElement * localTmp = tmp->getFirstElementChild(); // if it is a DublinCore attribute if (isDCSimpleType((std::string)(xercesc::XMLString::transcode(localTmp->getAttribute (xercesc::XMLString::transcode("base")))))) { //push the dublincore attribute attributes.push_back(DCAttribute()); } else { // if it is not a dublincore attribute, that means that is an attributeGroup or external attribute groupName.push_back(removePrefix ((std::string)(xercesc::XMLString::transcode(localTmp->getAttribute (xercesc::XMLString::transcode("base")))),":" )); } // enter inside the current element localTmp = localTmp->getFirstElementChild(); // in plus of external attribute and attributeGroup treatments, we can have // several local attributes and attributeGroups to solve // if xercesc pointer is not null while (localTmp != 0) { // if it is a simple attribute if ((std::string)(xercesc::XMLString::transcode(localTmp->getTagName())) == "attribute" ) { // wrap and push the attribute attributes.push_back(packAttribute(localTmp)); // if it is an attributeGroup } else if ((std::string)(xercesc::XMLString::transcode(localTmp->getTagName())) == "attributeGroup" ) { // save the attributeGroup name/reference... groupName.push_back(removePrefix ((std::string)(xercesc::XMLString::transcode(localTmp->getAttribute (xercesc::XMLString::transcode("ref")))),":")); } // next element... localTmp = localTmp->getNextElementSibling(); } // if attribute is an attributeGroup } else if ((std::string)(xercesc::XMLString::transcode(tmp->getTagName())) == "attributeGroup") { // save the attributeGroup name/reference groupName.push_back(removePrefix ((std::string)(xercesc::XMLString::transcode(tmp->getAttribute (xercesc::XMLString::transcode("ref")))), ":" )); // if attribute is a simple attribute } else if ((std::string)(xercesc::XMLString::transcode(tmp->getTagName())) == "attribute") { // wrap and push the attribute attributes.push_back(packAttribute(tmp)); } // next... tmp = tmp->getNextElementSibling(); } } } // We don't know if the father is an implicit complexType who references // an external attributeGroup, so we consider it as an external references if (father!="") { groupName.push_back(father); } // for each external attributeGroup, build the set of attributes for (int i=0; i<(int)groupName.size(); i++) { // pointer starter... xercesc::DOMElement * tmpEl = el; // looking for the root of the schema document while ((std::string)(xercesc::XMLString::transcode((tmpEl->getParentNode())->getNodeName())) != "schema") { tmpEl = dynamic_cast<xercesc::DOMElement*>(tmpEl->getParentNode()); } // grab the first child of the schema tmpEl=(dynamic_cast<xercesc::DOMElement*>(tmpEl->getParentNode()))->getFirstElementChild(); // looking for a complexType or an attributeGroup with the right name while (((std::string)(xercesc::XMLString::transcode(tmpEl->getTagName())) != "complexType" && xercesc::XMLString::transcode(tmpEl->getAttribute (xercesc::XMLString::transcode("name"))) != groupName.at(i) ) || ((std::string)(xercesc::XMLString::transcode(tmpEl->getTagName())) != "attributeGroup" && xercesc::XMLString::transcode(tmpEl->getAttribute (xercesc::XMLString::transcode("name"))) != groupName.at(i)) ) { tmpEl = tmpEl->getNextElementSibling(); } //grab the first child tmpEl=tmpEl->getFirstElementChild(); // while xerces pointer not null do { // and if the element is an attribute if ((std::string)(xercesc::XMLString::transcode(tmpEl->getTagName())) == "attribute") { // wrap and push the attribute attributes.push_back(packAttribute(tmpEl)); } // next tmpEl = tmpEl->getNextElementSibling(); } while (tmpEl != 0); } return attributes; }
std::string WsModulesLoader::pathWithoutPrefix(const std::string& path) { std::string remP = removePrefix(path); if ( remP == "" ) remP = "/"; return remP; }
QString GeneratorNG::generateDebugWriteOperatorDeclaration(const TLType &type) { QString argName = removePrefix(type.name); argName[0] = argName.at(0).toLower(); return QString("QDebug operator<<(QDebug d, const %1 &%2);\n").arg(type.name).arg(argName); }
QString GeneratorNG::generateStreamWriteOperatorDeclaration(const TLType &type) { QString argName = removePrefix(type.name); argName[0] = argName.at(0).toLower(); return spacing + QString("%1 &operator<<(const %2 &%3);\n").arg(streamClassName).arg(type.name).arg(argName); }
void stripLeft(Collection &collection, const std::function<bool(const Element&)> predicate = defaultStripPredicate<Element>) { while(!collection.empty() && predicate(collection.front())) removePrefix(collection); }