Skip to content

Commit

Permalink
style: change format settings
Browse files Browse the repository at this point in the history
  • Loading branch information
OEOTYAN committed Nov 8, 2024
1 parent d5c6ed2 commit f557e2f
Show file tree
Hide file tree
Showing 61 changed files with 195 additions and 176 deletions.
7 changes: 6 additions & 1 deletion .clang-format
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
BasedOnStyle: LLVM
AccessModifierOffset: -4
AlignAfterOpenBracket: BlockIndent
AlignArrayOfStructures: Left
AlignArrayOfStructures: Right
AlignConsecutiveDeclarations:
Enabled: true
AcrossEmptyLines: false
Expand Down Expand Up @@ -44,3 +44,8 @@ PointerAlignment: Left
TabWidth: 4
UseTab: Never
SortIncludes: CaseSensitive
# RemoveEmptyLinesInUnwrappedLines: true
RemoveSemicolon: true
# SeparateDefinitionBlocks: Always
SortUsingDeclarations: LexicographicNumeric
Standard: Latest
14 changes: 14 additions & 0 deletions scripts/encode_dectect.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# execute clang-format at src with multi-threading

import os
import chardet

if __name__ == "__main__":
for path in ["./src", "./src-server", "./src-client", "./src-test"]:
for root, dirs, files in os.walk(path):
for file in files:
if file.endswith(".h") or file.endswith(".cpp"):
with open(os.path.join(root, file), "rb") as f:
d = chardet.detect(f.read())
if d.get('encoding') != 'ascii' and d.get('encoding') != 'utf-8':
print(d, file)
4 changes: 2 additions & 2 deletions src-client/ll/core/gui/ImguiConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ LL_CONFIG_IMPL(LeviImguiConfig, u8"ImguiConfig.json");
std::vector<LeviImguiConfig::Font> LeviImguiConfig::getDefaultFonts() {
if (i18n::getDefaultLocaleCode().starts_with("zh")) {
return {
{"default", Font::GlyphRange::Latins, Font::Width::Half},
{"system", Font::GlyphRange::ChineseFull, Font::Width::Full}
{"default", Font::GlyphRange::Latins, Font::Width::Half},
{ "system", Font::GlyphRange::ChineseFull, Font::Width::Full}
};
}
return {
Expand Down
8 changes: 4 additions & 4 deletions src-client/ll/core/gui/win/GUI.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "ll/core/gui/GUI.h"
#include "ll/core/gui/GUI.h"

#include <cstring>
#include <string>
Expand All @@ -13,10 +13,10 @@

#include "imgui.h"

#include "ll/core/gui/ImGuiAnsiColor.h"
#include "ll/core/gui/ImGuiHooks.h"
#include "ll/api/utils/FontUtils.h"
#include "ll/api/utils/StringUtils.h"
#include "ll/core/gui/ImGuiAnsiColor.h"
#include "ll/core/gui/ImGuiHooks.h"
#include "ll/core/gui/ImguiConfig.h"
#include "ll/core/gui/styles/ImguiSpectrum.h"
#include "ll/core/io/LogPipe.h"
Expand Down Expand Up @@ -131,7 +131,7 @@ void initializeImGui() {
io.IniFilename = nullptr;

io.ConfigFlags |= ImGuiConfigFlags_DockingEnable;

// io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable;
// io.BackendFlags |= ImGuiBackendFlags_PlatformHasViewports;
// io.BackendFlags |= ImGuiBackendFlags_HasMouseHoveredViewport;
Expand Down
38 changes: 19 additions & 19 deletions src-server/ll/api/form/CustomForm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Label : public CustomFormElement {
[[nodiscard]] nlohmann::ordered_json serialize() const override {
return {
{"type", "label"},
{"text", mText }
{"text", mText}
};
}

Expand All @@ -49,7 +49,7 @@ class Input : public CustomFormElement {
[[nodiscard]] nlohmann::ordered_json serialize() const override {
nlohmann::ordered_json input = {
{"type", "input"},
{"text", mText }
{"text", mText}
};
if (!mPlaceholder.empty()) {
input["placeholder"] = mPlaceholder;
Expand Down Expand Up @@ -81,8 +81,8 @@ class Toggle : public CustomFormElement {

[[nodiscard]] nlohmann::ordered_json serialize() const override {
return {
{"type", "toggle"},
{"text", mText },
{ "type", "toggle"},
{ "text", mText},
{"default", mDefault}
};
}
Expand Down Expand Up @@ -110,10 +110,10 @@ class Dropdown : public CustomFormElement {

[[nodiscard]] nlohmann::ordered_json serialize() const override {
return {
{"type", "dropdown"},
{"text", mText },
{"options", mOptions },
{"default", mDefault }
{ "type", "dropdown"},
{ "text", mText},
{"options", mOptions},
{"default", mDefault}
};
}

Expand Down Expand Up @@ -173,11 +173,11 @@ class Slider : public CustomFormElement {
return {};
}
return {
{"type", "slider"},
{"text", mText },
{"min", mMin },
{"max", mMax },
{"step", mStep },
{ "type", "slider"},
{ "text", mText},
{ "min", mMin},
{ "max", mMax},
{ "step", mStep},
{"default", mDefault}
};
}
Expand Down Expand Up @@ -219,10 +219,10 @@ class StepSlider : public CustomFormElement {
return {};
}
return {
{"type", "step_slider"},
{"text", mText },
{"steps", mSteps },
{"default", mDefault }
{ "type", "step_slider"},
{ "text", mText},
{ "steps", mSteps},
{"default", mDefault}
};
}

Expand Down Expand Up @@ -265,8 +265,8 @@ class CustomForm::CustomFormImpl : public FormImpl {

[[nodiscard]] nlohmann::ordered_json serialize() const override {
nlohmann::ordered_json form = {
{"title", mTitle },
{"type", "custom_form" },
{ "title", mTitle},
{ "type", "custom_form"},
{"content", nlohmann::ordered_json::array()}
};
for (auto& e : mElements) {
Expand Down
6 changes: 3 additions & 3 deletions src-server/ll/api/form/ModalForm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ class ModalForm::ModalFormImpl : public FormImpl {

[[nodiscard]] nlohmann::ordered_json serialize() const override {
return {
{"type", "modal" },
{"title", mTitle },
{"content", mContent },
{ "type", "modal"},
{ "title", mTitle},
{"content", mContent},
{"button1", mUpperButton},
{"button2", mLowerButton}
};
Expand Down
6 changes: 3 additions & 3 deletions src-server/ll/api/form/SimpleForm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ class SimpleForm::SimpleFormImpl : public FormImpl {

[[nodiscard]] nlohmann::ordered_json serialize() const override {
nlohmann::ordered_json form = {
{"title", mTitle },
{"type", "form" },
{"content", mContent },
{ "title", mTitle},
{ "type", "form"},
{"content", mContent},
{"buttons", nlohmann::ordered_json::array()}
};
for (auto& e : mElements) {
Expand Down
2 changes: 1 addition & 1 deletion src-server/ll/core/Statistics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ void Statistics::call(bool enable) {
} else if (!enable) {
impl.reset();
}
};
}

Statistics::Statistics() = default;
Statistics::~Statistics() = default;
Expand Down
2 changes: 1 addition & 1 deletion src-server/ll/core/tweak/ForceEnableCheatCommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ void ForceEnableCheatCommands::call(bool enable) {
} else {
impl.reset();
}
};
}

ForceEnableCheatCommands::ForceEnableCheatCommands() = default;
ForceEnableCheatCommands::~ForceEnableCheatCommands() = default;
Expand Down
12 changes: 6 additions & 6 deletions src-test/server/ConfigTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,15 @@ class TestClass {
int plain = 1111;

std::map<std::string, MyPair> amap = {
{"key1", {} },
{"key1", {}},
{"key2", {"a new thing", 42}},
{"key3", {} },
{"key3", {}},
};
std::map<mce::UUID, int> bmap = {
{{}, 4454556 },
{{2, 3}, 4366 },
{{4, 5}, -63556654},
{mce::UUID::random(), -5674236 },
{ {}, 4454556},
{ {2, 3}, 4366},
{ {4, 5}, -63556654},
{mce::UUID::random(), -5674236},
};

Vec2 vec2{};
Expand Down
2 changes: 1 addition & 1 deletion src-test/server/Packet_test.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// #define GENERATE_PACKET
// #define GENERATE_PACKET

#ifdef GENERATE_PACKET

Expand Down
30 changes: 15 additions & 15 deletions src-test/server/TestNbt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,30 @@ LL_AUTO_TYPE_INSTANCE_HOOK(NbtTest, HookPriority::Normal, ServerInstance, &Serve
using namespace ll::literals;

auto nbt = CompoundTag{
{"anull", nullptr },
{"string?", R"(streee _ _o-ix 我超, utf8 "\asfa%"*)##q)$\\"\Q34\\""'':)"_tag},
{"1num", 1 },
{"nums", (int16)3 },
{"byte", (int8)127 },
{"list", ListTag{5_b, ByteTag{true}, ByteTag{false}, -2_b} },
{"compound",
{ "anull", nullptr },
{ "string?", R"(streee _ _o-ix 我超, utf8 "\asfa%"*)##q)$\\"\Q34\\""'':)"_tag},
{ "1num", 1},
{ "nums", (int16)3},
{ "byte", (int8)127},
{ "list", ListTag{5_b, ByteTag{true}, ByteTag{false}, -2_b}},
{ "compound",
CompoundTag{
{"float", 0.1f},
{"long", 10000ull},
{"double", 0.3},
{"sdouble", 1.0},
{"float", 0.1f},
{"long", 10000ull},
{"double", 0.3},
{"sdouble", 1.0},
} },
{"bytearray", ByteArrayTag{1, 2, 3, 4, 5, 62, 63, 66} },
{"intarray", IntArrayTag{1, 2, 3, 4, 5, -2, -3, -6} },
{"bytearray", ByteArrayTag{1, 2, 3, 4, 5, 62, 63, 66}},
{ "intarray", IntArrayTag{1, 2, 3, 4, 5, -2, -3, -6}},
};

nbt["some"]["new"]["compound"] = nbt;
nbt["hello"]["789\xDB\xFE"]["\u123456"] = std::string{R"(\n\t\r\b\u1234\uffffffff)"} + "\xDB\xFE";


nlohmann::json j{
{"num", 1 },
{"nums", (int16)3 },
{ "num", 1},
{"nums", (int16)3},
{"byte", (int8)127}
};
j["some"]["new"]["json"] = 2;
Expand Down
2 changes: 1 addition & 1 deletion src-test/server/testCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ LL_AUTO_TYPE_INSTANCE_HOOK(
"testenum",
{
{"testenumhhhh", 124144},
{"hrshh54w4t4", 67584 }
{ "hrshh54w4t4", 67584}
}
);

Expand Down
2 changes: 1 addition & 1 deletion src/ll/api/base/ToString.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ struct fmt::formatter<T> : fmt::formatter<std::string> {

// std::format support
template <ll::concepts::Stringable T>
struct std::formatter<T> : std::formatter<std::string> { // NOLINT
struct std::formatter<T> : std::formatter<std::string> {
template <class FormatContext>
auto format(T const& t, FormatContext& ctx) const {
return std::formatter<std::string>::format(nonstd::to_string(t), ctx);
Expand Down
4 changes: 2 additions & 2 deletions src/ll/api/coro/CoroTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class CoroTask {
public:
struct ExpectedAwaiter : public WaiterBase {
constexpr ExpectedAwaiter(Handle h) : WaiterBase(h) {}
constexpr ExpectedResult await_resume() noexcept { return WaiterBase::getResult(); };
constexpr ExpectedResult await_resume() noexcept { return WaiterBase::getResult(); }
};

struct ValueAwaiter : public WaiterBase {
Expand All @@ -53,7 +53,7 @@ class CoroTask {
if (handle) {
std::exchange(handle, nullptr).destroy();
}
};
}

constexpr void setExecutor(ExecutorRef ex) { handle.promise().exec = ex; }

Expand Down
9 changes: 8 additions & 1 deletion src/ll/api/data/KeyValueDB.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "ll/api/data/KeyValueDB.h"
#include "ll/api/data/KeyValueDB.h"

#include <filesystem>
#include <functional>
Expand Down Expand Up @@ -59,6 +59,7 @@ KeyValueDB::KeyValueDB(std::filesystem::path const& path, bool createIfMiss, boo
bloomFilterBit
);
}

KeyValueDB::KeyValueDB(std::filesystem::path const& path) : KeyValueDB(path, true, true, 0) {}

KeyValueDB::KeyValueDB(KeyValueDB&&) noexcept = default;
Expand All @@ -75,11 +76,13 @@ std::optional<std::string> KeyValueDB::get(std::string_view key) const {
}
return result;
}

bool KeyValueDB::set(std::string_view key, std::string_view val) {
return impl->db
->Put(impl->writeOptions, leveldb::Slice(key.data(), key.size()), leveldb::Slice(val.data(), val.size()))
.ok();
}

bool KeyValueDB::has(std::string_view key) const {
std::unique_ptr<leveldb::Iterator> it(impl->db->NewIterator(impl->readOptions));
auto slice = leveldb::Slice(key.data(), key.size());
Expand All @@ -89,14 +92,17 @@ bool KeyValueDB::has(std::string_view key) const {
}
return false;
}

bool KeyValueDB::empty() const {
std::unique_ptr<leveldb::Iterator> it(impl->db->NewIterator(impl->readOptions));
it->SeekToFirst();
return it->Valid();
}

bool KeyValueDB::del(std::string_view key) {
return impl->db->Delete(impl->writeOptions, leveldb::Slice(key.data(), key.size())).ok();
}

void KeyValueDB::iter(std::function<bool(std::string_view, std::string_view)> const& fn) const {
std::unique_ptr<leveldb::Iterator> it(impl->db->NewIterator(impl->readOptions));
for (it->SeekToFirst(); it->Valid(); it->Next()) {
Expand All @@ -107,6 +113,7 @@ void KeyValueDB::iter(std::function<bool(std::string_view, std::string_view)> co
}
}
}

coro::Generator<std::pair<std::string_view, std::string_view>> KeyValueDB::iter() const {
std::unique_ptr<leveldb::Iterator> it(impl->db->NewIterator(impl->readOptions));
for (it->SeekToFirst(); it->Valid(); it->Next()) {
Expand Down
2 changes: 1 addition & 1 deletion src/ll/api/data/KeyValueDB.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma once
#pragma once

#include <filesystem>
#include <functional>
Expand Down
8 changes: 4 additions & 4 deletions src/ll/api/memory/MemoryOperators.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ void operator delete[](void* p) noexcept { operator delete(p); }

void operator delete[](void* p, std::nothrow_t const&) noexcept { operator delete[](p); }

void operator delete(void* p, std::size_t) noexcept { operator delete(p); };
void operator delete(void* p, std::size_t) noexcept { operator delete(p); }

void operator delete[](void* p, std::size_t) noexcept { operator delete[](p); };
void operator delete[](void* p, std::size_t) noexcept { operator delete[](p); }

void operator delete(void* p, std::align_val_t) noexcept { ::ll::memory::getDefaultAllocator().alignedRelease(p); }

Expand All @@ -33,9 +33,9 @@ void operator delete[](void* p, std::align_val_t alignment) noexcept { operator
void operator delete[](void* p, std::align_val_t alignment, std::nothrow_t const&) noexcept {
operator delete[](p, alignment);
}
void operator delete(void* p, std::size_t, std::align_val_t alignment) noexcept { operator delete(p, alignment); };
void operator delete(void* p, std::size_t, std::align_val_t alignment) noexcept { operator delete(p, alignment); }

void operator delete[](void* p, std::size_t, std::align_val_t alignment) noexcept { operator delete[](p, alignment); };
void operator delete[](void* p, std::size_t, std::align_val_t alignment) noexcept { operator delete[](p, alignment); }

[[nodiscard]] LL_ALLOCATOR void* operator new(std::size_t size) {
if (void* const block = ::ll::memory::getDefaultAllocator().allocate(size)) {
Expand Down
Loading

0 comments on commit f557e2f

Please sign in to comment.