@@ -60,10 +60,10 @@ impl PositionEncoding {
6060 /// // UTF-16: "Hello " (6) + "🌍" (2 UTF-16 units) = position 8
6161 /// let offset = PositionEncoding::Utf16.line_col_to_offset(
6262 /// &index,
63- /// LineCol(( 0, 8) ),
63+ /// LineCol::new( 0, 8),
6464 /// text
6565 /// );
66- /// assert_eq!(offset, Some(ByteOffset(10))); // "Hello 🌍" is 10 bytes
66+ /// assert_eq!(offset, Some(ByteOffset::new (10))); // "Hello 🌍" is 10 bytes
6767 /// ```
6868 #[ must_use]
6969 pub fn line_col_to_offset (
@@ -78,11 +78,11 @@ impl PositionEncoding {
7878 // Handle line bounds - if line > line_count, return document length
7979 let line_start_utf8 = match index. lines ( ) . get ( line as usize ) {
8080 Some ( start) => * start,
81- None => return Some ( ByteOffset ( u32 :: try_from ( text. len ( ) ) . unwrap_or ( u32 :: MAX ) ) ) ,
81+ None => return Some ( ByteOffset :: from_usize ( text. len ( ) ) ) ,
8282 } ;
8383
8484 if character == 0 {
85- return Some ( ByteOffset ( line_start_utf8) ) ;
85+ return Some ( ByteOffset :: new ( line_start_utf8) ) ;
8686 }
8787
8888 let next_line_start = index
@@ -96,14 +96,14 @@ impl PositionEncoding {
9696 // Fast path optimization for ASCII text, all encodings are equivalent to byte offsets
9797 if line_text. is_ascii ( ) {
9898 let char_offset = character. min ( u32:: try_from ( line_text. len ( ) ) . unwrap_or ( u32:: MAX ) ) ;
99- return Some ( ByteOffset ( line_start_utf8 + char_offset) ) ;
99+ return Some ( ByteOffset :: new ( line_start_utf8 + char_offset) ) ;
100100 }
101101
102102 match self {
103103 PositionEncoding :: Utf8 => {
104104 // UTF-8: character positions are already byte offsets
105105 let char_offset = character. min ( u32:: try_from ( line_text. len ( ) ) . unwrap_or ( u32:: MAX ) ) ;
106- Some ( ByteOffset ( line_start_utf8 + char_offset) )
106+ Some ( ByteOffset :: new ( line_start_utf8 + char_offset) )
107107 }
108108 PositionEncoding :: Utf16 => {
109109 // UTF-16: count UTF-16 code units
@@ -119,7 +119,7 @@ impl PositionEncoding {
119119 }
120120
121121 // If character position exceeds line length, clamp to line end
122- Some ( ByteOffset ( line_start_utf8 + utf8_pos) )
122+ Some ( ByteOffset :: new ( line_start_utf8 + utf8_pos) )
123123 }
124124 PositionEncoding :: Utf32 => {
125125 // UTF-32: count Unicode code points (characters)
@@ -133,7 +133,7 @@ impl PositionEncoding {
133133 }
134134
135135 // If character position exceeds line length, clamp to line end
136- Some ( ByteOffset ( line_start_utf8 + utf8_pos) )
136+ Some ( ByteOffset :: new ( line_start_utf8 + utf8_pos) )
137137 }
138138 }
139139 }
@@ -158,15 +158,15 @@ mod tests {
158158 // "Hello " = 6 UTF-16 units, "🌍" = 2 UTF-16 units
159159 // So position (0, 8) in UTF-16 should be after the emoji
160160 let offset = PositionEncoding :: Utf16
161- . line_col_to_offset ( & index, LineCol ( ( 0 , 8 ) ) , text)
161+ . line_col_to_offset ( & index, LineCol :: new ( 0 , 8 ) , text)
162162 . expect ( "Should get offset" ) ;
163- assert_eq ! ( offset, ByteOffset ( 10 ) ) ; // "Hello 🌍" is 10 bytes
163+ assert_eq ! ( offset, ByteOffset :: new ( 10 ) ) ; // "Hello 🌍" is 10 bytes
164164
165165 // In UTF-8, character 10 would be at the 'r' in 'world'
166166 let offset_utf8 = PositionEncoding :: Utf8
167- . line_col_to_offset ( & index, LineCol ( ( 0 , 10 ) ) , text)
167+ . line_col_to_offset ( & index, LineCol :: new ( 0 , 10 ) , text)
168168 . expect ( "Should get offset" ) ;
169- assert_eq ! ( offset_utf8, ByteOffset ( 10 ) ) ;
169+ assert_eq ! ( offset_utf8, ByteOffset :: new ( 10 ) ) ;
170170 }
171171
172172 #[ test]
@@ -176,17 +176,17 @@ mod tests {
176176
177177 // For ASCII text, all encodings should give the same result
178178 let offset_utf8 = PositionEncoding :: Utf8
179- . line_col_to_offset ( & index, LineCol ( ( 0 , 5 ) ) , text)
179+ . line_col_to_offset ( & index, LineCol :: new ( 0 , 5 ) , text)
180180 . expect ( "Should get offset" ) ;
181181 let offset_utf16 = PositionEncoding :: Utf16
182- . line_col_to_offset ( & index, LineCol ( ( 0 , 5 ) ) , text)
182+ . line_col_to_offset ( & index, LineCol :: new ( 0 , 5 ) , text)
183183 . expect ( "Should get offset" ) ;
184184 let offset_utf32 = PositionEncoding :: Utf32
185- . line_col_to_offset ( & index, LineCol ( ( 0 , 5 ) ) , text)
185+ . line_col_to_offset ( & index, LineCol :: new ( 0 , 5 ) , text)
186186 . expect ( "Should get offset" ) ;
187187
188- assert_eq ! ( offset_utf8, ByteOffset ( 5 ) ) ;
189- assert_eq ! ( offset_utf16, ByteOffset ( 5 ) ) ;
190- assert_eq ! ( offset_utf32, ByteOffset ( 5 ) ) ;
188+ assert_eq ! ( offset_utf8, ByteOffset :: new ( 5 ) ) ;
189+ assert_eq ! ( offset_utf16, ByteOffset :: new ( 5 ) ) ;
190+ assert_eq ! ( offset_utf32, ByteOffset :: new ( 5 ) ) ;
191191 }
192192}
0 commit comments