CTempString CShortReadFastaInputSource::x_ParseDefline(CTempString& line) { // set local sequence id for the new sequence as the string between '>' // and the first space size_t begin = 1; size_t end = line.find(' ', 1); CTempString id = line.substr(begin, end - begin); return id; }
static void s_ProcessECNumberLine(const CTempString& line, CProt_ref::EECNumberStatus status) { if (status == CProt_ref::eEC_replaced) { SIZE_TYPE tab_pos = line.find('\t'); if (tab_pos == NPOS) { ERR_POST_X(1, Warning << "No tab in ecnum_replaced entry " << line << "; disregarding"); } else { string lhs(line.substr(0, tab_pos)), rhs(line.substr(tab_pos + 1)); s_ECNumberStatusMap[lhs] = status; s_ECNumberReplacementMap[lhs] = rhs; } } else { SIZE_TYPE tab_pos = line.find('\t'); if (tab_pos == NPOS) { s_ECNumberStatusMap[line] = status; } else { string lhs(line.substr(0, tab_pos)); s_ECNumberStatusMap[lhs] = status; } } }
BEGIN_NCBI_SCOPE ////////////////////////////////////////////////////////////////////////////// static TSvrRef make_server(const CTempString& specification, double& preference) { CTempString server; // string host; Uint4 host = 0; Uint2 port = 0; string::size_type pos = 0; pos = specification.find_first_of("@(", pos); if (pos != string::npos) { server = specification.substr(0, pos); if (specification[pos] == '@') { // string::size_type old_pos = pos + 1; pos = specification.find_first_of(":(", pos + 1); if (pos != string::npos) { // string host_str = specification.substr(old_pos, pos - old_pos); // Ignore host in order to avoid dependebcy on libconnect. // SOCK_StringToHostPort(specification.c_str() + old_pos, &host, &port); if (specification[pos] == ':') { port = NStr::StringToUInt(specification.substr(pos + 1), NStr::fAllowLeadingSpaces | NStr::fAllowTrailingSymbols | NStr::fConvErr_NoThrow); pos = specification.find("(", pos + 1); if (pos != string::npos) { // preference = NStr::StringToDouble( preference = NStr::StringToUInt( specification.substr(pos + 1), NStr::fAllowLeadingSpaces | NStr::fAllowTrailingSymbols | NStr::fConvErr_NoThrow); } } else { // preference = NStr::StringToDouble( preference = NStr::StringToUInt( specification.substr(pos + 1), NStr::fAllowLeadingSpaces | NStr::fAllowTrailingSymbols | NStr::fConvErr_NoThrow); } } else { // host = specification.substr(old_pos); // Ignore host in order to avoid dependebcy on libconnect. // SOCK_StringToHostPort(specification.c_str() + old_pos, &host, &port); } } else { // preference = NStr::StringToDouble( preference = NStr::StringToUInt( specification.substr(pos + 1), NStr::fAllowLeadingSpaces | NStr::fAllowTrailingSymbols | NStr::fConvErr_NoThrow); } } else { server = specification; } if (server.empty() && host == 0) { DATABASE_DRIVER_ERROR("Either server name or host name expected.", 110100 ); } return TSvrRef(new CDBServer(server, host, port)); }
CTextseq_id& CTextseq_id::Set (const CTempString& acc_in, const CTempString& name_in, int version, const CTempString& release_in, bool allow_dot_version) { // Perform general sanity checks up front. if (version < 0) { NCBI_THROW(CSeqIdException, eFormat, "Unexpected negative version " + NStr::IntToString(version) + " for accession " + string(acc_in)); } CTempString acc = NStr::TruncateSpaces_Unsafe(acc_in, NStr::eTrunc_Both); CTempString name = NStr::TruncateSpaces_Unsafe(name_in, NStr::eTrunc_Both); CTempString release = NStr::TruncateSpaces_Unsafe(release_in, NStr::eTrunc_Both); if (acc.empty() && name.empty()) { } if (acc.empty()) { ResetAccession(); } else { SIZE_TYPE idx = NPOS; if (allow_dot_version) { idx = acc.rfind('.'); } if (idx == NPOS) { // no version within acc SetAccession(acc); // any standalone version is ok if (version > 0) { SetVersion(version); } else { ResetVersion(); } } else { // accession.version CTempString accession = acc.substr(0, idx); CTempString acc_ver = acc.substr(idx + 1); int ver = NStr::StringToNonNegativeInt(acc_ver); if (ver <= 0) { NCBI_THROW(CSeqIdException, eFormat, "Version embedded in accession " + string(acc) + " is not a positive integer"); } else if (version > 0 && ver != version) { NCBI_THROW(CSeqIdException, eFormat, "Incompatible version " + NStr::IntToString(version) + " supplied for accession " + string(acc)); } SetAccession(accession); SetVersion(ver); } } if (name.empty()) { ResetName(); } else { SetName(name); } if (acc.empty() && name.empty()) { NCBI_THROW(CSeqIdException, eFormat, "Accession and name missing for Textseq-id (but got" " version " + NStr::IntToString(version) + ", release " + string(release) + ')'); } else if (release.empty()) { ResetRelease(); } else { SetRelease(release); } return *this; }