/*only used it the linkAPI is enabled*/ void NxsTaxaBlockSurrogate::HandleLinkTaxaCommand(NxsToken & token) { token.GetNextToken(); const std::map<std::string, std::string> kv = token.ProcessAsSimpleKeyValuePairs("LINK"); std::map<std::string, std::string>::const_iterator pairIt = kv.begin(); for (;pairIt != kv.end(); ++pairIt) { NxsTaxaBlockAPI *entryTaxa = taxa; int entryTaxaLinkStatus = taxaLinkStatus; NxsString key(pairIt->first.c_str()); key.ToUpper(); NxsString value(pairIt->second.c_str()); if (key == "TAXA") { if (taxa && !taxa->GetID().EqualsCaseInsensitive(value)) { if (GetTaxaLinkStatus() & NxsBlock::BLOCK_LINK_USED) { NxsString errormsg = "LINK to a Taxa block must occur before commands that use a taxa block"; throw NxsException(errormsg, token); } SetTaxaBlockPtr(NULL, NxsBlock::BLOCK_LINK_UNINITIALIZED); } if (!taxa) { if (!nxsReader) { NxsString errormsg = "API Error: No nxsReader during parse in NxsTaxaBlockSurrogate::HandleLinkTaxaCommand"; throw NxsNCLAPIException(errormsg, token); } NxsTaxaBlockAPI * cb = nxsReader->GetTaxaBlockByTitle(value.c_str(), NULL); if (cb == NULL) { NxsString errormsg = "Unknown TAXA block ("; errormsg += value; errormsg +=") referred to in the LINK command"; taxa = entryTaxa; taxaLinkStatus = entryTaxaLinkStatus; throw NxsException(errormsg, token); } SetTaxaBlockPtr(cb, NxsBlock::BLOCK_LINK_FROM_LINK_CMD); } } else { NxsString errormsg = "Skipping unknown LINK subcommand: "; errormsg += pairIt->first.c_str(); nxsReader->NexusWarnToken(errormsg, NxsReader::SKIPPING_CONTENT_WARNING, token); errormsg.clear(); //this token pos will be off a bit. } } }
std::string getLegalRelaxedPhylipTaxonName(const std::string & origName, const std::set<std::string> & used) { NxsString numericExtension; std::string toReturn; const std::string cleanedName(purgeIllegalCharactersFromRelaxedPhylipName(origName)); for (unsigned i = 1;; ++i) { if (formLegalRelaxedPhylipName(cleanedName, numericExtension, used, toReturn)) return toReturn; numericExtension.clear(); numericExtension << i; } }
/*-------------------------------------------------------------------------------------------------------------------------- | Written to make it easy to initialize a vector of strings. Similar to the perl split function. Converts a string like | this -- "A|bro|ken strin|g" -- to a vector of strings with four elements: "A", "bro", "ken string", and "g". */ NxsStringVector BreakPipeSeparatedList( const NxsString &strList) /* the string submitted for splitting */ { NxsString::const_iterator p = strList.begin(); NxsString ss; NxsStringVector retVec; for (;;) { bool done = (p == strList.end()); if (done || (*p == '|')) { retVec.push_back(ss); ss.clear(); if (done) break; p++; } ss += *p; p++; } return retVec; }
std::string assignUniqueName(const std::string & prefix, unsigned maxLen, const std::set<std::string> & safeLabelSet) { NxsString s; s << prefix; std::set<std::string>::const_iterator sIt = safeLabelSet.find(s); if (sIt == safeLabelSet.end()) return s; unsigned i = 1; for (;;) { NxsString numAsStr; numAsStr << i++; s.clear(); unsigned concatLen = numAsStr.length() + prefix.length(); if (concatLen > maxLen) s << prefix.substr(0, 2*maxLen - 1 - concatLen); else s << prefix; s << numAsStr; sIt = safeLabelSet.find(s); if (sIt == safeLabelSet.end()) return s; } }