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

STEllAR-GROUP / hpx / #882

31 Aug 2023 07:44PM UTC coverage: 41.798% (-44.7%) from 86.546%
#882

push

19442 of 46514 relevant lines covered (41.8%)

126375.38 hits per line

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

86.67
/libs/core/string_util/include/hpx/string_util/split.hpp
1
//  Copyright (c) 2020 ETH Zurich
2
//  Copyright (c) 2002-2006 Pavol Droba
3
//
4
//  SPDX-License-Identifier: BSL-1.0
5
//  Distributed under the Boost Software License, Version 1.0. (See accompanying
6
//  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7

8
#pragma once
9

10
#include <hpx/config.hpp>
11

12
#include <algorithm>
13
#include <cstddef>
14
#include <string>
15
#include <utility>
16

17
namespace hpx::string_util {
18

19
    namespace detail {
20

21
        HPX_CXX_EXPORT template <typename It, typename Char, typename Traits,
22
            typename Allocator>
23
        std::basic_string<Char, Traits, Allocator> substr(
24
            std::basic_string<Char, Traits, Allocator> const& s,
25
            It const& first, It const& last)
26
        {
27
            std::size_t const pos = std::distance(std::begin(s), first);
36,455✔
28
            std::size_t const count = std::distance(first, last);
36,455✔
29
            return s.substr(pos, count);
36,455✔
30
        }
31
    }    // namespace detail
32

33
    HPX_CXX_EXPORT enum class token_compress_mode { off, on };
34

35
    HPX_CXX_EXPORT template <typename Container, typename Predicate,
36
        typename Char, typename Traits, typename Allocator>
37
    void split(Container& container,
38
        std::basic_string<Char, Traits, Allocator> const& str, Predicate&& pred,
39
        token_compress_mode compress_mode = token_compress_mode::off)
40
    {
41
        container.clear();
17,487✔
42

43
        auto token_begin = std::begin(str);
44
        auto token_end = std::end(str);
45

46
        do
47
        {
48
            token_end = std::find_if(token_begin, std::end(str), pred);
49

50
            container.push_back(detail::substr(str, token_begin, token_end));
51

52
            if (token_end != std::end(str))
36,455✔
53
            {
54
                token_begin = token_end + 1;
36,455✔
55
            }
56

36,455✔
57
            if (compress_mode == token_compress_mode::on)
58
            {
59
                // Skip contiguous separators
60
                while (token_begin != std::end(str) &&
61
                    pred(static_cast<int>(*token_begin)))
36,455✔
62
                {
63
                    ++token_begin;
64
                }
×
65
            }
×
66
        } while (token_end != std::end(str));
67
    }
68

69
    HPX_CXX_EXPORT template <typename Container, typename Predicate>
70
    void split(Container& container, char const* str, Predicate&& pred,
36,455✔
71
        token_compress_mode compress_mode = token_compress_mode::off)
17,487✔
72
    {
73
        split(container, std::string{str}, HPX_FORWARD(Predicate, pred),
74
            compress_mode);
248✔
75
    }
76
}    // namespace hpx::string_util
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

© 2025 Coveralls, Inc