Nix 2.93.3
Lix: A modern, delicious implementation of the Nix package manager; unstable internal interfaces
Loading...
Searching...
No Matches
english.hh
Go to the documentation of this file.
1#pragma once
3
4#include <iostream>
5#include <algorithm>
6#include <iterator>
7#include <ranges>
8#include <sstream>
9
10namespace nix {
11
17std::ostream & pluralize(
18 std::ostream & output,
19 unsigned int count,
20 const std::string_view single,
21 const std::string_view plural);
22
23
30template<typename F, std::ranges::input_range R>
31std::string concatStringsCommaAnd(F transform, const R & args)
32{
33 std::stringstream result;
34 if (args.size() != 0) {
35 result << transform(*args.begin());
36 }
37 if (args.size() >= 2) {
38 // will not do anything for size <= 2
39 std::for_each(std::next(args.begin()), std::prev(args.end()), [&](auto const & arg) {
40 result << ", " << transform(arg);
41 });
42 result << " and " << transform(*args.rbegin());
43 }
44 return result.str();
45};
46
47}
std::string concatStringsCommaAnd(F transform, const R &args)
Definition english.hh:31