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

BlueBrain / MorphIO / 11255477262

09 Oct 2024 12:28PM UTC coverage: 77.697% (+0.08%) from 77.615%
11255477262

Pull #476

github

mgeplf
comments
Pull Request #476: Efficient swc build

286 of 321 new or added lines in 10 files covered. (89.1%)

9 existing lines in 4 files now uncovered.

2125 of 2735 relevant lines covered (77.7%)

901.01 hits per line

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

92.31
/src/readers/utils.cpp
1
#include "./utils.h"
2

3
namespace morphio {
4
#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
5
#define freelocale _free_locale
6
#define strtol_l _strtol_l
7

8
#ifdef MORPHIO_USE_DOUBLE
9
#define strto_float _strtod_l
10
#else
11
#define strto_float _strtof_l
12
#endif
13

14
#else  // not WIN32
15

16
#ifdef MORPHIO_USE_DOUBLE
17
#define strto_float strtod_l
18
#else
19
#define strto_float strtof_l
20
#endif
21

22
#endif
23

24
// Only create the `locale` to facilitate number handling once
25
StringToNumber::StringToNumber()
114✔
26
#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
27
    // On windows, use their locale handling for their runtime
28
    : locale(_create_locale(LC_ALL, "C")) {
29
}
30
#else
31
    // On other platforms, use the POSIX version
32
    : locale(newlocale(LC_NUMERIC_MASK, "POSIX", nullptr)) {
114✔
33
}
114✔
34
#endif
35

36
StringToNumber::~StringToNumber() {
228✔
37
    freelocale(locale);
114✔
38
}
114✔
39

40
std::tuple<int64_t, size_t> StringToNumber::toInt(const std::string& s, size_t offset) const {
2,062✔
41
    const size_t base = 10;
2,062✔
42
    const char *pos = &s[offset];
2,062✔
43
    const char *endpos = &s[s.size()];
2,062✔
44
    int64_t ret = strtol_l(pos, const_cast<char**>(&endpos), base, locale);
2,062✔
45

46
    auto new_offset = static_cast<size_t>(endpos - s.data());
2,062✔
47

48
    if (ret == 0 && new_offset == 0) {
2,062✔
NEW
49
        throw std::invalid_argument("could not parse integer");
×
50
    }
51

52
    return {ret, new_offset};
4,124✔
53
}
54

55
std::tuple<floatType, size_t> StringToNumber::toFloat(const std::string& s, size_t offset) const {
5,224✔
56
    const char *pos = &s[offset];
5,224✔
57
    const char *endpos = &s[s.size()];
5,224✔
58
    floatType ret = strto_float(pos, const_cast<char**>(&endpos), locale);
5,224✔
59

60
    auto new_offset = static_cast<size_t>(endpos - s.data());
5,224✔
61

62
    if (std::fabs(ret - 0) < morphio::epsilon && new_offset == 0) {
5,224✔
NEW
63
        throw std::invalid_argument("could not parse float");
×
64
    }
65

66
    return {ret, new_offset};
10,448✔
67
}
68

69
StringToNumber& getStringToNumber() {
620✔
70
    static StringToNumber stn;
620✔
71
    return stn;
620✔
72
}
73

74
#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
75
#undef freelocale
76
#undef strtol_l
77
#endif
78

79
#undef strto_float
80

81
}  // namespace morphio
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