Skip to content

Commit fc59957

Browse files
committed
[#3210] address review
1 parent 54d0219 commit fc59957

File tree

5 files changed

+158
-129
lines changed

5 files changed

+158
-129
lines changed

src/lib/util/filesystem.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ getContent(string const& file_name) {
4242
}
4343
string content;
4444
file >> content;
45-
return content;
45+
return (content);
4646
}
4747

4848
bool
@@ -148,7 +148,7 @@ Path::replaceExtension(string const& replacement) {
148148
extension_ = trimmed_replacement.substr(last_dot);
149149
}
150150
}
151-
return *this;
151+
return (*this);
152152
}
153153

154154
Path&
@@ -161,7 +161,7 @@ Path::replaceParentPath(string const& replacement) {
161161
} else {
162162
parent_path_ = trimmed_replacement + '/';
163163
}
164-
return *this;
164+
return (*this);
165165
}
166166

167167
} // namespace file

src/lib/util/filesystem.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ struct Path {
7373
///
7474
/// Counterpart for std::filesystem::path::stem.
7575
///
76-
/// \return the base name of the file without the extension.
76+
/// \return the base name of current path without the extension.
7777
std::string stem() const;
7878

7979
/// \brief Get the extension of the file.
@@ -83,9 +83,9 @@ struct Path {
8383
/// \return extension of current path.
8484
std::string extension() const;
8585

86-
/// \brief Get the extension of the file.
86+
/// \brief Get the name of the file, extension included.
8787
///
88-
/// Counterpart for std::filesystem::path::extension.
88+
/// Counterpart for std::filesystem::path::filename.
8989
///
9090
/// \return name + extension of current path.
9191
std::string filename() const;

src/lib/util/io.h

+22-19
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ namespace util {
2323
///
2424
/// \return Value of the integer.
2525
template <typename uint_t>
26-
uint_t
26+
constexpr uint_t
2727
readUint(void const* const buffer, size_t const length) {
2828
constexpr size_t size(sizeof(uint_t));
2929
if (length < size) {
@@ -33,10 +33,11 @@ readUint(void const* const buffer, size_t const length) {
3333
}
3434

3535
uint8_t const* const byte_buffer(static_cast<uint8_t const*>(buffer));
36-
uint_t result;
37-
uint8_t* pointer_to_result(static_cast<uint8_t*>(static_cast<void*>(&result)));
36+
uint_t result(0);
3837

39-
std::reverse_copy(byte_buffer, byte_buffer + size, pointer_to_result);
38+
for (size_t i = 0; i < size; ++i) {
39+
result |= (static_cast<uint_t>(byte_buffer[i])) << (8 * (size - (i + 1)));
40+
}
4041

4142
return (result);
4243
}
@@ -51,7 +52,7 @@ readUint(void const* const buffer, size_t const length) {
5152
///
5253
/// \return pointer to the next byte after stored value
5354
template <typename uint_t>
54-
uint8_t*
55+
constexpr uint8_t*
5556
writeUint(uint_t const value, void* const buffer, size_t const length) {
5657
constexpr size_t size(sizeof(uint_t));
5758
if (length < size) {
@@ -60,48 +61,50 @@ writeUint(uint_t const value, void* const buffer, size_t const length) {
6061
<< (length == 1 ? "" : "s") << " instead");
6162
}
6263

63-
uint8_t const* pointer_to_value(static_cast<uint8_t const*>(static_cast<void const*>(&value)));
6464
uint8_t* byte_buffer(static_cast<uint8_t*>(buffer));
6565

66-
std::reverse_copy(pointer_to_value, pointer_to_value + size, byte_buffer);
66+
for (size_t i = 0; i < size; ++i) {
67+
uint8_t const shift_by(8 * (size - (i + 1)));
68+
byte_buffer[i] = uint8_t((value & (uint_t(0xff) << shift_by)) >> shift_by);
69+
}
6770

6871
return (byte_buffer + size);
6972
}
7073

7174
/// \brief uint16_t wrapper over readUint.
72-
inline uint16_t
75+
constexpr inline uint16_t
7376
readUint16(void const* const buffer, size_t const length) {
74-
return readUint<uint16_t>(buffer, length);
77+
return (readUint<uint16_t>(buffer, length));
7578
}
7679

7780
/// \brief uint32_t wrapper over readUint.
78-
inline uint32_t
81+
constexpr inline uint32_t
7982
readUint32(void const* const buffer, size_t const length) {
80-
return readUint<uint32_t>(buffer, length);
83+
return (readUint<uint32_t>(buffer, length));
8184
}
8285

8386
/// \brief uint16_t wrapper over readUint.
84-
inline uint64_t
87+
constexpr inline uint64_t
8588
readUint64(void const* const buffer, size_t const length) {
86-
return readUint<uint64_t>(buffer, length);
89+
return (readUint<uint64_t>(buffer, length));
8790
}
8891

8992
/// \brief uint16_t wrapper over writeUint.
90-
inline uint8_t*
93+
constexpr inline uint8_t*
9194
writeUint16(uint16_t const value, void* const buffer, size_t const length) {
92-
return writeUint(value, buffer, length);
95+
return (writeUint(value, buffer, length));
9396
}
9497

9598
/// \brief uint32_t wrapper over writeUint.
96-
inline uint8_t*
99+
constexpr inline uint8_t*
97100
writeUint32(uint32_t const value, void* const buffer, size_t const length) {
98-
return writeUint(value, buffer, length);
101+
return (writeUint(value, buffer, length));
99102
}
100103

101104
/// \brief uint64_t wrapper over writeUint.
102-
inline uint8_t*
105+
constexpr inline uint8_t*
103106
writeUint64(uint64_t const value, void* const buffer, size_t const length) {
104-
return writeUint(value, buffer, length);
107+
return (writeUint(value, buffer, length));
105108
}
106109

107110
} // namespace util

src/lib/util/str.cc

+4-4
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,21 @@ namespace str {
3131
string
3232
trim(const string& input) {
3333
if (input.empty()) {
34-
return string();
34+
return (string());
3535
}
3636
static const char* blanks = " \t\n";
3737

3838
// Search for first non-blank character in the string.
3939
size_t const first(input.find_first_not_of(blanks));
4040
if (first == string::npos) {
41-
return string();
41+
return (string());
4242
}
4343

4444
// String not all blanks, so look for last character.
4545
size_t const last(input.find_last_not_of(blanks));
4646

4747
// Extract the trimmed substring.
48-
return input.substr(first, (last - first + 1));
48+
return (input.substr(first, (last - first + 1)));
4949
}
5050

5151
vector<string>
@@ -329,7 +329,7 @@ isPrintable(const vector<uint8_t>& content) {
329329
string
330330
dumpAsHex(const uint8_t* data, size_t length) {
331331
stringstream output;
332-
for (unsigned int i = 0; i < length; i++) {
332+
for (size_t i = 0; i < length; ++i) {
333333
if (i) {
334334
output << ":";
335335
}

0 commit comments

Comments
 (0)