1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 06:37:35 +00:00

Everywhere: Behaviour => Behavior

This commit is contained in:
Andreas Kling 2021-09-07 12:56:50 +02:00
parent 55b0b06897
commit 6ad427993a
48 changed files with 120 additions and 120 deletions

View file

@ -14,8 +14,8 @@ namespace Reader {
class CSV : public XSV {
public:
CSV(StringView source, ParserBehaviour behaviours = default_behaviours())
: XSV(source, { ",", "\"", ParserTraits::Repeat }, behaviours)
CSV(StringView source, ParserBehavior behaviors = default_behaviors())
: XSV(source, { ",", "\"", ParserTraits::Repeat }, behaviors)
{
}
};

View file

@ -18,7 +18,7 @@ TEST_CASE(should_parse_valid_data)
1, 2, 3
4, 5, 6
"""x", y"z, 9)~~~";
auto csv = Reader::CSV { data, Reader::default_behaviours() | Reader::ParserBehaviour::ReadHeaders | Reader::ParserBehaviour::TrimLeadingFieldSpaces };
auto csv = Reader::CSV { data, Reader::default_behaviors() | Reader::ParserBehavior::ReadHeaders | Reader::ParserBehavior::TrimLeadingFieldSpaces };
csv.parse();
EXPECT(!csv.has_error());
@ -32,7 +32,7 @@ TEST_CASE(should_parse_valid_data)
1 , 2, 3
4, "5 " , 6
"""x", y"z, 9 )~~~";
auto csv = Reader::CSV { data, Reader::default_behaviours() | Reader::ParserBehaviour::ReadHeaders | Reader::ParserBehaviour::TrimLeadingFieldSpaces | Reader::ParserBehaviour::TrimTrailingFieldSpaces };
auto csv = Reader::CSV { data, Reader::default_behaviors() | Reader::ParserBehavior::ReadHeaders | Reader::ParserBehavior::TrimLeadingFieldSpaces | Reader::ParserBehavior::TrimTrailingFieldSpaces };
csv.parse();
EXPECT(!csv.has_error());
@ -48,7 +48,7 @@ TEST_CASE(should_fail_nicely)
{
auto data = R"~~~(Foo, Bar, Baz
x, y)~~~";
auto csv = Reader::CSV { data, Reader::default_behaviours() | Reader::ParserBehaviour::ReadHeaders | Reader::ParserBehaviour::TrimLeadingFieldSpaces };
auto csv = Reader::CSV { data, Reader::default_behaviors() | Reader::ParserBehavior::ReadHeaders | Reader::ParserBehavior::TrimLeadingFieldSpaces };
csv.parse();
EXPECT(csv.has_error());
EXPECT_EQ(csv.error(), Reader::ReadError::NonConformingColumnCount);
@ -57,7 +57,7 @@ TEST_CASE(should_fail_nicely)
{
auto data = R"~~~(Foo, Bar, Baz
x, y, "z)~~~";
auto csv = Reader::CSV { data, Reader::default_behaviours() | Reader::ParserBehaviour::ReadHeaders | Reader::ParserBehaviour::TrimLeadingFieldSpaces };
auto csv = Reader::CSV { data, Reader::default_behaviors() | Reader::ParserBehavior::ReadHeaders | Reader::ParserBehavior::TrimLeadingFieldSpaces };
csv.parse();
EXPECT(csv.has_error());
EXPECT_EQ(csv.error(), Reader::ReadError::QuoteFailure);
@ -70,7 +70,7 @@ TEST_CASE(should_iterate_rows)
1, 2, 3
4, 5, 6
"""x", y"z, 9)~~~";
auto csv = Reader::CSV { data, Reader::default_behaviours() | Reader::ParserBehaviour::ReadHeaders | Reader::ParserBehaviour::TrimLeadingFieldSpaces };
auto csv = Reader::CSV { data, Reader::default_behaviors() | Reader::ParserBehavior::ReadHeaders | Reader::ParserBehavior::TrimLeadingFieldSpaces };
csv.parse();
EXPECT(!csv.has_error());
@ -92,7 +92,7 @@ BENCHMARK_CASE(fairly_big_data)
memcpy(buf.offset_pointer(row * line.length()), line.characters_without_null_termination(), line.length());
}
auto csv = Reader::CSV { (char const*)buf.data(), Reader::default_behaviours() | Reader::ParserBehaviour::ReadHeaders };
auto csv = Reader::CSV { (char const*)buf.data(), Reader::default_behaviors() | Reader::ParserBehavior::ReadHeaders };
csv.parse();
EXPECT(!csv.has_error());

View file

@ -9,14 +9,14 @@
namespace Reader {
ParserBehaviour operator&(ParserBehaviour left, ParserBehaviour right)
ParserBehavior operator&(ParserBehavior left, ParserBehavior right)
{
return static_cast<ParserBehaviour>(to_underlying(left) & to_underlying(right));
return static_cast<ParserBehavior>(to_underlying(left) & to_underlying(right));
}
ParserBehaviour operator|(ParserBehaviour left, ParserBehaviour right)
ParserBehavior operator|(ParserBehavior left, ParserBehavior right)
{
return static_cast<ParserBehaviour>(to_underlying(left) | to_underlying(right));
return static_cast<ParserBehavior>(to_underlying(left) | to_underlying(right));
}
void XSV::set_error(ReadError error)
@ -46,7 +46,7 @@ Vector<String> XSV::headers() const
void XSV::parse_preview()
{
reset();
if ((m_behaviours & ParserBehaviour::ReadHeaders) != ParserBehaviour::None)
if ((m_behaviors & ParserBehavior::ReadHeaders) != ParserBehavior::None)
read_headers();
while (!has_error() && !m_lexer.is_eof()) {
@ -59,7 +59,7 @@ void XSV::parse_preview()
void XSV::parse()
{
reset();
if ((m_behaviours & ParserBehaviour::ReadHeaders) != ParserBehaviour::None)
if ((m_behaviors & ParserBehavior::ReadHeaders) != ParserBehavior::None)
read_headers();
while (!has_error() && !m_lexer.is_eof())
@ -103,7 +103,7 @@ Vector<XSV::Field> XSV::read_row(bool header_row)
}
}
auto is_lenient = (m_behaviours & ParserBehaviour::Lenient) != ParserBehaviour::None;
auto is_lenient = (m_behaviors & ParserBehavior::Lenient) != ParserBehavior::None;
if (is_lenient) {
if (m_rows.is_empty())
return row;
@ -120,7 +120,7 @@ Vector<XSV::Field> XSV::read_row(bool header_row)
row.resize(new_size);
}
} else {
auto should_read_headers = (m_behaviours & ParserBehaviour::ReadHeaders) != ParserBehaviour::None;
auto should_read_headers = (m_behaviors & ParserBehavior::ReadHeaders) != ParserBehavior::None;
if (!header_row && should_read_headers && row.size() != m_names.size())
set_error(ReadError::NonConformingColumnCount);
else if (!header_row && !has_explicit_headers() && !m_rows.is_empty() && m_rows.first().size() != row.size())
@ -132,7 +132,7 @@ Vector<XSV::Field> XSV::read_row(bool header_row)
XSV::Field XSV::read_one_field()
{
if ((m_behaviours & ParserBehaviour::TrimLeadingFieldSpaces) != ParserBehaviour::None)
if ((m_behaviors & ParserBehavior::TrimLeadingFieldSpaces) != ParserBehavior::None)
m_lexer.consume_while(is_any_of(" \t\v"));
bool is_quoted = false;
@ -144,7 +144,7 @@ XSV::Field XSV::read_one_field()
field = read_one_unquoted_field();
}
if ((m_behaviours & ParserBehaviour::TrimTrailingFieldSpaces) != ParserBehaviour::None) {
if ((m_behaviors & ParserBehavior::TrimTrailingFieldSpaces) != ParserBehavior::None) {
m_lexer.consume_while(is_any_of(" \t\v"));
if (!is_quoted) {
@ -182,7 +182,7 @@ XSV::Field XSV::read_one_quoted_field()
size_t start = m_lexer.tell(), end = start;
bool is_copy = false;
StringBuilder builder;
auto allow_newlines = (m_behaviours & ParserBehaviour::AllowNewlinesInFields) != ParserBehaviour::None;
auto allow_newlines = (m_behaviors & ParserBehavior::AllowNewlinesInFields) != ParserBehavior::None;
for (; !m_lexer.is_eof();) {
char ch;
@ -248,7 +248,7 @@ XSV::Field XSV::read_one_quoted_field()
XSV::Field XSV::read_one_unquoted_field()
{
size_t start = m_lexer.tell(), end = start;
bool allow_quote_in_field = (m_behaviours & ParserBehaviour::QuoteOnlyInFieldStart) != ParserBehaviour::None;
bool allow_quote_in_field = (m_behaviors & ParserBehavior::QuoteOnlyInFieldStart) != ParserBehavior::None;
for (; !m_lexer.is_eof();) {
if (m_lexer.next_is(m_traits.separator.view()))

View file

@ -14,7 +14,7 @@
namespace Reader {
enum class ParserBehaviour : u32 {
enum class ParserBehavior : u32 {
None = 0,
ReadHeaders = 1,
AllowNewlinesInFields = ReadHeaders << 1,
@ -27,8 +27,8 @@ enum class ParserBehaviour : u32 {
// - updates previous rows with extra columns
};
ParserBehaviour operator&(ParserBehaviour left, ParserBehaviour right);
ParserBehaviour operator|(ParserBehaviour left, ParserBehaviour right);
ParserBehavior operator&(ParserBehavior left, ParserBehavior right);
ParserBehavior operator|(ParserBehavior left, ParserBehavior right);
struct ParserTraits {
String separator;
@ -52,18 +52,18 @@ enum class ReadError {
#undef E
};
constexpr ParserBehaviour default_behaviours()
constexpr ParserBehavior default_behaviors()
{
return ParserBehaviour::QuoteOnlyInFieldStart;
return ParserBehavior::QuoteOnlyInFieldStart;
}
class XSV {
public:
XSV(StringView source, ParserTraits traits, ParserBehaviour behaviours = default_behaviours())
XSV(StringView source, ParserTraits traits, ParserBehavior behaviors = default_behaviors())
: m_source(source)
, m_lexer(m_source)
, m_traits(traits)
, m_behaviours(behaviours)
, m_behaviors(behaviors)
{
parse_preview();
}
@ -88,7 +88,7 @@ public:
size_t size() const { return m_rows.size(); }
Vector<String> headers() const;
[[nodiscard]] bool has_explicit_headers() const { return (static_cast<u32>(m_behaviours) & static_cast<u32>(ParserBehaviour::ReadHeaders)) != 0; }
[[nodiscard]] bool has_explicit_headers() const { return (static_cast<u32>(m_behaviors) & static_cast<u32>(ParserBehavior::ReadHeaders)) != 0; }
class Row {
public:
@ -207,7 +207,7 @@ private:
StringView m_source;
GenericLexer m_lexer;
ParserTraits m_traits;
ParserBehaviour m_behaviours;
ParserBehavior m_behaviors;
Vector<Field> m_names;
Vector<Vector<Field>> m_rows;
ReadError m_error { ReadError::None };