clang-format

This commit is contained in:
Victor Zverovich 2023-12-25 09:05:26 -08:00
parent 0a9d08fefd
commit 41c2433358
2 changed files with 13 additions and 29 deletions

View File

@ -95,7 +95,7 @@ template <> struct scanner<num> {
template <class ScanContext> template <class ScanContext>
auto scan(num&, ScanContext& ctx) const -> typename ScanContext::iterator { auto scan(num&, ScanContext& ctx) const -> typename ScanContext::iterator {
// TODO // TODO
//return fmt::scan({ctx.begin(), ctx.end()}, "{}", n.value); // return fmt::scan({ctx.begin(), ctx.end()}, "{}", n.value);
return ctx.begin(); return ctx.begin();
} }
}; };
@ -105,7 +105,7 @@ TEST(scan_test, read_custom) {
auto input = "42"; auto input = "42";
auto n = num(); auto n = num();
fmt::scan(input, "{:}", n); fmt::scan(input, "{:}", n);
//EXPECT_EQ(n, 42); // EXPECT_EQ(n, 42);
} }
#endif #endif
@ -151,8 +151,7 @@ TEST(scan_test, lock) {
std::thread producer([&]() { std::thread producer([&]() {
fmt::string_view input = "42 "; fmt::string_view input = "42 ";
for (int i = 0; i < 1000; ++i) for (int i = 0; i < 1000; ++i) write_end.write(input.data(), input.size());
write_end.write(input.data(), input.size());
write_end.close(); write_end.close();
}); });

View File

@ -14,12 +14,9 @@
FMT_BEGIN_NAMESPACE FMT_BEGIN_NAMESPACE
namespace detail { namespace detail {
inline bool is_whitespace(char c) { inline bool is_whitespace(char c) { return c == ' ' || c == '\n'; }
return c == ' ' || c == '\n';
}
template <typename T> template <typename T> class optional {
class optional {
private: private:
T value_; T value_;
bool has_value_ = false; bool has_value_ = false;
@ -28,9 +25,7 @@ class optional {
optional() = default; optional() = default;
optional(T value) : value_(std::move(value)), has_value_(true) {} optional(T value) : value_(std::move(value)), has_value_(true) {}
explicit operator bool() const { explicit operator bool() const { return has_value_; }
return has_value_;
}
const T& operator*() const { const T& operator*() const {
if (!has_value_) throw std::runtime_error("bad optional access"); if (!has_value_) throw std::runtime_error("bad optional access");
@ -65,9 +60,7 @@ class scan_buffer {
const char* ptr() const { return ptr_; } const char* ptr() const { return ptr_; }
auto peek() -> int { auto peek() -> int { return ptr_ != end_ ? *ptr_ : EOF; }
return ptr_ != end_ ? *ptr_ : EOF;
}
public: public:
scan_buffer(const scan_buffer&) = delete; scan_buffer(const scan_buffer&) = delete;
@ -245,14 +238,11 @@ class file_scan_buffer : public scan_buffer {
decltype(get_file(static_cast<FILE*>(nullptr), 0)) file_; decltype(get_file(static_cast<FILE*>(nullptr), 0)) file_;
#ifdef _WIN32 #ifdef _WIN32
static void flockfile(FILE* f) { static void flockfile(FILE* f) { _lock_file(f); }
_lock_file(f); static void funlockfile(FILE* f) { _unlock_file(f); }
}
static void funlockfile(FILE* f) {
_unlock_file(file_);
}
#endif #endif
// Fills the buffer if it is empty.
void fill() { void fill() {
string_view buf = file_.buffer(); string_view buf = file_.buffer();
if (buf.size() == 0) { if (buf.size() == 0) {
@ -266,7 +256,6 @@ class file_scan_buffer : public scan_buffer {
void consume() override { void consume() override {
// Consume the current buffer content. // Consume the current buffer content.
// TODO: do it more efficiently
size_t n = to_unsigned(ptr() - file_.buffer().begin()); size_t n = to_unsigned(ptr() - file_.buffer().begin());
for (size_t i = 0; i != n; ++i) file_.get(); for (size_t i = 0; i != n; ++i) file_.get();
fill(); fill();
@ -278,9 +267,7 @@ class file_scan_buffer : public scan_buffer {
flockfile(f); flockfile(f);
fill(); fill();
} }
~file_scan_buffer() { ~file_scan_buffer() { funlockfile(file_); }
funlockfile(file_);
}
}; };
} // namespace detail } // namespace detail
@ -319,9 +306,7 @@ struct scan_context {
auto begin() const -> iterator { return buf_.begin(); } auto begin() const -> iterator { return buf_.begin(); }
auto end() const -> iterator { return buf_.end(); } auto end() const -> iterator { return buf_.end(); }
void advance_to(iterator) { void advance_to(iterator) { buf_.consume(); }
buf_.consume();
}
}; };
namespace detail { namespace detail {