src/rfc/combine_field_values.cpp

92.6% Lines (25/27) 100.0% List of functions (1/1)
combine_field_values.cpp
f(x) Functions (1)
Line TLA Hits Source Code
1 //
2 // Copyright (c) 2021 Vinnie Falco (vinnie.falco@gmail.com)
3 //
4 // Distributed under the Boost Software License, Version 1.0. (See accompanying
5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 //
7 // Official repository: https://github.com/cppalliance/http
8 //
9
10 #include <boost/http/rfc/combine_field_values.hpp>
11
12 namespace boost {
13 namespace http {
14
15 core::string_view
16 8x combine_field_values(
17 fields_base::subrange const& vr,
18 grammar::recycled_ptr<std::string>& temp)
19 {
20 8x core::string_view result;
21 8x bool acquired = false;
22 19x for(auto s : vr)
23 {
24 11x if(s.empty())
25 continue;
26 11x if(result.empty())
27 {
28 7x result = s;
29 }
30 4x else if(! acquired)
31 {
32 3x acquired = true;
33 3x if(temp.empty())
34 temp.acquire();
35 3x temp->clear();
36 3x temp->reserve(
37 3x result.size() +
38 3x 1 + s.size());
39 3x *temp = result;
40 3x temp->push_back(',');
41 3x temp->append(
42 s.data(), s.size());
43 3x result = *temp;
44 }
45 else
46 {
47 1x temp->reserve(
48 1x temp->size() +
49 1x 1 + s.size());
50 1x temp->push_back(',');
51 1x temp->append(
52 s.data(), s.size());
53 1x result = *temp;
54 }
55 }
56 8x return result;
57 }
58
59 } // http
60 } // boost
61