diff --git a/src/core/TextLoader.cc b/src/core/TextLoader.cc index 71052b4..5d52f56 100644 --- a/src/core/TextLoader.cc +++ b/src/core/TextLoader.cc @@ -6,6 +6,7 @@ TextLoader::TextLoader() { m_line_endings = LINE_ENDING_LF; m_lines = NULL; + m_eol_at_eof = true; } /** diff --git a/src/core/TextLoader.h b/src/core/TextLoader.h index d6a33c5..7da57b3 100644 --- a/src/core/TextLoader.h +++ b/src/core/TextLoader.h @@ -32,6 +32,7 @@ public: int get_line_endings() { return m_line_endings; } auto begin() { return m_lines->begin(); } auto end() { return m_lines->end(); } + bool get_eol_at_eof() { return m_eol_at_eof; } typedef std::pair LineIndexPair; typedef std::list LineIndexPairList; @@ -39,6 +40,7 @@ public: protected: int m_line_endings; + bool m_eol_at_eof; LineIndexPairListRef m_lines; }; diff --git a/test/src/test_TextLoader.cc b/test/src/test_TextLoader.cc index 092f82c..a28e8b8 100644 --- a/test/src/test_TextLoader.cc +++ b/test/src/test_TextLoader.cc @@ -23,6 +23,7 @@ TEST(TextLoaderTest, loading_empty_file) auto file = TestSupport::read_file("test/files/empty.txt"); tl.load_buffer(&(*file)[0], file->size()); EXPECT_EQ(0u, tl.num_lines()); + EXPECT_EQ(true, tl.get_eol_at_eof()); } TEST(TextLoaderTest, detects_lf_line_endings) @@ -36,6 +37,7 @@ TEST(TextLoaderTest, detects_lf_line_endings) EXPECT_EQ("Hello.", line_to_string(it)); it++; EXPECT_EQ("This file is in LF line ending format.", line_to_string(it)); + EXPECT_EQ(true, tl.get_eol_at_eof()); } TEST(TextLoaderTest, detects_cr_line_endings) @@ -49,6 +51,7 @@ TEST(TextLoaderTest, detects_cr_line_endings) EXPECT_EQ("Hello.", line_to_string(it)); it++; EXPECT_EQ("This file is in CR line ending format.", line_to_string(it)); + EXPECT_EQ(true, tl.get_eol_at_eof()); } TEST(TextLoaderTest, detects_crlf_line_endings) @@ -62,4 +65,5 @@ TEST(TextLoaderTest, detects_crlf_line_endings) EXPECT_EQ("Hello.", line_to_string(it)); it++; EXPECT_EQ("This file is in CRLF line ending format.", line_to_string(it)); + EXPECT_EQ(true, tl.get_eol_at_eof()); }