@@ -678,14 +678,17 @@ pub(crate) fn highlight_line_matches(
678
678
// into the stripped string at the point where it is being checked.
679
679
let mut inserted_escs_len = 0 ;
680
680
for esc in & escapes {
681
- let match_count: usize = matches. iter ( )
681
+ let match_count: usize = matches
682
+ . iter ( )
682
683
. take_while ( |( s, _) | * s <= esc. 0 )
683
- . map ( |( _, e) | if * e <= esc. 0 {
684
- // if the end of the match is at the same point as the escape, the NORMAL should be
685
- // inserted before the escape so that the escape isn't immediately negated
686
- 2
687
- } else {
688
- 1
684
+ . map ( |( _, e) | {
685
+ if * e <= esc. 0 {
686
+ // if the end of the match is at the same point as the escape, the NORMAL should be
687
+ // inserted before the escape so that the escape isn't immediately negated
688
+ 2
689
+ } else {
690
+ 1
691
+ }
689
692
} )
690
693
. sum ( ) ;
691
694
// Find how many invert|normal markers appear before this escape
@@ -728,7 +731,8 @@ pub(crate) fn highlight_line_matches(
728
731
729
732
// then we need to find all of the escapes which would be placed before it in the final
730
733
// string
731
- let escapes: usize = escapes. iter ( )
734
+ let escapes: usize = escapes
735
+ . iter ( )
732
736
// we take them while their start position in the stripped string is before the end
733
737
// position of this match in the final string. We use `<` instead of `<=` b/c we insert
734
738
// the escapes back into the inverted string after the NORMAL
@@ -1150,7 +1154,8 @@ eros.",
1150
1154
#[ test]
1151
1155
fn single_match_no_esc ( ) {
1152
1156
let res =
1153
- highlight_line_matches ( "this is a test" , & Regex :: new ( " a " ) . unwrap ( ) , false ) . unwrap ( ) ;
1157
+ highlight_line_matches ( "this is a test" , & Regex :: new ( " a " ) . unwrap ( ) , false )
1158
+ . unwrap ( ) ;
1154
1159
assert_eq ! ( res, format!( "this is{} a {}test" , * INVERT , * NORMAL ) ) ;
1155
1160
}
1156
1161
@@ -1160,7 +1165,8 @@ eros.",
1160
1165
"test another test" ,
1161
1166
& Regex :: new ( "test" ) . unwrap ( ) ,
1162
1167
false ,
1163
- ) . unwrap ( ) ;
1168
+ )
1169
+ . unwrap ( ) ;
1164
1170
assert_eq ! (
1165
1171
res,
1166
1172
format!( "{i}test{n} another {i}test{n}" , i = * INVERT , n = * NORMAL )
@@ -1175,7 +1181,8 @@ eros.",
1175
1181
& format ! ( "{ESC}color{NONE} and test" ) ,
1176
1182
& Regex :: new ( "test" ) . unwrap ( ) ,
1177
1183
false ,
1178
- ) . unwrap ( ) ;
1184
+ )
1185
+ . unwrap ( ) ;
1179
1186
assert_eq ! (
1180
1187
res,
1181
1188
format!( "{}color{} and {}test{}" , ESC , NONE , * INVERT , * NORMAL )
@@ -1185,7 +1192,8 @@ eros.",
1185
1192
#[ test]
1186
1193
fn esc_pair_end_in_match ( ) {
1187
1194
let orig = format ! ( "this {ESC}is a te{NONE}st" ) ;
1188
- let res = highlight_line_matches ( & orig, & Regex :: new ( "test" ) . unwrap ( ) , false ) . unwrap ( ) ;
1195
+ let res =
1196
+ highlight_line_matches ( & orig, & Regex :: new ( "test" ) . unwrap ( ) , false ) . unwrap ( ) ;
1189
1197
assert_eq ! (
1190
1198
res,
1191
1199
format!( "this {}is a {}test{}{}" , ESC , * INVERT , * NORMAL , NONE )
@@ -1195,7 +1203,8 @@ eros.",
1195
1203
#[ test]
1196
1204
fn esc_pair_start_in_match ( ) {
1197
1205
let orig = format ! ( "this is a te{ESC}st again{NONE}" ) ;
1198
- let res = highlight_line_matches ( & orig, & Regex :: new ( "test" ) . unwrap ( ) , false ) . unwrap ( ) ;
1206
+ let res =
1207
+ highlight_line_matches ( & orig, & Regex :: new ( "test" ) . unwrap ( ) , false ) . unwrap ( ) ;
1199
1208
assert_eq ! (
1200
1209
res,
1201
1210
format!( "this is a {}test{}{ESC} again{}" , * INVERT , * NORMAL , NONE )
@@ -1205,7 +1214,8 @@ eros.",
1205
1214
#[ test]
1206
1215
fn esc_pair_around_match ( ) {
1207
1216
let orig = format ! ( "this is {ESC}a test again{NONE}" ) ;
1208
- let res = highlight_line_matches ( & orig, & Regex :: new ( "test" ) . unwrap ( ) , false ) . unwrap ( ) ;
1217
+ let res =
1218
+ highlight_line_matches ( & orig, & Regex :: new ( "test" ) . unwrap ( ) , false ) . unwrap ( ) ;
1209
1219
assert_eq ! (
1210
1220
res,
1211
1221
format!( "this is {}a {}test{} again{}" , ESC , * INVERT , * NORMAL , NONE )
@@ -1215,7 +1225,8 @@ eros.",
1215
1225
#[ test]
1216
1226
fn esc_pair_within_match ( ) {
1217
1227
let orig = format ! ( "this is a t{ESC}es{NONE}t again" ) ;
1218
- let res = highlight_line_matches ( & orig, & Regex :: new ( "test" ) . unwrap ( ) , false ) . unwrap ( ) ;
1228
+ let res =
1229
+ highlight_line_matches ( & orig, & Regex :: new ( "test" ) . unwrap ( ) , false ) . unwrap ( ) ;
1219
1230
assert_eq ! (
1220
1231
res,
1221
1232
format!( "this is a {}test{}{ESC}{NONE} again" , * INVERT , * NORMAL )
@@ -1225,7 +1236,8 @@ eros.",
1225
1236
#[ test]
1226
1237
fn multi_escape_match ( ) {
1227
1238
let orig = format ! ( "this {ESC}is a te{NONE}st again {ESC}yeah{NONE} test" , ) ;
1228
- let res = highlight_line_matches ( & orig, & Regex :: new ( "test" ) . unwrap ( ) , false ) . unwrap ( ) ;
1239
+ let res =
1240
+ highlight_line_matches ( & orig, & Regex :: new ( "test" ) . unwrap ( ) , false ) . unwrap ( ) ;
1229
1241
assert_eq ! (
1230
1242
res,
1231
1243
format!(
@@ -1246,7 +1258,8 @@ eros.",
1246
1258
"{ESC}test{NONE} this {ESC}is a te{NONE}st again {ESC}yeah{NONE} test" ,
1247
1259
) ;
1248
1260
1249
- let res = highlight_line_matches ( & orig, & Regex :: new ( "test" ) . unwrap ( ) , true ) . unwrap ( ) ;
1261
+ let res =
1262
+ highlight_line_matches ( & orig, & Regex :: new ( "test" ) . unwrap ( ) , true ) . unwrap ( ) ;
1250
1263
assert_eq ! (
1251
1264
res,
1252
1265
format!(
@@ -1266,7 +1279,8 @@ eros.",
1266
1279
& format ! ( "{ESC}color{NONE} and test" ) ,
1267
1280
& Regex :: new ( "test" ) . unwrap ( ) ,
1268
1281
true ,
1269
- ) . unwrap ( ) ;
1282
+ )
1283
+ . unwrap ( ) ;
1270
1284
assert_eq ! (
1271
1285
res,
1272
1286
format!( "{}color{} and {}test{}" , ESC , NONE , * INVERT , * NORMAL )
@@ -1276,7 +1290,8 @@ eros.",
1276
1290
#[ test]
1277
1291
fn esc_pair_end_in_match ( ) {
1278
1292
let orig = format ! ( "this {ESC}is a te{NONE}st" ) ;
1279
- let res = highlight_line_matches ( & orig, & Regex :: new ( "test" ) . unwrap ( ) , true ) . unwrap ( ) ;
1293
+ let res =
1294
+ highlight_line_matches ( & orig, & Regex :: new ( "test" ) . unwrap ( ) , true ) . unwrap ( ) ;
1280
1295
assert_eq ! (
1281
1296
res,
1282
1297
format!( "this {ESC}is a {}te{NONE}st{}" , * INVERT , * NORMAL )
@@ -1286,7 +1301,8 @@ eros.",
1286
1301
#[ test]
1287
1302
fn esc_pair_start_in_match ( ) {
1288
1303
let orig = format ! ( "this is a te{ESC}st again{NONE}" ) ;
1289
- let res = highlight_line_matches ( & orig, & Regex :: new ( "test" ) . unwrap ( ) , true ) . unwrap ( ) ;
1304
+ let res =
1305
+ highlight_line_matches ( & orig, & Regex :: new ( "test" ) . unwrap ( ) , true ) . unwrap ( ) ;
1290
1306
assert_eq ! (
1291
1307
res,
1292
1308
format!( "this is a {}te{ESC}st{} again{NONE}" , * INVERT , * NORMAL )
@@ -1296,7 +1312,8 @@ eros.",
1296
1312
#[ test]
1297
1313
fn esc_pair_around_match ( ) {
1298
1314
let orig = format ! ( "this is {ESC}a test again{NONE}" ) ;
1299
- let res = highlight_line_matches ( & orig, & Regex :: new ( "test" ) . unwrap ( ) , true ) . unwrap ( ) ;
1315
+ let res =
1316
+ highlight_line_matches ( & orig, & Regex :: new ( "test" ) . unwrap ( ) , true ) . unwrap ( ) ;
1300
1317
assert_eq ! (
1301
1318
res,
1302
1319
format!( "this is {ESC}a {}test{} again{NONE}" , * INVERT , * NORMAL )
@@ -1306,7 +1323,8 @@ eros.",
1306
1323
#[ test]
1307
1324
fn esc_pair_within_match ( ) {
1308
1325
let orig = format ! ( "this is a t{ESC}es{NONE}t again" ) ;
1309
- let res = highlight_line_matches ( & orig, & Regex :: new ( "test" ) . unwrap ( ) , true ) . unwrap ( ) ;
1326
+ let res =
1327
+ highlight_line_matches ( & orig, & Regex :: new ( "test" ) . unwrap ( ) , true ) . unwrap ( ) ;
1310
1328
assert_eq ! (
1311
1329
res,
1312
1330
format!( "this is a {}t{ESC}es{NONE}t{} again" , * INVERT , * NORMAL )
@@ -1316,7 +1334,8 @@ eros.",
1316
1334
#[ test]
1317
1335
fn multi_escape_match ( ) {
1318
1336
let orig = format ! ( "this {ESC}is a te{NONE}st again {ESC}yeah{NONE} test" , ) ;
1319
- let res = highlight_line_matches ( & orig, & Regex :: new ( "test" ) . unwrap ( ) , true ) . unwrap ( ) ;
1337
+ let res =
1338
+ highlight_line_matches ( & orig, & Regex :: new ( "test" ) . unwrap ( ) , true ) . unwrap ( ) ;
1320
1339
assert_eq ! (
1321
1340
res,
1322
1341
format!(
0 commit comments