LCOV - code coverage report
Current view: top level - include - Utils.h (source / functions) Hit Total Coverage
Test: cpp-bencoding code coverage Lines: 8 8 100.0 %
Date: 2018-04-21 15:28:44 Functions: 3 3 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /**
       2             : * @file      Utils.h
       3             : * @copyright (c) 2014 by Petr Zemek (s3rvac@gmail.com) and contributors
       4             : * @license   BSD, see the @c LICENSE file for more details
       5             : * @brief     Utilities.
       6             : */
       7             : 
       8             : #ifndef BENCODING_UTILS_H
       9             : #define BENCODING_UTILS_H
      10             : 
      11             : #include <ios>
      12             : #include <istream>
      13             : #include <queue>
      14             : #include <sstream>
      15             : #include <stack>
      16             : #include <string>
      17             : 
      18             : namespace bencoding {
      19             : 
      20             : /// @name Conversions
      21             : /// @{
      22             : 
      23             : /**
      24             : * @brief Converts the given string into a number
      25             : *
      26             : * @param[in] str String to be converted into a number.
      27             : * @param[out] num Place to store the converted number.
      28             : * @param[in] format Number format (e.g. std::dec or std::hex).
      29             : *
      30             : * @return @c true if the conversion was successful, @c false otherwise.
      31             : *
      32             : * If the conversion fails, @a num is left unchanged.
      33             : */
      34             : template<typename N>
      35          51 : bool strToNum(const std::string &str, N &num,
      36             :         std::ios_base &(* format)(std::ios_base &) = std::dec) {
      37         102 :     std::istringstream stream(str);
      38          51 :     N convNum = 0;
      39          51 :     stream >> format >> convNum;
      40          51 :     if (!stream.fail() && stream.eof()) {
      41          42 :         num = convNum;
      42          42 :         return true;
      43             :     }
      44           9 :     return false;
      45             : }
      46             : 
      47             : /// @}
      48             : 
      49             : /// @name Data Reading
      50             : /// @{
      51             : 
      52             : bool readUpTo(std::istream &stream, std::string &readData, char sentinel);
      53             : bool readUntil(std::istream &stream, std::string &readData, char last);
      54             : 
      55             : /// @}
      56             : 
      57             : /// @name String Operations
      58             : /// @{
      59             : 
      60             : std::string replace(const std::string &str, char what,
      61             :     const std::string &withWhat);
      62             : 
      63             : /// @}
      64             : 
      65             : } // namespace bencoding
      66             : 
      67             : #endif

Generated by: LCOV version 1.13