11--[[
22
3+ 与显示无关的抽象位置对象。
4+ cu
5+ - UTF-8 8-bit byte
6+ - UTF-16 16-bit
7+ - UTF-32 32-bit
8+
39]]
410
511local Format = require (' fittencode.base.format' )
612
713--- @class FittenCode.Position
8- --- @field line number A zero-based row value.
9- --- @field cu number A zero-based column value.
14+ --- @field line number A zero-based line value.
15+ --- @field cu number A zero-based codeunit value.
16+ --- @field encoding ? FittenCode.Encoding
1017local Position = {}
1118Position .__index = Position
1219
@@ -22,7 +29,8 @@ function Position.new(options)
2229end
2330
2431function Position :__tostring ()
25- return Format .nothrow_format (' Position<{}:{}>' , self .line , self .cu )
32+ return Format .nothrow_format (' ({},{})' , self .line , self .cu )
33+ -- return Format.nothrow_format('Position[line:{} cu:{}]', self.line, self.cu)
2634end
2735
2836-- Check if this position is equal to `other`.
@@ -86,9 +94,9 @@ function Position:compare_to(other)
8694end
8795
8896-- Create a new position relative to this position.
89- --- @param line_delta ? number The number of rows to move.
90- --- @param cu_delta ? number The number of columns to move.
91- --- @return FittenCode.Position The new position.
97+ --- @param line_delta ? number The number of lines to move.
98+ --- @param cu_delta ? number The number of codeunits to move.
99+ --- @return FittenCode.Position
92100function Position :translate (line_delta , cu_delta )
93101 return Position .new ({
94102 line = self .line + (line_delta or 0 ),
@@ -97,9 +105,9 @@ function Position:translate(line_delta, cu_delta)
97105end
98106
99107-- Create a new position derived from this position.
100- --- @param line ? number The new row value.
101- --- @param cu ? number The new column value.
102- --- @return FittenCode.Position The new position.
108+ --- @param line ? number The new line value.
109+ --- @param cu ? number The new codeunit value.
110+ --- @return FittenCode.Position
103111function Position :with (line , cu )
104112 return Position .new ({
105113 line = line or self .line ,
@@ -108,7 +116,7 @@ function Position:with(line, cu)
108116end
109117
110118-- Create a copy of this position.
111- --- @return FittenCode.Position The new position.
119+ --- @return FittenCode.Position
112120function Position :clone ()
113121 return Position .new ({
114122 line = self .line ,
@@ -130,6 +138,9 @@ function Position:rel_lastline()
130138 return self .line == - 1
131139end
132140
141+ --- @param line number The new line value.
142+ --- @param cu number The new codeunit value.
143+ --- @return FittenCode.Position
133144function Position .of (line , cu )
134145 return Position .new ({
135146 line = line ,
0 commit comments