summaryrefslogtreecommitdiffstats
path: root/yql/essentials/sql/v1/ide/pure_ast/cursor_text.cpp
blob: 4c869ab749f660cb195c673c3a9f884f51208272 (plain) (blame)
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
#include "cursor_text.h"

#include <util/generic/yexception.h>

namespace NSQLPureAST {

TCursorText TCursorText::FromSharped(TString& text Y_LIFETIME_BOUND) {
    constexpr char delim = '#';

    size_t pos = text.find_first_of(delim);
    if (pos == TString::npos) {
        return {
            .Text = text,
        };
    }

    Y_ENSURE(!TStringBuf(text).Tail(pos + 1).Contains(delim));
    text.erase(std::begin(text) + pos);
    return {
        .Text = text,
        .CursorPosition = pos,
    };
}

} // namespace NSQLPureAST