Skip to content

Commit

Permalink
add SegmentReg active_text(string) (#329)
Browse files Browse the repository at this point in the history
便於取得 substr   ,  減少  lua  string.sub  定位問題 
string.sub( inp,  seg._start+1 , seg._end )
```lua
function tran.func(inp, seg, env)
    local active_inp = seg:active_text(inp)
     ....
 end
```
  • Loading branch information
shewer authored May 2, 2024
1 parent 7c1b939 commit c85440f
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/types.cc
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ namespace SegmentReg {
t.status = T::kConfirmed;
}

string active_text(T &t, const string &r) {
return r.substr(t.start, t.end - t.start);
}

static const luaL_Reg funcs[] = {
{ "Segment", WRAP(make) },
{ NULL, NULL },
Expand All @@ -116,6 +120,7 @@ namespace SegmentReg {
{ "has_tag", WRAPMEM(T::HasTag) },
{ "get_candidate_at", WRAPMEM(T::GetCandidateAt) },
{ "get_selected_candidate", WRAPMEM(T::GetSelectedCandidate) },
{ "active_text", WRAP(active_text) },
{ NULL, NULL },
};

Expand Down

0 comments on commit c85440f

Please sign in to comment.