add FileLoader::get_line()
This commit is contained in:
parent
9adcd93fd3
commit
1636ee1728
@ -95,3 +95,14 @@ void FileLoader::load_buf(size_t size)
|
||||
m_lines = lines[LINE_ENDING_LF];
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<Text> FileLoader::get_line(size_t index)
|
||||
{
|
||||
if (index > num_lines())
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const LineIndexPair & line_index_pair = (*m_lines)[index];
|
||||
return std::make_shared<Text>(line_index_pair.first, line_index_pair.second);
|
||||
}
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include <stdint.h>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include "Text.h"
|
||||
|
||||
class FileLoader
|
||||
{
|
||||
@ -19,7 +20,7 @@ public:
|
||||
FileLoader();
|
||||
~FileLoader();
|
||||
bool load(const char * fname);
|
||||
unsigned int num_lines()
|
||||
size_t num_lines()
|
||||
{
|
||||
if (m_lines == NULL)
|
||||
{
|
||||
@ -31,6 +32,7 @@ public:
|
||||
}
|
||||
}
|
||||
int get_line_endings() { return m_line_endings; }
|
||||
std::shared_ptr<Text> get_line(size_t index);
|
||||
protected:
|
||||
typedef std::pair<const uint8_t *, size_t> LineIndexPair;
|
||||
typedef std::vector<LineIndexPair> LineIndexPairVector;
|
||||
|
Loading…
x
Reference in New Issue
Block a user