Skip to content

Commit

Permalink
clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaut committed Dec 25, 2023
1 parent 0a9d08f commit 9ae3a11
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 28 deletions.
7 changes: 3 additions & 4 deletions test/scan-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ template <> struct scanner<num> {
template <class ScanContext>
auto scan(num&, ScanContext& ctx) const -> typename ScanContext::iterator {
// TODO
//return fmt::scan({ctx.begin(), ctx.end()}, "{}", n.value);
// return fmt::scan({ctx.begin(), ctx.end()}, "{}", n.value);
return ctx.begin();
}
};
Expand All @@ -105,7 +105,7 @@ TEST(scan_test, read_custom) {
auto input = "42";
auto n = num();
fmt::scan(input, "{:}", n);
//EXPECT_EQ(n, 42);
// EXPECT_EQ(n, 42);
}
#endif

Expand Down Expand Up @@ -151,8 +151,7 @@ TEST(scan_test, lock) {

std::thread producer([&]() {
fmt::string_view input = "42 ";
for (int i = 0; i < 1000; ++i)
write_end.write(input.data(), input.size());
for (int i = 0; i < 1000; ++i) write_end.write(input.data(), input.size());
write_end.close();
});

Expand Down
33 changes: 9 additions & 24 deletions test/scan.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,9 @@
FMT_BEGIN_NAMESPACE
namespace detail {

inline bool is_whitespace(char c) {
return c == ' ' || c == '\n';
}
inline bool is_whitespace(char c) { return c == ' ' || c == '\n'; }

template <typename T>
class optional {
template <typename T> class optional {
private:
T value_;
bool has_value_ = false;
Expand All @@ -28,9 +25,7 @@ class optional {
optional() = default;
optional(T value) : value_(std::move(value)), has_value_(true) {}

explicit operator bool() const {
return has_value_;
}
explicit operator bool() const { return has_value_; }

const T& operator*() const {
if (!has_value_) throw std::runtime_error("bad optional access");
Expand Down Expand Up @@ -65,9 +60,7 @@ class scan_buffer {

const char* ptr() const { return ptr_; }

auto peek() -> int {
return ptr_ != end_ ? *ptr_ : EOF;
}
auto peek() -> int { return ptr_ != end_ ? *ptr_ : EOF; }

public:
scan_buffer(const scan_buffer&) = delete;
Expand Down Expand Up @@ -245,12 +238,8 @@ class file_scan_buffer : public scan_buffer {
decltype(get_file(static_cast<FILE*>(nullptr), 0)) file_;

#ifdef _WIN32
static void flockfile(FILE* f) {
_lock_file(f);
}
static void funlockfile(FILE* f) {
_unlock_file(file_);
}
static void flockfile(FILE* f) { _lock_file(f); }
static void funlockfile(FILE* f) { _unlock_file(file_); }
#endif

void fill() {
Expand Down Expand Up @@ -278,9 +267,7 @@ class file_scan_buffer : public scan_buffer {
flockfile(f);
fill();
}
~file_scan_buffer() {
funlockfile(file_);
}
~file_scan_buffer() { funlockfile(file_); }
};
} // namespace detail

Expand Down Expand Up @@ -319,9 +306,7 @@ struct scan_context {
auto begin() const -> iterator { return buf_.begin(); }
auto end() const -> iterator { return buf_.end(); }

void advance_to(iterator) {
buf_.consume();
}
void advance_to(iterator) { buf_.consume(); }
};

namespace detail {
Expand Down Expand Up @@ -424,7 +409,7 @@ struct scan_handler : error_handler {
if (c < '0' || c > '9') break;
} while (it != end);
scan_ctx_.advance_to(it);

// Check overflow.
if (num_digits <= std::numeric_limits<int>::digits10) return value;
const unsigned max = to_unsigned((std::numeric_limits<int>::max)());
Expand Down

0 comments on commit 9ae3a11

Please sign in to comment.