mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 07:57:46 +00:00
LibCore: Add support for range-based for loops on LineIterators
This commit is contained in:
parent
6d948c1a92
commit
2c43eaa50c
3 changed files with 54 additions and 17 deletions
|
@ -319,4 +319,8 @@ LineIterator& LineIterator::operator++()
|
|||
m_buffer = m_device->read_line();
|
||||
return *this;
|
||||
}
|
||||
|
||||
LineIterator LineRange::begin() { return m_device.line_begin(); }
|
||||
LineIterator LineRange::end() { return m_device.line_end(); }
|
||||
|
||||
}
|
||||
|
|
|
@ -12,6 +12,8 @@
|
|||
|
||||
namespace Core {
|
||||
|
||||
class IODevice;
|
||||
|
||||
// This is not necessarily a valid iterator in all contexts,
|
||||
// if we had concepts, this would be InputIterator, not Copyable, Movable.
|
||||
class LineIterator {
|
||||
|
@ -34,6 +36,20 @@ private:
|
|||
String m_buffer;
|
||||
};
|
||||
|
||||
class LineRange {
|
||||
public:
|
||||
LineRange() = delete;
|
||||
explicit LineRange(IODevice& device)
|
||||
: m_device(device)
|
||||
{
|
||||
}
|
||||
LineIterator begin();
|
||||
LineIterator end();
|
||||
|
||||
private:
|
||||
IODevice& m_device;
|
||||
};
|
||||
|
||||
enum class OpenMode : unsigned {
|
||||
NotOpen = 0,
|
||||
ReadOnly = 1,
|
||||
|
@ -91,6 +107,10 @@ public:
|
|||
|
||||
LineIterator line_begin() & { return LineIterator(*this); }
|
||||
LineIterator line_end() { return LineIterator(*this, true); }
|
||||
LineRange lines()
|
||||
{
|
||||
return LineRange(*this);
|
||||
}
|
||||
|
||||
protected:
|
||||
explicit IODevice(Object* parent = nullptr);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue