summaryrefslogtreecommitdiff
path: root/Editor/Line.h
blob: dc6a19f2ba4261a5ff063c8125c0405e4a983da9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#pragma once

#include "cuki.h"
#include <deque>
#include <string>
#include <tuple>

class Chunk {
public:
    explicit Chunk(const std::string&);
    ~Chunk();

    const std::string& data() const { return m_data; }
    size_t length() const { return m_data.size(); }

private:
    std::string m_data;
};

class Line {
    AK_MAKE_NONCOPYABLE(Line);
public:
    Line() { }
    Line(const std::string&);
    Line(Line&&);
    ~Line();

    std::string data() const;
    size_t length() const { return data().size(); }

    void insert(size_t index, const std::string&);

    std::string truncate(size_t length);

    void coalesce();

private:
    void append(const std::string&);
    void prepend(const std::string&);

    std::tuple<size_t, size_t> chunk_index_for_position(size_t);

    std::deque<Chunk> m_chunks;
};