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

BlueBrain / MorphIO / 11254817533

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

Pull #476

github

mgeplf
Merge remote-tracking branch 'origin/master' into efficient-swc-build
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
StringToNumber::StringToNumber()
114✔
25
#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
26
    : locale(_create_locale(LC_ALL, "C")) {
27
}
28
#else
29
    : locale(newlocale(LC_NUMERIC_MASK, "POSIX", nullptr)) {
114✔
30
}
114✔
31
#endif
32

33
StringToNumber::~StringToNumber() {
228✔
34
    freelocale(locale);
114✔
35
}
114✔
36

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

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

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

49
    return {ret, new_offset};
4,124✔
50
}
51

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

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

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

63
    return {ret, new_offset};
10,448✔
64
}
65

66
StringToNumber& getStringToNumber() {
620✔
67
    static StringToNumber stn;
620✔
68
    return stn;
620✔
69
}
70

71
#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
72
#undef freelocale
73
#undef strtol_l
74
#endif
75

76
#undef strto_float
77

78
}  // 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