Execute clang tidy and IWYU (#528)

This commit is contained in:
Arthur Sonzogni
2022-12-19 18:51:25 +01:00
committed by ArthurSonzogni
parent 4dc1a9fff9
commit 0542227ba7
55 changed files with 315 additions and 298 deletions

View File

@@ -103,11 +103,11 @@ Color::Color(uint8_t red, uint8_t green, uint8_t blue)
const int database_begin = 16;
const int database_end = 256;
for (int i = database_begin; i < database_end; ++i) {
ColorInfo color_info = GetColorInfo(Color::Palette256(i));
int dr = color_info.red - red;
int dg = color_info.green - green;
int db = color_info.blue - blue;
int dist = dr * dr + dg * dg + db * db;
const ColorInfo color_info = GetColorInfo(Color::Palette256(i));
const int dr = color_info.red - red;
const int dg = color_info.green - green;
const int db = color_info.blue - blue;
const int dist = dr * dr + dg * dg + db * db;
if (closest > dist) {
closest = dist;
best = i;
@@ -186,7 +186,7 @@ Color Color::Interpolate(float t, const Color& a, const Color& b) {
}
case ColorType::Palette16: {
ColorInfo info = GetColorInfo(Color::Palette16(color.red_));
const ColorInfo info = GetColorInfo(Color::Palette16(color.red_));
*red = info.red;
*green = info.green;
*blue = info.blue;
@@ -194,7 +194,7 @@ Color Color::Interpolate(float t, const Color& a, const Color& b) {
}
case ColorType::Palette256: {
ColorInfo info = GetColorInfo(Color::Palette256(color.red_));
const ColorInfo info = GetColorInfo(Color::Palette256(color.red_));
*red = info.red;
*green = info.green;
*blue = info.blue;

View File

@@ -410,7 +410,7 @@ std::string Screen::ToString() {
std::stringstream ss;
Pixel previous_pixel;
Pixel final_pixel;
const Pixel final_pixel;
for (int y = 0; y < dimy_; ++y) {
if (y != 0) {

View File

@@ -1,5 +1,6 @@
// Content of this file was created thanks to:
// - https://www.unicode.org/Public/UCD/latest/ucd/auxiliary/WordBreakProperty.txt
// -
// https://www.unicode.org/Public/UCD/latest/ucd/auxiliary/WordBreakProperty.txt
// - Markus Kuhn -- 2007-05-26 (Unicode 5.0)
// http://www.cl.cam.ac.uk/~mgk25/ucs/wcwidth.c
// Thanks you!
@@ -7,9 +8,11 @@
#include "ftxui/screen/string.hpp"
#include <array> // for array
#include <cstdint> // for uint32_t, uint8_t
#include <cstdint> // for uint32_t, uint8_t, uint16_t, int32_t
#include <string> // for string, basic_string, wstring
#include <tuple> // for std::ignore
#include <tuple> // for _Swallow_assign, ignore
#include "ftxui/screen/deprecated.hpp" // for wchar_width, wstring_width
namespace {
@@ -1485,7 +1488,7 @@ bool Bisearch(uint32_t ucs, const std::array<Interval, N> table) {
int min = 0;
int max = N - 1;
while (max >= min) {
int mid = (min + max) / 2;
const int mid = (min + max) / 2;
if (ucs > table[mid].last) { // NOLINT
min = mid + 1;
} else if (ucs < table[mid].first) { // NOLINT
@@ -1508,7 +1511,7 @@ bool Bisearch(uint32_t ucs, const std::array<C, N> table, C* out) {
int min = 0;
int max = N - 1;
while (max >= min) {
int mid = (min + max) / 2;
const int mid = (min + max) / 2;
if (ucs > table[mid].last) { // NOLINT
min = mid + 1;
} else if (ucs < table[mid].first) { // NOLINT
@@ -1574,7 +1577,7 @@ bool EatCodePoint(const std::string& input,
*end = start + 1;
return false;
}
uint8_t C0 = input[start];
const uint8_t C0 = input[start];
// 1 byte string.
if ((C0 & 0b1000'0000) == 0b0000'0000) { // NOLINT
@@ -1586,7 +1589,7 @@ bool EatCodePoint(const std::string& input,
// 2 byte string.
if ((C0 & 0b1110'0000) == 0b1100'0000 && // NOLINT
start + 1 < input.size()) {
uint8_t C1 = input[start + 1];
const uint8_t C1 = input[start + 1];
*ucs = 0;
*ucs += C0 & 0b0001'1111; // NOLINT
*ucs <<= 6; // NOLINT
@@ -1598,8 +1601,8 @@ bool EatCodePoint(const std::string& input,
// 3 byte string.
if ((C0 & 0b1111'0000) == 0b1110'0000 && // NOLINT
start + 2 < input.size()) {
uint8_t C1 = input[start + 1];
uint8_t C2 = input[start + 2];
const uint8_t C1 = input[start + 1];
const uint8_t C2 = input[start + 2];
*ucs = 0;
*ucs += C0 & 0b0000'1111; // NOLINT
*ucs <<= 6; // NOLINT
@@ -1613,9 +1616,9 @@ bool EatCodePoint(const std::string& input,
// 4 byte string.
if ((C0 & 0b1111'1000) == 0b1111'0000 && // NOLINT
start + 3 < input.size()) {
uint8_t C1 = input[start + 1];
uint8_t C2 = input[start + 2];
uint8_t C3 = input[start + 3];
const uint8_t C1 = input[start + 1];
const uint8_t C2 = input[start + 2];
const uint8_t C3 = input[start + 3];
*ucs = 0;
*ucs += C0 & 0b0000'0111; // NOLINT
*ucs <<= 6; // NOLINT
@@ -1645,10 +1648,9 @@ bool EatCodePoint(const std::wstring& input,
return false;
}
// On linux wstring uses the UTF32 encoding:
if constexpr (sizeof(wchar_t) == 4) {
*ucs = input[start]; // NOLINT
*ucs = input[start]; // NOLINT
*end = start + 1;
return true;
}
@@ -1686,7 +1688,7 @@ int wstring_width(const std::wstring& text) {
int width = 0;
for (const wchar_t& it : text) {
int w = wchar_width(it);
const int w = wchar_width(it);
if (w < 0) {
return -1;
}
@@ -1724,7 +1726,7 @@ int string_width(const std::string& input) {
std::vector<std::string> Utf8ToGlyphs(const std::string& input) {
std::vector<std::string> out;
std::string current;
const std::string current;
out.reserve(input.size());
size_t start = 0;
size_t end = 0;
@@ -1735,7 +1737,7 @@ std::vector<std::string> Utf8ToGlyphs(const std::string& input) {
continue;
}
std::string append = input.substr(start, end - start);
const std::string append = input.substr(start, end - start);
start = end;
// Ignore control characters.
@@ -1772,7 +1774,7 @@ int GlyphPosition(const std::string& input, size_t glyph_index, size_t start) {
size_t end = 0;
while (start < input.size()) {
uint32_t codepoint = 0;
bool eaten = EatCodePoint(input, start, &end, &codepoint);
const bool eaten = EatCodePoint(input, start, &end, &codepoint);
// Ignore invalid, control characters and combining characters.
if (!eaten || IsControl(codepoint) || IsCombining(codepoint)) {
@@ -1801,7 +1803,7 @@ std::vector<int> CellToGlyphIndex(const std::string& input) {
size_t end = 0;
while (start < input.size()) {
uint32_t codepoint = 0;
bool eaten = EatCodePoint(input, start, &end, &codepoint);
const bool eaten = EatCodePoint(input, start, &end, &codepoint);
start = end;
// Ignore invalid / control characters.
@@ -1840,7 +1842,7 @@ int GlyphCount(const std::string& input) {
size_t end = 0;
while (start < input.size()) {
uint32_t codepoint = 0;
bool eaten = EatCodePoint(input, start, &end, &codepoint);
const bool eaten = EatCodePoint(input, start, &end, &codepoint);
start = end;
// Ignore invalid characters:
@@ -1916,7 +1918,7 @@ std::string to_string(const std::wstring& s) {
// 1 byte UTF8
if (codepoint <= 0b000'0000'0111'1111) { // NOLINT
uint8_t p1 = codepoint;
const uint8_t p1 = codepoint;
out.push_back(p1); // NOLINT
continue;
}

View File

@@ -134,8 +134,8 @@ TEST(StringTest, Utf8ToWordBreakProperty) {
EXPECT_EQ(Utf8ToWordBreakProperty("'"), T({P::Single_Quote}));
EXPECT_EQ(Utf8ToWordBreakProperty(":"), T({P::MidLetter}));
EXPECT_EQ(Utf8ToWordBreakProperty("."), T({P::MidNumLet}));
EXPECT_EQ(Utf8ToWordBreakProperty("\r"), T({})); // FIXME
EXPECT_EQ(Utf8ToWordBreakProperty("\n"), T({})); // FIXME
EXPECT_EQ(Utf8ToWordBreakProperty("\r"), T({})); // FIXME
EXPECT_EQ(Utf8ToWordBreakProperty("\n"), T({})); // FIXME
}
TEST(StringTest, to_string) {