• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

polserver / polserver / 21108840797

18 Jan 2026 08:35AM UTC coverage: 60.508% (+0.02%) from 60.492%
21108840797

push

github

web-flow
ClangTidy readability-else-after-return (#857)

* trigger tidy

* Automated clang-tidy change: readability-else-after-return

* compile test

* rerun

* Automated clang-tidy change: readability-else-after-return

* trigger..

* Automated clang-tidy change: readability-else-after-return

* manually removed a few

* Automated clang-tidy change: readability-else-after-return

* removed duplicate code

* fix remaining warnings

* fixed scope

---------

Co-authored-by: Clang Tidy <clang-tidy@users.noreply.github.com>

837 of 1874 new or added lines in 151 files covered. (44.66%)

46 existing lines in 25 files now uncovered.

44448 of 73458 relevant lines covered (60.51%)

525066.38 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

92.09
/pol-core/clib/strutil.cpp
1
/** @file
2
 *
3
 * @par History
4
 * - 2009/09/12 MuadDib:   Disabled 4244 in this file due to it being on a string iter. Makes no
5
 * sense.
6
 * - 2014/06/10 Nando:  Removed pragma that disabled 4244. (tolower()/toupper() used ints because -1
7
 * is a valid output).
8
 */
9

10

11
#include "strutil.h"
12

13
#include <boost/algorithm/string.hpp>
14
#include <boost/algorithm/string/case_conv.hpp>
15
#include <boost/algorithm/string/trim.hpp>
16
#include <utf8cpp/utf8.h>
17

18
#include "logfacility.h"
19
#include "stlutil.h"
20

21

22
namespace Pol::Clib
23
{
24
void splitnamevalue( const std::string& istr, std::string& propname, std::string& propvalue )
162,222✔
25
{
26
  std::string::size_type start = istr.find_first_not_of( " \t\r\n" );
162,222✔
27
  if ( start != std::string::npos )
162,222✔
28
  {
29
    std::string::size_type delimpos = istr.find_first_of( " \t\r\n=", start + 1 );
152,442✔
30
    if ( delimpos != std::string::npos )
152,442✔
31
    {
32
      std::string::size_type valuestart = istr.find_first_not_of( " \t\r\n", delimpos + 1 );
133,724✔
33
      std::string::size_type valueend = istr.find_last_not_of( " \t\r\n" );
133,724✔
34
      propname = istr.substr( start, delimpos - start );
133,724✔
35
      if ( valuestart != std::string::npos && valueend != std::string::npos )
133,724✔
36
      {
37
        propvalue = istr.substr( valuestart, valueend - valuestart + 1 );
133,575✔
38
      }
39
      else
40
      {
41
        propvalue = "";
149✔
42
      }
43
    }
44
    else
45
    {
46
      propname = istr.substr( start, std::string::npos );
18,718✔
47
      propvalue = "";
18,718✔
48
    }
49
  }
50
  else
51
  {
52
    propname = "";
9,780✔
53
    propvalue = "";
9,780✔
54
  }
55
}
162,222✔
56

57
void decodequotedstring( std::string& str )
8✔
58
{
59
  if ( str.empty() )
8✔
60
    return;
8✔
61
  std::string tmp;
8✔
62
  tmp.swap( str );
8✔
63
  const char* s = tmp.c_str();
8✔
64
  str.reserve( tmp.size() );
8✔
65
  ++s;
8✔
66
  while ( *s )
50✔
67
  {
68
    char ch = *s++;
50✔
69

70
    switch ( ch )
50✔
71
    {
72
    case '\\':
1✔
73
      ch = *s++;
1✔
74
      switch ( ch )
1✔
75
      {
76
      case '\0':
×
77
        return;
×
78
      case 'n':  // newline
×
79
        str += "\n";
×
80
        break;
×
81
      default:  // slash, quote, etc
1✔
82
        str += ch;
1✔
83
        break;
1✔
84
      }
85
      break;
1✔
86

87
    case '\"':
8✔
88
      return;
8✔
89

90
    default:
41✔
91
      str += ch;
41✔
92
      break;
41✔
93
    }
94
  }
95
}
8✔
96
void encodequotedstring( std::string& str )
20,176✔
97
{
98
  std::string tmp;
20,176✔
99
  tmp.swap( str );
20,176✔
100
  const char* s = tmp.c_str();
20,176✔
101
  str.reserve( tmp.size() + 2 );
20,176✔
102
  str += "\"";
20,176✔
103

104
  while ( *s )
101,766✔
105
  {
106
    char ch = *s++;
81,590✔
107
    switch ( ch )
81,590✔
108
    {
109
    case '\\':
177✔
110
      str += "\\\\";
177✔
111
      break;
177✔
112
    case '\"':
28✔
113
      str += "\\\"";
28✔
114
      break;
28✔
115
    case '\n':
101✔
116
      str += "\\n";
101✔
117
      break;
101✔
118
    default:
81,284✔
119
      str += ch;
81,284✔
120
      break;
81,284✔
121
    }
122
  }
123

124
  str += "\"";
20,176✔
125
}
20,176✔
126

127
std::string getencodedquotedstring( const std::string& in )
20,172✔
128
{
129
  std::string tmp = in;
20,172✔
130
  encodequotedstring( tmp );
20,172✔
131
  return tmp;
20,172✔
132
}
×
133

134
// If we have boost, I think we should use it...
135
void mklowerASCII( std::string& str )
9,512✔
136
{
137
  boost::to_lower( str );
9,512✔
138
}
9,512✔
139

140
void mkupperASCII( std::string& str )
33✔
141
{
142
  boost::to_upper( str );
33✔
143
}
33✔
144

145
std::string strlowerASCII( const std::string& str )
2,867✔
146
{
147
  return boost::to_lower_copy( str );
2,867✔
148
}
149

150
std::string strupperASCII( const std::string& str )
×
151
{
152
  return boost::to_upper_copy( str );
×
153
}
154

155
std::string strtrim( const std::string& str )
13✔
156
{
157
  return boost::trim_copy( str );
13✔
158
}
159

160
bool isValidUnicode( const std::string& str )
255,719✔
161
{
162
  return utf8::find_invalid( str.begin(), str.end() ) == str.end();
255,719✔
163
}
164

165
void sanitizeUnicodeWithIso( std::string* str )
206,350✔
166
{
167
  if ( isValidUnicode( *str ) )
206,350✔
168
    return;
206,338✔
169
  // assume iso8859
170
  std::string utf8( "" );
12✔
171
  utf8.reserve( 2 * str->size() + 1 );
12✔
172

173
  for ( const auto& s : *str )
567✔
174
  {
175
    if ( !( s & 0x80 ) )
555✔
176
    {
177
      utf8.push_back( s );
536✔
178
    }
179
    else
180
    {
181
      utf8.push_back( 0xc2 | ( (unsigned char)( s ) >> 6 ) );
19✔
182
      utf8.push_back( 0xbf & s );
19✔
183
    }
184
  }
185
  *str = utf8;
12✔
186
}
12✔
187

188
void sanitizeUnicode( std::string* str )
445✔
189
{
190
  if ( !isValidUnicode( *str ) )
445✔
191
  {
192
    try
193
    {
194
      std::string new_s;
×
195
      utf8::replace_invalid( str->begin(), str->end(), std::back_inserter( new_s ) );
×
196
      *str = new_s;
×
197
    }
×
198
    catch ( utf8::exception& )
×
199
    {
200
      *str = "Invalid unicode";
×
201
    }
×
202
  }
203
  auto begin = str->begin();
445✔
204
  auto end = str->end();
445✔
205
  auto invalid_chr = []( u32 c )
490✔
206
  {
207
    return ( c >= 0x1u && c < 0x9u ) /*0x9 \t 0x10 \n*/ ||
490✔
208
           ( c >= 0x11u && c < 0x13u ) /*0x13 \r*/ || ( c >= 0x14u && c < 0x20u ) || c == 0x7Fu ||
995✔
209
           ( c >= 0x80u && c <= 0x9Fu );
505✔
210
  };
211
  while ( begin != end )
929✔
212
  {
213
    auto c = utf8::unchecked::next( begin );
487✔
214
    if ( invalid_chr( c ) )
487✔
215
    {
216
      // control character found build new string skipping them
217
      std::string new_s;
3✔
218
      begin = str->begin();
3✔
219
      while ( begin != end )
6✔
220
      {
221
        c = utf8::unchecked::next( begin );
3✔
222
        if ( invalid_chr( c ) )
3✔
223
          continue;
3✔
224
        utf8::unchecked::append( c, std::back_inserter( new_s ) );
×
225
      }
226
      *str = new_s;
3✔
227
      break;
3✔
228
    }
3✔
229
  }
230
}
445✔
231

232
void remove_bom( std::string* strbuf )
27,375✔
233
{
234
  if ( strbuf->size() >= 3 )
27,375✔
235
  {
236
    if ( utf8::starts_with_bom( strbuf->cbegin(), strbuf->cend() ) )
27,200✔
237
      strbuf->erase( 0, 3 );
18✔
238
  }
239
}
27,375✔
240

241
uint8_t unicodeToCp1252( uint32_t codepoint )
1,915✔
242
{
243
  if ( codepoint >= 0x80 && codepoint <= 0x9f )
1,915✔
244
    return '?';
×
245
  if ( codepoint <= 0xff )
1,915✔
246
    return (char)codepoint;
1,888✔
247

248
  switch ( codepoint )
27✔
249
  {
250
  case 0x20AC:
1✔
251
    return 128;  // €
1✔
252
  case 0x201A:
1✔
253
    return 130;  // ‚
1✔
254
  case 0x0192:
1✔
255
    return 131;  // ƒ
1✔
256
  case 0x201E:
1✔
257
    return 132;  // „
1✔
258
  case 0x2026:
1✔
259
    return 133;  // …
1✔
260
  case 0x2020:
1✔
261
    return 134;  // †
1✔
262
  case 0x2021:
1✔
263
    return 135;  // ‡
1✔
264
  case 0x02C6:
1✔
265
    return 136;  // ˆ
1✔
266
  case 0x2030:
1✔
267
    return 137;  // ‰
1✔
268
  case 0x0160:
1✔
269
    return 138;  // Š
1✔
270
  case 0x2039:
1✔
271
    return 139;  // ‹
1✔
272
  case 0x0152:
1✔
273
    return 140;  // Œ
1✔
274
  case 0x017D:
1✔
275
    return 142;  // Ž
1✔
276
  case 0x2018:
1✔
277
    return 145;  // ‘
1✔
278
  case 0x2019:
1✔
279
    return 146;  // ’
1✔
280
  case 0x201C:
1✔
281
    return 147;  // “
1✔
282
  case 0x201D:
1✔
283
    return 148;  // ”
1✔
284
  case 0x2022:
1✔
285
    return 149;  // •
1✔
286
  case 0x2013:
1✔
287
    return 150;  // –
1✔
288
  case 0x2014:
1✔
289
    return 151;  // —
1✔
290
  case 0x02DC:
1✔
291
    return 152;  // ˜
1✔
292
  case 0x2122:
1✔
293
    return 153;  // ™
1✔
294
  case 0x0161:
1✔
295
    return 154;  // š
1✔
296
  case 0x203A:
1✔
297
    return 155;  // ›
1✔
298
  case 0x0153:
1✔
299
    return 156;  // œ
1✔
300
  case 0x017E:
1✔
301
    return 158;  // ž
1✔
302
  case 0x0178:
1✔
303
    return 159;  // Ÿ
1✔
NEW
304
  default:
×
NEW
305
    return '?';
×
306
  }
307
}
308

309
uint32_t cp1252ToUnicode( uint8_t codepoint )
218✔
310
{
311
  switch ( codepoint )
218✔
312
  {
313
  case 128:
1✔
314
    return 0x20AC;  // €
1✔
315
  case 130:
1✔
316
    return 0x201A;  // ‚
1✔
317
  case 131:
1✔
318
    return 0x0192;  // ƒ
1✔
319
  case 132:
1✔
320
    return 0x201E;  // „
1✔
321
  case 133:
1✔
322
    return 0x2026;  // …
1✔
323
  case 134:
1✔
324
    return 0x2020;  // †
1✔
325
  case 135:
1✔
326
    return 0x2021;  // ‡
1✔
327
  case 136:
1✔
328
    return 0x02C6;  // ˆ
1✔
329
  case 137:
1✔
330
    return 0x2030;  // ‰
1✔
331
  case 138:
1✔
332
    return 0x0160;  // Š
1✔
333
  case 139:
1✔
334
    return 0x2039;  // ‹
1✔
335
  case 140:
1✔
336
    return 0x0152;  // Œ
1✔
337
  case 142:
1✔
338
    return 0x017D;  // Ž
1✔
339
  case 145:
1✔
340
    return 0x2018;  // ‘
1✔
341
  case 146:
1✔
342
    return 0x2019;  // ’
1✔
343
  case 147:
1✔
344
    return 0x201C;  // “
1✔
345
  case 148:
1✔
346
    return 0x201D;  // ”
1✔
347
  case 149:
1✔
348
    return 0x2022;  // •
1✔
349
  case 150:
1✔
350
    return 0x2013;  // –
1✔
351
  case 151:
1✔
352
    return 0x2014;  // —
1✔
353
  case 152:
1✔
354
    return 0x02DC;  // ˜
1✔
355
  case 153:
1✔
356
    return 0x2122;  // ™
1✔
357
  case 154:
1✔
358
    return 0x0161;  // š
1✔
359
  case 155:
1✔
360
    return 0x203A;  // ›
1✔
361
  case 156:
1✔
362
    return 0x0153;  // œ
1✔
363
  case 158:
1✔
364
    return 0x017E;  // ž
1✔
365
  case 159:
1✔
366
    return 0x0178;  // Ÿ
1✔
367
  default:
191✔
368
    return codepoint;
191✔
369
  }
370
}
371

372
std::string strUtf8ToCp1252( const std::string& utf8string )
197✔
373
{
374
  auto itr = utf8string.begin();
197✔
375
  auto end = utf8string.end();
197✔
376
  std::string outstring;
197✔
377
  while ( itr != end )
2,112✔
378
  {
379
    auto c = unicodeToCp1252( utf8::unchecked::next( itr ) );
1,915✔
380
    outstring.push_back( c );
1,915✔
381
  }
382
  return outstring;
394✔
383
}
×
384

385
std::string strCp1252ToUtf8( const std::string& cp1252string )
1✔
386
{
387
  auto itr = cp1252string.begin();
1✔
388
  auto end = cp1252string.end();
1✔
389
  std::string outstring;
1✔
390
  auto inserter = std::back_inserter( outstring );
1✔
391
  while ( itr != end )
219✔
392
  {
393
    utf8::unchecked::append( cp1252ToUnicode( *itr++ ), inserter );
218✔
394
  }
395
  return outstring;
2✔
396
}
×
397

398
bool caseInsensitiveEqual( const std::string& input, const std::string& test )
30,834✔
399
{
400
  return boost::iequals( input, test );
30,834✔
401
}
402

403
std::wstring to_wstring( const std::string& value )
153✔
404
{
405
  std::wstring result;
153✔
406
  if constexpr ( sizeof( wchar_t ) == sizeof( unsigned short ) )
407
  {
408
    utf8::unchecked::utf8to16( value.begin(), value.end(), std::back_inserter( result ) );
409
  }
410
  else
411
  {
412
    utf8::unchecked::utf8to32( value.begin(), value.end(), std::back_inserter( result ) );
153✔
413
  }
414

415
  return result;
153✔
416
}
×
417
}  // namespace Pol::Clib
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc