Coverage Report

Created: 2022-08-24 06:55

/src/solidity/libsolutil/CommonIO.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
  This file is part of solidity.
3
4
  solidity is free software: you can redistribute it and/or modify
5
  it under the terms of the GNU General Public License as published by
6
  the Free Software Foundation, either version 3 of the License, or
7
  (at your option) any later version.
8
9
  solidity is distributed in the hope that it will be useful,
10
  but WITHOUT ANY WARRANTY; without even the implied warranty of
11
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
  GNU General Public License for more details.
13
14
  You should have received a copy of the GNU General Public License
15
  along with solidity.  If not, see <http://www.gnu.org/licenses/>.
16
*/
17
// SPDX-License-Identifier: GPL-3.0
18
/** @file CommonIO.h
19
 * @author Gav Wood <i@gavwood.com>
20
 * @date 2014
21
 *
22
 * File & stream I/O routines.
23
 */
24
25
#pragma once
26
27
#include <boost/filesystem.hpp>
28
29
#include <libsolutil/Common.h>
30
#include <iostream>
31
#include <sstream>
32
#include <string>
33
34
namespace solidity
35
{
36
37
inline std::ostream& operator<<(std::ostream& os, bytes const& _bytes)
38
0
{
39
0
  std::ostringstream ss;
40
0
  ss << std::hex;
41
0
  std::copy(_bytes.begin(), _bytes.end(), std::ostream_iterator<int>(ss, ","));
42
0
  std::string result = ss.str();
43
0
  result.pop_back();
44
0
  os << "[" + result + "]";
45
0
  return os;
46
0
}
47
48
namespace util
49
{
50
51
/// Retrieves and returns the contents of the given file as a std::string.
52
/// If the file doesn't exist, it will throw a FileNotFound exception.
53
/// If the file exists but is not a regular file, it will throw NotAFile exception.
54
/// If the file is empty, returns an empty string.
55
std::string readFileAsString(boost::filesystem::path const& _file);
56
57
/// Retrieves and returns the whole content of the specified input stream (until EOF).
58
std::string readUntilEnd(std::istream& _stdin);
59
60
/// Tries to read exactly @a _length bytes from @a _input.
61
/// Returns a string containing as much data as has been read.
62
std::string readBytes(std::istream& _input, size_t _length);
63
64
/// Retrieves and returns a character from standard input (without waiting for EOL).
65
int readStandardInputChar();
66
67
/// Converts arbitrary value to string representation using std::stringstream.
68
template <class T>
69
std::string toString(T const& _t)
70
463k
{
71
463k
  std::ostringstream o;
72
463k
  o << _t;
73
463k
  return o.str();
74
463k
}
std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > solidity::util::toString<unsigned int>(unsigned int const&)
Line
Count
Source
70
463k
{
71
463k
  std::ostringstream o;
72
463k
  o << _t;
73
463k
  return o.str();
74
463k
}
Unexecuted instantiation: std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > solidity::util::toString<boost::multiprecision::number<boost::multiprecision::backends::cpp_int_backend<256u, 256u, (boost::multiprecision::cpp_integer_type)0, (boost::multiprecision::cpp_int_check_type)0, void>, (boost::multiprecision::expression_template_option)0> >(boost::multiprecision::number<boost::multiprecision::backends::cpp_int_backend<256u, 256u, (boost::multiprecision::cpp_integer_type)0, (boost::multiprecision::cpp_int_check_type)0, void>, (boost::multiprecision::expression_template_option)0> const&)
Unexecuted instantiation: std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > solidity::util::toString<unsigned long>(unsigned long const&)
Unexecuted instantiation: std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > solidity::util::toString<long>(long const&)
Unexecuted instantiation: std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > solidity::util::toString<int>(int const&)
Unexecuted instantiation: std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > solidity::util::toString<solidity::util::FixedHash<32u> >(solidity::util::FixedHash<32u> const&)
75
76
/// @returns the absolute path corresponding to @a _path relative to @a _reference.
77
std::string absolutePath(std::string const& _path, std::string const& _reference);
78
79
/// Helper function to return path converted strings.
80
std::string sanitizePath(std::string const& _path);
81
82
}
83
}