diff --git a/modules/base/src/string_ref.cc b/modules/base/src/string_ref.cc index 5cc42986b497f65cd9899b971eafbd3bbdd93a45..6a1d622541a331df3c2d8e4fa9d33bc4f3442cd6 100644 --- a/modules/base/src/string_ref.cc +++ b/modules/base/src/string_ref.cc @@ -113,4 +113,17 @@ std::vector<StringRef> StringRef::split(char p) const return result; } +std::string StringRef::str_no_whitespace() const +{ + std::string whitespaceless_string; + whitespaceless_string.reserve(this->size()); + for (const char* s=begin_; s!=end_; ++s) { + if (isspace(*s)) { + continue; + } + whitespaceless_string.push_back(*s); + + } + return whitespaceless_string; +} } diff --git a/modules/base/src/string_ref.hh b/modules/base/src/string_ref.hh index cc5661ebaa2c15dc96818d8fb86fbb8a3a7b4696..d72a27a8532897810cde97e6009464bfefd31d1f 100644 --- a/modules/base/src/string_ref.hh +++ b/modules/base/src/string_ref.hh @@ -147,6 +147,10 @@ public: /// \brief split string into chunks delimited by \p p std::vector<StringRef> split(char p) const; + + /// \brief returns a new string with all whitespace removed from + /// this StringRef + std::string str_no_whitespace() const; private: const char* begin_; const char* end_; diff --git a/modules/io/src/mol/mmcif_reader.cc b/modules/io/src/mol/mmcif_reader.cc index b766d74fb3959e9122bb1fe4fd312c8e87fca87d..98c3572256535c97e561d32623cf35e8c833ed36 100644 --- a/modules/io/src/mol/mmcif_reader.cc +++ b/modules/io/src/mol/mmcif_reader.cc @@ -518,22 +518,23 @@ void MMCifParser::ParseEntityPoly(const std::vector<StringRef>& columns) this->GetCurrentLinenum())); } if (read_seqres_) { + StringRef seqres; if (seqres_can_) { if (indices_[PDBX_SEQ_ONE_LETTER_CODE_CAN] != -1) { - edm_it->second.seqres = - columns[indices_[PDBX_SEQ_ONE_LETTER_CODE_CAN]].str(); + seqres=columns[indices_[PDBX_SEQ_ONE_LETTER_CODE_CAN]]; } else { throw IOException(this->FormatDiagnostic(STAR_DIAG_ERROR, "'entity_poly.pdbx_seq_one_letter_code_can' not available.'", this->GetCurrentLinenum())); } } else if (indices_[PDBX_SEQ_ONE_LETTER_CODE] != -1) { - edm_it->second.seqres = columns[indices_[PDBX_SEQ_ONE_LETTER_CODE]].str(); + seqres=columns[indices_[PDBX_SEQ_ONE_LETTER_CODE]]; } else { throw IOException(this->FormatDiagnostic(STAR_DIAG_ERROR, "'entity_poly.pdbx_seq_one_letter_code' not available.'", this->GetCurrentLinenum())); } + edm_it->second.seqres = seqres.str_no_whitespace(); } }