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

Return-To-The-Roots / libsiedler2 / 41335575034

01 Nov 2026 06:14PM UTC coverage: 87.583% (+4.4%) from 83.224%
41335575034

push

github

Flamefire
Detect *.mid as *.midi files

1 of 1 new or added line in 1 file covered. (100.0%)

32 existing lines in 5 files now uncovered.

4909 of 5605 relevant lines covered (87.58%)

4551.57 hits per line

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

80.77
/src/loadMapping.cpp
1
// Copyright (C) 2005 - 2021 Settlers Freaks (sf-team at siedler25.org)
2
//
3
// SPDX-License-Identifier: GPL-2.0-or-later
4

5
#include "loadMapping.h"
6
#include "s25util/StringConversion.h"
7
#include <boost/algorithm/string.hpp>
8
#include <boost/filesystem/path.hpp>
9
#include <boost/nowide/fstream.hpp>
10

11
namespace libsiedler2 {
12

13
void loadMapping(std::istream& stream, const std::function<void(unsigned idx, const std::string&)>& onItem)
14 ✔
14
{
15
    std::string line;
28 ✔
16
    const std::string delimiters(" \t");
28 ✔
17
    unsigned lineNr = 0;
14 ✔
18
    while(std::getline(stream, line))
302 ✔
19
    {
20
        ++lineNr;
294 ✔
21
        boost::algorithm::trim(line);
294 ✔
22
        if(line.empty() || line[0] == '#')
294 ✔
23
            continue;
10 ✔
24
        try
25
        {
26
            const auto iDelimiter = line.find_first_of(delimiters);
284 ✔
27
            if(iDelimiter == std::string::npos || iDelimiter == 0u)
284 ✔
28
                throw std::runtime_error("No index or value");
1 ✔
29
            const std::string sIdx = line.substr(0, iDelimiter);
566 ✔
30
            int idx;
31
            if(!s25util::tryFromStringClassic(sIdx, idx) || idx < 0)
283 ✔
32
                throw std::runtime_error("Invalid index: " + sIdx);
5 ✔
33
            line.erase(0, iDelimiter + 1);
278 ✔
34
            onItem(static_cast<unsigned>(idx), line);
278 ✔
35
        } catch(const std::exception& e)
12 ✔
36
        {
37
            throw std::runtime_error("Error at line " + std::to_string(lineNr) + ": " + e.what());
6 ✔
38
        }
39
    }
40
    if(!stream.eof())
8 ✔
UNCOV
41
        throw std::runtime_error("Error getting line");
×
42
}
8 ✔
43

UNCOV
44
void loadMapping(const boost::filesystem::path& filepath,
×
45
                 const std::function<void(unsigned idx, const std::string&)>& onItem)
46
{
47
    boost::nowide::ifstream f(filepath);
×
UNCOV
48
    loadMapping(f, onItem);
×
UNCOV
49
}
×
50

51
} // namespace libsiedler2
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc