Skip to content

Commit 1b2de0c

Browse files
authored
Merge pull request #3508 from roystgnr/isspace_robust
Make our use of isspace more robust
2 parents eda2b5f + 5b40c68 commit 1b2de0c

4 files changed

Lines changed: 16 additions & 10 deletions

File tree

include/base/getpot.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
#include <cmath>
4747
#include <cstdlib>
4848
#include <ctime>
49+
#include <cctype>
4950

5051
extern "C" {
5152
#include <stdarg.h> // --> va_list and friends
@@ -1308,7 +1309,7 @@ GetPot::_skip_whitespace(std::istream& istr)
13081309
int tmp = istr.get();
13091310
do {
13101311
// -- search a non whitespace
1311-
while (isspace(tmp))
1312+
while (std::isspace(tmp))
13121313
{
13131314
tmp = istr.get();
13141315
if (!istr)
@@ -2811,7 +2812,7 @@ GetPot::_DBE_get_expr_list(const std::string& str_, const unsigned ExpectedNumbe
28112812
unsigned i=0;
28122813
// (1) eat initial whitespaces
28132814
for (; i < str.size(); i++)
2814-
if (!isspace(str[i]))
2815+
if (!std::isspace(str[i]))
28152816
break;
28162817

28172818
STRING_VECTOR expr_list;
@@ -2825,13 +2826,13 @@ GetPot::_DBE_get_expr_list(const std::string& str_, const unsigned ExpectedNumbe
28252826
{
28262827
const char letter = str[i];
28272828
// whitespace -> end of expression
2828-
if (isspace(letter) && open_brackets == 0)
2829+
if (std::isspace(letter) && open_brackets == 0)
28292830
{
28302831
expr_list.push_back(str.substr(start_new_string, i - start_new_string));
28312832
bool no_breakout_f = true;
28322833
for (i++; i < l ; i++)
28332834
{
2834-
if (!isspace(str[i]))
2835+
if (!std::isspace(str[i]))
28352836
{
28362837
no_breakout_f = false;
28372838
start_new_string = i;

src/mesh/abaqus_io.C

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
#include <string>
2929
#include <cstdlib> // std::strtol
3030
#include <sstream>
31-
#include <ctype.h> // isspace
31+
#include <cctype> // isspace
3232

3333
// Anonymous namespace to hold mapping Data for Abaqus/libMesh element types
3434
namespace
@@ -56,7 +56,9 @@ bool string_to_num(const std::string & input, dof_id_type & output)
5656
*/
5757
void strip_ws(std::string & line)
5858
{
59-
line.erase(std::remove_if(line.begin(), line.end(), isspace), line.end());
59+
line.erase(std::remove_if(line.begin(), line.end(),
60+
[](unsigned char const c){return std::isspace(c);}),
61+
line.end());
6062
}
6163

6264
/**

src/mesh/gmv_io.C

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#include <iomanip>
2020
#include <fstream>
2121
#include <vector>
22-
#include <ctype.h> // isspace
22+
#include <cctype> // isspace
2323

2424
// Local includes
2525
#include "libmesh/libmesh_config.h"
@@ -2135,7 +2135,9 @@ void GMVIO::_read_one_cell()
21352135
ElemType GMVIO::gmv_elem_to_libmesh_elem(std::string elemname)
21362136
{
21372137
// Erase any whitespace padding in name coming from gmv before performing comparison.
2138-
elemname.erase(std::remove_if(elemname.begin(), elemname.end(), isspace), elemname.end());
2138+
elemname.erase(std::remove_if(elemname.begin(), elemname.end(),
2139+
[](unsigned char const c){return std::isspace(c);}),
2140+
elemname.end());
21392141
return libmesh_map_find(_reading_element_map, elemname);
21402142
}
21412143

src/mesh/unv_io.C

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
#include <iomanip>
4242
#include <algorithm> // for std::sort
4343
#include <fstream>
44-
#include <ctype.h> // isspace
44+
#include <cctype> // isspace
4545
#include <sstream> // std::istringstream
4646
#include <unordered_map>
4747

@@ -156,7 +156,8 @@ void UNVIO::read_implementation (std::istream & in_stream)
156156
// UNV files always have some amount of leading
157157
// whitespace, let's not rely on exactly how much... This
158158
// command deletes it.
159-
current_line.erase(std::remove_if(current_line.begin(), current_line.end(), isspace),
159+
current_line.erase(std::remove_if(current_line.begin(), current_line.end(),
160+
[](unsigned char const c){return std::isspace(c);}),
160161
current_line.end());
161162

162163
// Parse the nodes section

0 commit comments

Comments
 (0)