Coverage Report

Created: 2026-03-31 07:01

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/quantlib/ql/utilities/dataformatters.cpp
Line
Count
Source
1
/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3
/*
4
 Copyright (C) 2005 StatPro Italia srl
5
6
 This file is part of QuantLib, a free-software/open-source library
7
 for financial quantitative analysts and developers - http://quantlib.org/
8
9
 QuantLib is free software: you can redistribute it and/or modify it
10
 under the terms of the QuantLib license.  You should have received a
11
 copy of the license along with this program; if not, please email
12
 <quantlib-dev@lists.sf.net>. The license is also available online at
13
 <https://www.quantlib.org/license.shtml>.
14
15
 This program is distributed in the hope that it will be useful, but WITHOUT
16
 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17
 FOR A PARTICULAR PURPOSE.  See the license for more details.
18
*/
19
20
#include <ql/utilities/dataformatters.hpp>
21
#include <ostream>
22
23
namespace QuantLib::detail {
24
25
        std::ostream& operator<<(std::ostream& out,
26
642
                                 const ordinal_holder& holder) {
27
642
            Size n = holder.n;
28
642
            out << n;
29
642
            if (n == Size(11) || n == Size(12) || n == Size(13)) {
30
0
                out << "th";
31
642
            } else {
32
642
                switch (n % 10) {
33
642
                  case 1:  out << "st";  break;
34
0
                  case 2:  out << "nd";  break;
35
0
                  case 3:  out << "rd";  break;
36
0
                  default: out << "th";
37
642
                }
38
642
            }
39
642
            return out;
40
642
        }
41
42
        std::ostream& operator<<(std::ostream& out,
43
0
                                 const percent_holder& holder) {
44
0
            std::ios::fmtflags flags = out.flags();
45
0
            Size width = (Size)out.width();
46
0
            if (width > 2)
47
0
                out.width(width-2); // eat space used by percent sign
48
0
            out << std::fixed;
49
0
            if (holder.value == Null<Real>())
50
0
                out << "null";
51
0
            else
52
0
                out << holder.value * 100.0 << " %";
53
0
            out.flags(flags);
54
0
            return out;
55
0
        }
56
57
    }
58