Skip to content

Commit 036329d

Browse files
committed
Address lint errors
1 parent 98baafd commit 036329d

File tree

4 files changed

+15
-7
lines changed

4 files changed

+15
-7
lines changed

.clang-tidy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ Checks: '*,
3232
-altera-id-dependent-backward-branch,
3333
-bugprone-easily-swappable-parameters,
3434
-modernize-return-braced-init-list,
35+
-abseil-string-find-str-contains,
3536
-cppcoreguidelines-avoid-magic-numbers,
3637
-readability-magic-numbers,
3738
-cppcoreguidelines-avoid-do-while,

cpr/sse.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
#include "cpr/sse.h"
22

3-
#include <algorithm>
4-
#include <cctype>
53
#include <charconv>
4+
#include <utility>
5+
#include <cstddef>
6+
#include <functional>
7+
#include <string>
8+
#include <string_view>
9+
#include <system_error>
610

711
namespace cpr {
812

@@ -46,7 +50,7 @@ bool ServerSentEventParser::processLine(const std::string& line, const std::func
4650
}
4751

4852
// Find the colon separator
49-
size_t colon_pos = line.find(':');
53+
const size_t colon_pos = line.find(':');
5054

5155
std::string field;
5256
std::string value;
@@ -82,7 +86,8 @@ bool ServerSentEventParser::processLine(const std::string& line, const std::func
8286
} else if (field == "retry") {
8387
// Parse retry value as integer
8488
size_t retry_value = 0;
85-
auto [ptr, ec] = std::from_chars(value.data(), value.data() + value.size(), retry_value);
89+
const std::string_view sv(value);
90+
auto [ptr, ec] = std::from_chars(sv.begin(), sv.end(), retry_value);
8691
if (ec == std::errc()) {
8792
current_event_.retry = retry_value;
8893
}
@@ -100,7 +105,7 @@ bool ServerSentEventParser::dispatchEvent(const std::function<bool(ServerSentEve
100105
}
101106

102107
// Invoke callback with the current event
103-
bool continue_parsing = callback(std::move(current_event_));
108+
const bool continue_parsing = callback(std::move(current_event_));
104109

105110
// Reset for next event (but keep event type as "message")
106111
current_event_ = ServerSentEvent();

cpr/util.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "cpr/cprtypes.h"
55
#include "cpr/curlholder.h"
66
#include "cpr/secure_string.h"
7+
#include "cpr/sse.h"
78
#include <algorithm>
89
#include <cctype>
910
#include <chrono>

include/cpr/sse.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include <cstdint>
55
#include <functional>
6+
#include <utility>
67
#include <optional>
78
#include <string>
89
#include <string_view>
@@ -22,7 +23,7 @@ struct ServerSentEvent {
2223
/**
2324
* The event type. If not specified, defaults to "message".
2425
*/
25-
std::string event;
26+
std::string event{"message"};
2627

2728
/**
2829
* The event data. Multiple data fields are concatenated with newlines.
@@ -34,7 +35,7 @@ struct ServerSentEvent {
3435
*/
3536
std::optional<size_t> retry;
3637

37-
ServerSentEvent() : event("message") {}
38+
ServerSentEvent() = default;
3839
};
3940

4041
/**

0 commit comments

Comments
 (0)