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

randombit / botan / 5123321399

30 May 2023 04:06PM UTC coverage: 92.213% (+0.004%) from 92.209%
5123321399

Pull #3558

github

web-flow
Merge dd72f7389 into 057bcbc35
Pull Request #3558: Add braces around all if/else statements

75602 of 81986 relevant lines covered (92.21%)

11859779.3 hits per line

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

83.33
/src/lib/utils/read_cfg.cpp
1
/*
2
* Simple config/test file reader
3
* (C) 2013,2014,2015 Jack Lloyd
4
*
5
* Botan is released under the Simplified BSD License (see license.txt)
6
*/
7

8
#include <botan/internal/parsing.h>
9

10
#include <botan/exceptn.h>
11

12
namespace Botan {
13

14
namespace {
15

16
std::string clean_ws(std::string_view s) {
1,416✔
17
   const char* ws = " \t\n";
1,416✔
18
   auto start = s.find_first_not_of(ws);
1,416✔
19
   auto end = s.find_last_not_of(ws);
1,416✔
20

21
   if(start == std::string::npos) {
1,416✔
22
      return "";
×
23
   }
24

25
   if(end == std::string::npos) {
1,416✔
26
      return std::string(s.substr(start, end));
×
27
   } else {
28
      return std::string(s.substr(start, start + end + 1));
2,832✔
29
   }
30
}
31

32
}  // namespace
33

34
std::map<std::string, std::string> read_cfg(std::istream& is) {
78✔
35
   std::map<std::string, std::string> kv;
78✔
36
   size_t line = 0;
78✔
37

38
   while(is.good()) {
635✔
39
      std::string s;
557✔
40

41
      std::getline(is, s);
557✔
42

43
      ++line;
557✔
44

45
      if(s.empty() || s[0] == '#') {
557✔
46
         continue;
85✔
47
      }
48

49
      s = clean_ws(s.substr(0, s.find('#')));
930✔
50

51
      if(s.empty()) {
472✔
52
         continue;
×
53
      }
54

55
      auto eq = s.find('=');
472✔
56

57
      if(eq == std::string::npos || eq == 0 || eq == s.size() - 1) {
472✔
58
         throw Decoding_Error("Bad read_cfg input '" + s + "' on line " + std::to_string(line));
×
59
      }
60

61
      const std::string key = clean_ws(s.substr(0, eq));
472✔
62
      const std::string val = clean_ws(s.substr(eq + 1, std::string::npos));
472✔
63

64
      kv[key] = val;
944✔
65
   }
1,334✔
66

67
   return kv;
78✔
68
}
×
69

70
}  // namespace Botan
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