Skip to content

Commit 0dac69c

Browse files
committed
Avoid using std::isspace and friends on potentially multibyte characters
1 parent 1b03538 commit 0dac69c

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

src/qcstring.cpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,9 @@ QCString QCString::simplifyWhiteSpace() const
188188
char *first = to;
189189
while ( TRUE )
190190
{
191-
while ( *from && isspace((uchar) *from) )
191+
while ( *from && qisspace(*from) )
192192
from++;
193-
while ( *from && !isspace((uchar)*from) )
193+
while ( *from && !qisspace(*from) )
194194
*to++ = *from++;
195195
if ( *from )
196196
*to++ = 0x20; // ' '
@@ -262,7 +262,7 @@ long QCString::toLong(bool *ok,int base) const
262262
int neg = 0;
263263
if ( !p )
264264
goto bye;
265-
while ( l && isspace(*p) ) // skip leading space
265+
while ( l && qisspace(*p) ) // skip leading space
266266
l--,p++;
267267
if ( l && *p == '-' ) {
268268
l--;
@@ -294,7 +294,7 @@ long QCString::toLong(bool *ok,int base) const
294294
}
295295
if ( neg )
296296
val = -val;
297-
while ( l && isspace(*p) ) // skip trailing space
297+
while ( l && qisspace(*p) ) // skip trailing space
298298
l--,p++;
299299
if ( !l )
300300
is_ok = TRUE;
@@ -313,7 +313,7 @@ ulong QCString::toULong(bool *ok,int base) const
313313
bool is_ok = FALSE;
314314
if ( !p )
315315
goto bye;
316-
while ( l && isspace(*p) ) // skip leading space
316+
while ( l && qisspace(*p) ) // skip leading space
317317
l--,p++;
318318
if ( *p == '+' )
319319
l--,p++;
@@ -338,7 +338,7 @@ ulong QCString::toULong(bool *ok,int base) const
338338
p++;
339339
}
340340

341-
while ( l && isspace(*p) ) // skip trailing space
341+
while ( l && qisspace(*p) ) // skip trailing space
342342
l--,p++;
343343
if ( !l )
344344
is_ok = TRUE;
@@ -357,7 +357,7 @@ uint64 QCString::toUInt64(bool *ok,int base) const
357357
bool is_ok = FALSE;
358358
if ( !p )
359359
goto bye;
360-
while ( l && isspace(*p) ) // skip leading space
360+
while ( l && qisspace(*p) ) // skip leading space
361361
l--,p++;
362362
if ( *p == '+' )
363363
l--,p++;
@@ -382,7 +382,7 @@ uint64 QCString::toUInt64(bool *ok,int base) const
382382
p++;
383383
}
384384

385-
while ( l && isspace(*p) ) // skip trailing space
385+
while ( l && qisspace(*p) ) // skip trailing space
386386
l--,p++;
387387
if ( !l )
388388
is_ok = TRUE;

src/qcstring.h

+7-3
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,14 @@ inline int qstrncmp( const char *str1, const char *str2, uint len )
8282
{ return (str1 && str2) ? strncmp(str1,str2,len) :
8383
(int)((intptr_t)str2 - (intptr_t)str1); }
8484

85+
inline bool qisspace(char c)
86+
{ return c==' ' || c=='\t' || c=='\n' || c=='\r'; }
87+
8588
int qstricmp( const char *str1, const char *str2 );
8689

8790
int qstrnicmp( const char *str1, const char *str2, uint len );
8891

92+
8993
/** This is an alternative implementation of QCString. It provides basically
9094
* the same functions but uses std::string as the underlying string type
9195
*/
@@ -231,11 +235,11 @@ class QCString
231235
QCString stripWhiteSpace() const
232236
{
233237
int sl = (uint)m_rep.size();
234-
if (sl==0 || (!std::isspace(m_rep[0]) && !std::isspace(m_rep[sl-1]))) return *this;
238+
if (sl==0 || (!qisspace(m_rep[0]) && !qisspace(m_rep[sl-1]))) return *this;
235239
int start=0,end=sl-1;
236-
while (start<sl && std::isspace(m_rep[start])) start++;
240+
while (start<sl && qisspace(m_rep[start])) start++;
237241
if (start==sl) return QCString(); // only whitespace
238-
while (end>start && std::isspace(m_rep[end])) end--;
242+
while (end>start && qisspace(m_rep[end])) end--;
239243
return QCString(m_rep.substr(start,1+end-start));
240244
}
241245

0 commit comments

Comments
 (0)