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

randombit / botan / 5079590438

25 May 2023 12:28PM UTC coverage: 92.228% (+0.5%) from 91.723%
5079590438

Pull #3502

github

Pull Request #3502: Apply clang-format to the codebase

75589 of 81959 relevant lines covered (92.23%)

12139530.51 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
   if(end == std::string::npos)
1,416✔
25
      return std::string(s.substr(start, end));
×
26
   else
27
      return std::string(s.substr(start, start + end + 1));
2,832✔
28
}
29

30
}
31

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

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

39
      std::getline(is, s);
557✔
40

41
      ++line;
557✔
42

43
      if(s.empty() || s[0] == '#')
557✔
44
         continue;
85✔
45

46
      s = clean_ws(s.substr(0, s.find('#')));
930✔
47

48
      if(s.empty())
472✔
49
         continue;
×
50

51
      auto eq = s.find('=');
472✔
52

53
      if(eq == std::string::npos || eq == 0 || eq == s.size() - 1)
472✔
54
         throw Decoding_Error("Bad read_cfg input '" + s + "' on line " + std::to_string(line));
×
55

56
      const std::string key = clean_ws(s.substr(0, eq));
472✔
57
      const std::string val = clean_ws(s.substr(eq + 1, std::string::npos));
472✔
58

59
      kv[key] = val;
944✔
60
   }
1,334✔
61

62
   return kv;
78✔
63
}
×
64

65
}
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