Iterating over SourceView lines

Hi guys,

I have a sourceview widget and I would like to iterate over the lines rather than get_source_buffer(). Could not find any applicable material so I wanted to ask on your expertise if there is a nice way to do it ?

Current status ;

    RefPtr<Gsv::Buffer> buf = source_view.get_source_buffer () ;
    cout << buf->get_text() << std::endl;
    std::string test = buf->get_text();

I am on GTK3 with gtksourceviewmm 3,

Use the buffer and investigate its functions returning iterators, moving by lines, etc. You should be able to do something like:

for (auto it = buffer->begin(), end = buffer->end(); it != end; it.forward_line()) {
    // it points to the start of line N, so use it
1 Like

Thank you, it’s efficiently working!

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.