summaryrefslogtreecommitdiff
path: root/Userland/Applications/Spreadsheet
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-09-07 12:56:50 +0200
committerAndreas Kling <kling@serenityos.org>2021-09-07 13:53:14 +0200
commit6ad427993a64c846c93ecc1fd3bf3f6d6be9cd3d (patch)
treebf364b00ad62291a34426cc8a820a18b7b8c1aaa /Userland/Applications/Spreadsheet
parent55b0b06897b7160b5fbc18ff9186a2242bbdf318 (diff)
downloadserenity-6ad427993a64c846c93ecc1fd3bf3f6d6be9cd3d.zip
Everywhere: Behaviour => Behavior
Diffstat (limited to 'Userland/Applications/Spreadsheet')
-rw-r--r--Userland/Applications/Spreadsheet/ExportDialog.cpp8
-rw-r--r--Userland/Applications/Spreadsheet/ImportDialog.cpp10
-rw-r--r--Userland/Applications/Spreadsheet/Readers/CSV.h4
-rw-r--r--Userland/Applications/Spreadsheet/Readers/Test/TestXSV.cpp12
-rw-r--r--Userland/Applications/Spreadsheet/Readers/XSV.cpp24
-rw-r--r--Userland/Applications/Spreadsheet/Readers/XSV.h18
-rw-r--r--Userland/Applications/Spreadsheet/Writers/CSV.h4
-rw-r--r--Userland/Applications/Spreadsheet/Writers/Test/TestXSVWriter.cpp4
-rw-r--r--Userland/Applications/Spreadsheet/Writers/XSV.h28
9 files changed, 56 insertions, 56 deletions
diff --git a/Userland/Applications/Spreadsheet/ExportDialog.cpp b/Userland/Applications/Spreadsheet/ExportDialog.cpp
index 0a80f4a627..52321f7e1c 100644
--- a/Userland/Applications/Spreadsheet/ExportDialog.cpp
+++ b/Userland/Applications/Spreadsheet/ExportDialog.cpp
@@ -154,17 +154,17 @@ auto CSVExportDialogPage::make_writer() -> Optional<XSV>
quote_escape,
};
- auto behaviours = Writer::default_behaviours();
+ auto behaviors = Writer::default_behaviors();
Vector<String> empty_headers;
auto* headers = &empty_headers;
if (should_export_headers) {
- behaviours = behaviours | Writer::WriterBehaviour::WriteHeaders;
+ behaviors = behaviors | Writer::WriterBehavior::WriteHeaders;
headers = &m_headers;
}
if (should_quote_all_fields)
- behaviours = behaviours | Writer::WriterBehaviour::QuoteAll;
+ behaviors = behaviors | Writer::WriterBehavior::QuoteAll;
// Note that the stream is used only by the ctor.
auto stream = Core::OutputFileStream::open(m_temp_output_file_path);
@@ -172,7 +172,7 @@ auto CSVExportDialogPage::make_writer() -> Optional<XSV>
dbgln("Cannot open {} for writing: {}", m_temp_output_file_path, stream.error());
return {};
}
- XSV writer(stream.value(), m_data, traits, *headers, behaviours);
+ XSV writer(stream.value(), m_data, traits, *headers, behaviors);
if (stream.value().has_any_error()) {
dbgln("Write error when making preview");
diff --git a/Userland/Applications/Spreadsheet/ImportDialog.cpp b/Userland/Applications/Spreadsheet/ImportDialog.cpp
index 5e9962dd18..3c19bbaf27 100644
--- a/Userland/Applications/Spreadsheet/ImportDialog.cpp
+++ b/Userland/Applications/Spreadsheet/ImportDialog.cpp
@@ -135,16 +135,16 @@ auto CSVImportDialogPage::make_reader() -> Optional<Reader::XSV>
quote_escape,
};
- auto behaviours = Reader::default_behaviours() | Reader::ParserBehaviour::Lenient;
+ auto behaviors = Reader::default_behaviors() | Reader::ParserBehavior::Lenient;
if (should_read_headers)
- behaviours = behaviours | Reader::ParserBehaviour::ReadHeaders;
+ behaviors = behaviors | Reader::ParserBehavior::ReadHeaders;
if (should_trim_leading)
- behaviours = behaviours | Reader::ParserBehaviour::TrimLeadingFieldSpaces;
+ behaviors = behaviors | Reader::ParserBehavior::TrimLeadingFieldSpaces;
if (should_trim_trailing)
- behaviours = behaviours | Reader::ParserBehaviour::TrimTrailingFieldSpaces;
+ behaviors = behaviors | Reader::ParserBehavior::TrimTrailingFieldSpaces;
- return Reader::XSV(m_csv, move(traits), behaviours);
+ return Reader::XSV(m_csv, move(traits), behaviors);
};
void CSVImportDialogPage::update_preview()
diff --git a/Userland/Applications/Spreadsheet/Readers/CSV.h b/Userland/Applications/Spreadsheet/Readers/CSV.h
index ae41405452..72283a72e0 100644
--- a/Userland/Applications/Spreadsheet/Readers/CSV.h
+++ b/Userland/Applications/Spreadsheet/Readers/CSV.h
@@ -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)
{
}
};
diff --git a/Userland/Applications/Spreadsheet/Readers/Test/TestXSV.cpp b/Userland/Applications/Spreadsheet/Readers/Test/TestXSV.cpp
index 0b2d901015..5dbe2a5966 100644
--- a/Userland/Applications/Spreadsheet/Readers/Test/TestXSV.cpp
+++ b/Userland/Applications/Spreadsheet/Readers/Test/TestXSV.cpp
@@ -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());
diff --git a/Userland/Applications/Spreadsheet/Readers/XSV.cpp b/Userland/Applications/Spreadsheet/Readers/XSV.cpp
index 9e3b737fd7..9039ee0f99 100644
--- a/Userland/Applications/Spreadsheet/Readers/XSV.cpp
+++ b/Userland/Applications/Spreadsheet/Readers/XSV.cpp
@@ -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()))
diff --git a/Userland/Applications/Spreadsheet/Readers/XSV.h b/Userland/Applications/Spreadsheet/Readers/XSV.h
index adc2e67805..25baaaa3d0 100644
--- a/Userland/Applications/Spreadsheet/Readers/XSV.h
+++ b/Userland/Applications/Spreadsheet/Readers/XSV.h
@@ -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 };
diff --git a/Userland/Applications/Spreadsheet/Writers/CSV.h b/Userland/Applications/Spreadsheet/Writers/CSV.h
index 1b7c7ba511..d7650e760a 100644
--- a/Userland/Applications/Spreadsheet/Writers/CSV.h
+++ b/Userland/Applications/Spreadsheet/Writers/CSV.h
@@ -15,8 +15,8 @@ namespace Writer {
template<typename ContainerType>
class CSV : public XSV<ContainerType> {
public:
- CSV(OutputStream& output, const ContainerType& data, const Vector<StringView>& headers = {}, WriterBehaviour behaviours = default_behaviours())
- : XSV<ContainerType>(output, data, { ",", "\"", WriterTraits::Repeat }, headers, behaviours)
+ CSV(OutputStream& output, const ContainerType& data, const Vector<StringView>& headers = {}, WriterBehavior behaviors = default_behaviors())
+ : XSV<ContainerType>(output, data, { ",", "\"", WriterTraits::Repeat }, headers, behaviors)
{
}
};
diff --git a/Userland/Applications/Spreadsheet/Writers/Test/TestXSVWriter.cpp b/Userland/Applications/Spreadsheet/Writers/Test/TestXSVWriter.cpp
index 542c544ea8..fd294d3a0c 100644
--- a/Userland/Applications/Spreadsheet/Writers/Test/TestXSVWriter.cpp
+++ b/Userland/Applications/Spreadsheet/Writers/Test/TestXSVWriter.cpp
@@ -53,7 +53,7 @@ TEST_CASE(can_write_with_header)
EXPECT_EQ(StringView { stream.bytes() }, expected_output);
}
-TEST_CASE(can_write_with_different_behaviours)
+TEST_CASE(can_write_with_different_behaviors)
{
Vector<Vector<String>> data = {
{ "Well", "Hello\"", "Friends" },
@@ -63,7 +63,7 @@ TEST_CASE(can_write_with_different_behaviours)
auto buffer = ByteBuffer::create_uninitialized(1024).release_value();
OutputMemoryStream stream { buffer };
- Writer::CSV csv(stream, data, { "A", "B\"", "C" }, Writer::WriterBehaviour::QuoteOnlyInFieldStart | Writer::WriterBehaviour::WriteHeaders);
+ Writer::CSV csv(stream, data, { "A", "B\"", "C" }, Writer::WriterBehavior::QuoteOnlyInFieldStart | Writer::WriterBehavior::WriteHeaders);
auto expected_output = R"~(A,B",C
Well,Hello",Friends
diff --git a/Userland/Applications/Spreadsheet/Writers/XSV.h b/Userland/Applications/Spreadsheet/Writers/XSV.h
index b72e35525b..08ce3a0b5c 100644
--- a/Userland/Applications/Spreadsheet/Writers/XSV.h
+++ b/Userland/Applications/Spreadsheet/Writers/XSV.h
@@ -16,7 +16,7 @@
namespace Writer {
-enum class WriterBehaviour : u32 {
+enum class WriterBehavior : u32 {
None = 0,
WriteHeaders = 1,
AllowNewlinesInFields = WriteHeaders << 1,
@@ -24,14 +24,14 @@ enum class WriterBehaviour : u32 {
QuoteAll = WriteHeaders << 3,
};
-inline WriterBehaviour operator&(WriterBehaviour left, WriterBehaviour right)
+inline WriterBehavior operator&(WriterBehavior left, WriterBehavior right)
{
- return static_cast<WriterBehaviour>(static_cast<u32>(left) & static_cast<u32>(right));
+ return static_cast<WriterBehavior>(static_cast<u32>(left) & static_cast<u32>(right));
}
-inline WriterBehaviour operator|(WriterBehaviour left, WriterBehaviour right)
+inline WriterBehavior operator|(WriterBehavior left, WriterBehavior right)
{
- return static_cast<WriterBehaviour>(static_cast<u32>(left) | static_cast<u32>(right));
+ return static_cast<WriterBehavior>(static_cast<u32>(left) | static_cast<u32>(right));
}
struct WriterTraits {
@@ -54,23 +54,23 @@ enum class WriteError {
#undef E
};
-constexpr WriterBehaviour default_behaviours()
+constexpr WriterBehavior default_behaviors()
{
- return WriterBehaviour::None;
+ return WriterBehavior::None;
}
template<typename ContainerType, typename HeaderType = Vector<StringView>>
class XSV {
public:
- XSV(OutputStream& output, const ContainerType& data, const WriterTraits& traits, const HeaderType& headers = {}, WriterBehaviour behaviours = default_behaviours())
+ XSV(OutputStream& output, const ContainerType& data, const WriterTraits& traits, const HeaderType& headers = {}, WriterBehavior behaviors = default_behaviors())
: m_data(data)
, m_traits(traits)
- , m_behaviours(behaviours)
+ , m_behaviors(behaviors)
, m_names(headers)
, m_output(output)
{
if (!headers.is_empty())
- m_behaviours = m_behaviours | WriterBehaviour::WriteHeaders;
+ m_behaviors = m_behaviors | WriterBehavior::WriteHeaders;
generate();
}
@@ -101,7 +101,7 @@ private:
void generate()
{
- auto with_headers = (m_behaviours & WriterBehaviour::WriteHeaders) != WriterBehaviour::None;
+ auto with_headers = (m_behaviors & WriterBehavior::WriteHeaders) != WriterBehavior::None;
if (with_headers) {
write_row(m_names);
if (m_output.write({ "\n", 1 }) != 1)
@@ -139,12 +139,12 @@ private:
{
auto string = String::formatted("{}", FormatIfSupported(entry));
- auto safe_to_write_normally = (m_behaviours & WriterBehaviour::QuoteAll) == WriterBehaviour::None
+ auto safe_to_write_normally = (m_behaviors & WriterBehavior::QuoteAll) == WriterBehavior::None
&& !string.contains("\n")
&& !string.contains(m_traits.separator);
if (safe_to_write_normally) {
- if ((m_behaviours & WriterBehaviour::QuoteOnlyInFieldStart) == WriterBehaviour::None)
+ if ((m_behaviors & WriterBehavior::QuoteOnlyInFieldStart) == WriterBehavior::None)
safe_to_write_normally = !string.contains(m_traits.quote);
else
safe_to_write_normally = !string.starts_with(m_traits.quote);
@@ -190,7 +190,7 @@ private:
const ContainerType& m_data;
const WriterTraits& m_traits;
- WriterBehaviour m_behaviours;
+ WriterBehavior m_behaviors;
const HeaderType& m_names;
WriteError m_error { WriteError::None };
OutputStream& m_output;