From 35ebbb762521a02bbf63dc0909de26f7dd71b620 Mon Sep 17 00:00:00 2001 From: Anthony Geay Date: Tue, 12 Sep 2017 14:12:41 +0200 Subject: [PATCH] For users having field names with white space at the end --- src/MEDLoader/MEDFileField.cxx | 13 +++++++++++++ src/MEDLoader/MEDFileField.hxx | 1 + 2 files changed, 14 insertions(+) diff --git a/src/MEDLoader/MEDFileField.cxx b/src/MEDLoader/MEDFileField.cxx index 378e7094f..cff3ef75c 100644 --- a/src/MEDLoader/MEDFileField.cxx +++ b/src/MEDLoader/MEDFileField.cxx @@ -5077,6 +5077,19 @@ void MEDFileAnyTypeField1TSWithoutSDA::writeLL(med_idt fid, const MEDFileWritabl _field_per_mesh[0]->writeLL(fid,nasc); } +/*! + * MED file does not support ' ' at the end of the field name. This method corrects the possibly invalid input \a nonCorrectFieldName to a correct one by right stripping input. + */ +std::string MEDFileAnyTypeField1TSWithoutSDA::FieldNameToMEDFileConvention(const std::string& nonCorrectFieldName) +{ + std::string::size_type pos0(nonCorrectFieldName.find_last_not_of(' ')); + if(pos0==std::string::npos) + return nonCorrectFieldName; + if(pos0+1==nonCorrectFieldName.length()) + return nonCorrectFieldName; + return nonCorrectFieldName.substr(0,pos0+1); +} + /*! * This methods returns true is the allocation has been needed leading to a modification of state in \a this->_nb_of_tuples_to_be_allocated. * If false is returned the memory allocation is not required. diff --git a/src/MEDLoader/MEDFileField.hxx b/src/MEDLoader/MEDFileField.hxx index 2749a349a..dc39fba0b 100644 --- a/src/MEDLoader/MEDFileField.hxx +++ b/src/MEDLoader/MEDFileField.hxx @@ -662,6 +662,7 @@ namespace MEDCoupling MEDLOADER_EXPORT void loadStructureAndBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc, const MEDFileMeshes *ms, const MEDFileEntities *entities); MEDLOADER_EXPORT void unloadArrays(); MEDLOADER_EXPORT void writeLL(med_idt fid, const MEDFileWritable& opts, const MEDFileFieldNameScope& nasc) const; + MEDLOADER_EXPORT static std::string FieldNameToMEDFileConvention(const std::string& nonCorrectFieldName); protected: int getMeshIdFromMeshName(const std::string& mName) const; int addNewEntryIfNecessary(const MEDCouplingMesh *mesh); -- 2.39.2