Skip to content

Commit ffdcb0a

Browse files
authored
Merge pull request #4222 from roystgnr/short_name_fix
New utilities fixing file suffix tests
2 parents aeff7f3 + 4328b6a commit ffdcb0a

22 files changed

+180
-135
lines changed

include/mesh/namebased_io.h

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -119,19 +119,6 @@ NameBasedIO::NameBasedIO (MeshBase & mesh) :
119119
{
120120
}
121121

122-
inline
123-
bool
124-
NameBasedIO::is_parallel_file_format (std::string_view name)
125-
{
126-
return ((name.rfind(".xda") < name.size()) ||
127-
(name.rfind(".xdr") < name.size()) ||
128-
(name.rfind(".nem") == name.size() - 4) ||
129-
(name.rfind(".n") == name.size() - 2) ||
130-
(name.rfind(".cp") < name.size())
131-
);
132-
}
133-
134-
135122
} // namespace libMesh
136123

137124

include/utils/utility.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,20 @@ void deallocate (std::vector<T> & vec)
386386
std::string_view basename_of(const std::string & fullname);
387387

388388

389+
/**
390+
* Look for a substring within a string.
391+
*/
392+
bool contains(std::string_view superstring,
393+
std::string_view substring);
394+
395+
396+
/**
397+
* Look for a substring at the very end of a string.
398+
*/
399+
bool ends_with(std::string_view superstring,
400+
std::string_view suffix);
401+
402+
389403
// Utility functions useful when dealing with complex numbers.
390404

391405
#ifdef LIBMESH_USE_COMPLEX_NUMBERS

src/apps/projection.C

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "libmesh/point.h"
3636
#include "libmesh/replicated_mesh.h"
3737
#include "libmesh/enum_xdr_mode.h"
38+
#include "libmesh/utility.h"
3839

3940

4041
using namespace libMesh;
@@ -151,9 +152,9 @@ int main(int argc, char ** argv)
151152

152153
XdrMODE read_mode;
153154

154-
if (solnname.rfind(".xdr") < solnname.size())
155+
if (Utility::contains(solnname, ".xdr"))
155156
read_mode = DECODE;
156-
else if (solnname.rfind(".xda") < solnname.size())
157+
else if (Utility::contains(solnname, ".xda"))
157158
read_mode = READ;
158159
else
159160
libmesh_error_msg("Unrecognized file extension on " << solnname);

src/mesh/abaqus_io.C

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ void AbaqusIO::read (const std::string & fname)
233233
the_mesh.clear();
234234

235235
// Open stream for reading
236-
const bool gzipped_file = (fname.rfind(".gz") == fname.size() - 3);
236+
const bool gzipped_file = Utility::ends_with(fname, ".gz");
237237

238238
if (gzipped_file)
239239
{

src/mesh/dyna_io.C

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,7 @@ DynaIO::DynaIO (MeshBase & mesh,
138138

139139
void DynaIO::read (const std::string & name)
140140
{
141-
const bool gzipped_file = (name.rfind(".gz") == name.size() - 3);
142-
// These will be handled in unzip_file:
143-
// const bool bzipped_file = (name.size() - name.rfind(".bz2") == 4);
144-
// const bool xzipped_file = (name.size() - name.rfind(".xz") == 3);
141+
const bool gzipped_file = Utility::ends_with(name, ".gz");
145142

146143
std::unique_ptr<std::istream> in;
147144

0 commit comments

Comments
 (0)