Quinoa all test code coverage report
Current view: top level - Base - PrintUtil.cpp (source / functions) Hit Total Coverage
Commit: -128-NOTFOUND Lines: 20 20 100.0 %
Date: 2024-04-29 14:42:33 Functions: 3 3 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 16 28 57.1 %

           Branch data     Line data    Source code
       1                 :            : // *****************************************************************************
       2                 :            : /*!
       3                 :            :   \file      src/Base/PrintUtil.cpp
       4                 :            :   \copyright 2012-2015 J. Bakosi,
       5                 :            :              2016-2018 Los Alamos National Security, LLC.,
       6                 :            :              2019-2021 Triad National Security, LLC.
       7                 :            :              All rights reserved. See the LICENSE file for details.
       8                 :            :   \brief     String conversion utilities
       9                 :            :   \details   Various string conversion utilities.
      10                 :            : */
      11                 :            : // *****************************************************************************
      12                 :            : 
      13                 :            : #include <string>
      14                 :            : #include <sstream>
      15                 :            : #include <algorithm>
      16                 :            : 
      17                 :            : #include "PrintUtil.hpp"
      18                 :            : 
      19                 :            : std::string
      20                 :        199 : tk::splitLines( std::string str,
      21                 :            :                 std::string indent,
      22                 :            :                 const std::string& name,
      23                 :            :                 std::size_t width )
      24                 :            : // *****************************************************************************
      25                 :            : //  Clean up whitespaces and format a long string into multiple lines
      26                 :            : //! \param[in] str String to format
      27                 :            : //! \param[in] name String to insert before string to output
      28                 :            : //! \param[in] indent String to use as identation
      29                 :            : //! \param[in] width Width in characters to insert newlines for output
      30                 :            : //! \see http://stackoverflow.com/a/6892562
      31                 :            : //! \see http://stackoverflow.com/a/8362145
      32                 :            : //! \see https://stackoverflow.com/a/6894764
      33                 :            : // *****************************************************************************
      34                 :            : {
      35                 :            :   // remove form feeds, line feeds, carriage returns, horizontal tabs,
      36                 :            :   // vertical tabs, see http://en.cppreference.com/w/cpp/string/byte/isspace
      37                 :            :   str.erase(
      38                 :            :     std::remove_if( str.begin(), str.end(),
      39                 :        199 :                     []( char x ){ return std::isspace( x ) && x != ' '; } ),
      40                 :        199 :     str.end() );
      41                 :            : 
      42                 :            :   // remove duplicate spaces
      43                 :            :   str.erase(
      44                 :            :     std::unique( str.begin(), str.end(),
      45                 :        199 :                  []( char a, char b ){ return a == b && a == ' '; } ),
      46                 :        199 :     str.end() );
      47                 :            : 
      48                 :            :   // format str to 'width'-character-long lines with indent
      49                 :        398 :   std::istringstream in(str);
      50         [ +  - ]:        398 :   std::ostringstream os;
      51                 :            : 
      52                 :            :   os << indent << name;
      53                 :        199 :   auto current = indent.size();
      54                 :            :   std::string word;
      55                 :            : 
      56 [ +  - ][ +  + ]:        920 :   while (in >> word) {
      57         [ +  + ]:        721 :     if (current + word.size() > width) {
      58         [ +  - ]:          4 :       os << '\n' << indent;
      59                 :          4 :       current = indent.size();
      60                 :            :     }
      61                 :        721 :     os << word << ' ';
      62                 :        721 :     current += word.size() + 1;
      63                 :            :   }
      64                 :            : 
      65                 :        199 :   return os.str();
      66                 :            : }
      67                 :            : 
      68                 :            : std::string
      69                 :      10472 : tk::baselogname( const std::string& executable )
      70                 :            : // *****************************************************************************
      71                 :            : // Calculate base log file name
      72                 :            : //! \param[in] executable Name of the executable
      73                 :            : //! \return Base log file name
      74                 :            : // *****************************************************************************
      75                 :            : {
      76                 :      10472 :   return executable + "_screen.log";
      77                 :            : }
      78                 :            : 
      79                 :            : std::string
      80                 :       7498 : tk::logname( const std::string& executable, int numrestart )
      81                 :            : // *****************************************************************************
      82                 :            : // Construct log file name
      83                 :            : //! \param[in] executable Name of the executable
      84                 :            : //! \param[in] numrestart Number of times restarted
      85                 :            : //! \return The name of the log file to use
      86                 :            : // *****************************************************************************
      87                 :            : {
      88 [ +  - ][ -  + ]:      14996 :   return baselogname( executable ) +
                 [ -  - ]
      89 [ +  + ][ +  - ]:      22538 :          (numrestart ? '.' + std::to_string(numrestart) : "" );
         [ +  - ][ +  - ]
         [ +  + ][ -  - ]
      90                 :            : }

Generated by: LCOV version 1.14