@@ -181,6 +181,7 @@ mod decl {
181
181
}
182
182
Ok ( ( * c - 0x20 ) & 0x3f )
183
183
}
184
+
184
185
#[ derive( FromArgs ) ]
185
186
struct A2bQpArgs {
186
187
#[ pyarg( any) ]
@@ -194,7 +195,7 @@ mod decl {
194
195
let header = args. header ;
195
196
s. with_ref ( |buffer| {
196
197
let len = buffer. len ( ) ;
197
- let mut out_data = Vec :: < u8 > :: with_capacity ( len) ;
198
+ let mut out_data = Vec :: with_capacity ( len) ;
198
199
199
200
let mut idx = 0 ;
200
201
@@ -308,56 +309,37 @@ mod decl {
308
309
if ( linelen + 3 ) >= 76 {
309
310
// MAXLINESIZE = 76
310
311
linelen = 0 ;
311
- if crlf {
312
- delta += 3 ;
313
- } else {
314
- delta += 2 ;
315
- }
312
+ delta += if crlf { 3 } else { 2 } ;
316
313
}
317
314
linelen += 3 ;
318
315
delta += 3 ;
319
316
inidx += 1 ;
317
+ } else if istext
318
+ && ( ( buf[ inidx] == 0x0a )
319
+ || ( ( inidx + 1 < buflen)
320
+ && ( buf[ inidx] == 0x0d )
321
+ && ( buf[ inidx + 1 ] == 0x0a ) ) )
322
+ {
323
+ linelen = 0 ;
324
+ if ( inidx != 0 ) && ( ( buf[ inidx - 1 ] == 0x20 ) || ( buf[ inidx - 1 ] == 0x09 ) ) {
325
+ delta += 2 ;
326
+ }
327
+ delta += if crlf { 2 } else { 1 } ;
328
+ inidx += if buf[ inidx] == 0x0d { 2 } else { 1 } ;
320
329
} else {
321
- if istext
322
- && ( ( buf[ inidx] == 0x0a )
323
- || ( ( inidx + 1 < buflen)
324
- && ( buf[ inidx] == 0x0d )
325
- && ( buf[ inidx + 1 ] == 0x0a ) ) )
326
- {
330
+ if ( inidx + 1 != buflen) && ( buf[ inidx + 1 ] != 0x0a ) && ( linelen + 1 ) >= 76 {
331
+ // MAXLINESIZE
327
332
linelen = 0 ;
328
- if ( inidx != 0 ) && ( ( buf[ inidx - 1 ] == 0x20 ) || ( buf[ inidx - 1 ] == 0x09 ) ) {
329
- delta += 2 ;
330
- }
331
- if crlf {
332
- delta += 2 ;
333
- } else {
334
- delta += 2 ;
335
- }
336
- if buf[ inidx] == 0x0d {
337
- inidx += 2 ;
338
- } else {
339
- inidx += 1 ;
340
- }
341
- } else {
342
- if ( inidx + 1 != buflen) && ( buf[ inidx + 1 ] != 0x0a ) && ( linelen + 1 ) >= 76
343
- {
344
- // MAXLINESIZE
345
- linelen = 0 ;
346
- if crlf {
347
- delta += 3 ;
348
- } else {
349
- delta += 2 ;
350
- }
351
- }
352
- linelen += 1 ;
353
- delta += 1 ;
354
- inidx += 1 ;
333
+ delta += if crlf { 3 } else { 2 } ;
355
334
}
335
+ linelen += 1 ;
336
+ delta += 1 ;
337
+ inidx += 1 ;
356
338
}
357
339
odatalen += delta;
358
340
}
359
341
360
- let mut out_data = Vec :: < u8 > :: with_capacity ( odatalen) ;
342
+ let mut out_data = Vec :: with_capacity ( odatalen) ;
361
343
inidx = 0 ;
362
344
outidx = 0 ;
363
345
linelen = 0 ;
@@ -395,79 +377,72 @@ mod decl {
395
377
outidx += 1 ;
396
378
397
379
ch = hex_nibble ( buf[ inidx] >> 4 ) ;
398
- if ch >= 0x61 && ch <= 0x66 {
380
+ if ( 0x61 ..= 0x66 ) . contains ( & ch ) {
399
381
ch -= 0x20 ;
400
382
}
401
383
out_data. push ( ch) ;
402
384
ch = hex_nibble ( buf[ inidx] & 0xf ) ;
403
- if ch >= 0x61 && ch <= 0x66 {
385
+ if ( 0x61 ..= 0x66 ) . contains ( & ch ) {
404
386
ch -= 0x20 ;
405
387
}
406
388
out_data. push ( ch) ;
407
389
408
390
outidx += 2 ;
409
391
inidx += 1 ;
410
392
linelen += 3 ;
411
- } else {
412
- if istext
413
- && ( ( buf[ inidx] == 0x0a )
414
- || ( ( inidx + 1 < buflen)
415
- && ( buf[ inidx] == 0x0d )
416
- && ( buf[ inidx + 1 ] == 0x0a ) ) )
393
+ } else if istext
394
+ && ( ( buf[ inidx] == 0x0a )
395
+ || ( ( inidx + 1 < buflen)
396
+ && ( buf[ inidx] == 0x0d )
397
+ && ( buf[ inidx + 1 ] == 0x0a ) ) )
398
+ {
399
+ linelen = 0 ;
400
+ if ( outidx != 0 )
401
+ && ( ( out_data[ outidx - 1 ] == 0x20 ) || ( out_data[ outidx - 1 ] == 0x09 ) )
417
402
{
418
- linelen = 0 ;
419
- if ( outidx != 0 )
420
- && ( ( out_data[ outidx - 1 ] == 0x20 ) || ( out_data[ outidx - 1 ] == 0x09 ) )
421
- {
422
- ch = hex_nibble ( out_data[ outidx - 1 ] >> 4 ) ;
423
- if ch >= 0x61 && ch <= 0x66 {
424
- ch -= 0x20 ;
425
- }
426
- out_data. push ( ch) ;
427
- ch = hex_nibble ( out_data[ outidx - 1 ] & 0xf ) ;
428
- if ch >= 0x61 && ch <= 0x66 {
429
- ch -= 0x20 ;
430
- }
431
- out_data. push ( ch) ;
432
- out_data[ outidx - 1 ] = 0x3d ;
433
- outidx += 2 ;
403
+ ch = hex_nibble ( out_data[ outidx - 1 ] >> 4 ) ;
404
+ if ( 0x61 ..=0x66 ) . contains ( & ch) {
405
+ ch -= 0x20 ;
434
406
}
407
+ out_data. push ( ch) ;
408
+ ch = hex_nibble ( out_data[ outidx - 1 ] & 0xf ) ;
409
+ if ( 0x61 ..=0x66 ) . contains ( & ch) {
410
+ ch -= 0x20 ;
411
+ }
412
+ out_data. push ( ch) ;
413
+ out_data[ outidx - 1 ] = 0x3d ;
414
+ outidx += 2 ;
415
+ }
435
416
417
+ if crlf {
418
+ out_data. push ( 0x0d ) ;
419
+ outidx += 1 ;
420
+ }
421
+ out_data. push ( 0x0a ) ;
422
+ outidx += 1 ;
423
+ inidx += if buf[ inidx] == 0x0d { 2 } else { 1 } ;
424
+ } else {
425
+ if ( inidx + 1 != buflen) && ( buf[ inidx + 1 ] != 0x0a ) && ( linelen + 1 ) >= 76 {
426
+ // MAXLINESIZE = 76
427
+ out_data. push ( 0x3d ) ;
428
+ outidx += 1 ;
436
429
if crlf {
437
430
out_data. push ( 0x0d ) ;
438
431
outidx += 1 ;
439
432
}
440
433
out_data. push ( 0x0a ) ;
441
434
outidx += 1 ;
442
- if buf[ inidx] == 0x0d {
443
- inidx += 2 ;
444
- } else {
445
- inidx += 1 ;
446
- }
435
+ linelen = 0 ;
436
+ }
437
+ linelen += 1 ;
438
+ if header && buf[ inidx] == 0x20 {
439
+ out_data. push ( 0x5f ) ;
440
+ outidx += 1 ;
441
+ inidx += 1 ;
447
442
} else {
448
- if ( inidx + 1 != buflen) && ( buf[ inidx + 1 ] != 0x0a ) && ( linelen + 1 ) >= 76
449
- {
450
- // MAXLINESIZE = 76
451
- out_data. push ( 0x3d ) ;
452
- outidx += 1 ;
453
- if crlf {
454
- out_data. push ( 0x0d ) ;
455
- outidx += 1 ;
456
- }
457
- out_data. push ( 0x0a ) ;
458
- outidx += 1 ;
459
- linelen = 0 ;
460
- }
461
- linelen += 1 ;
462
- if header && buf[ inidx] == 0x20 {
463
- out_data. push ( 0x5f ) ;
464
- outidx += 1 ;
465
- inidx += 1 ;
466
- } else {
467
- out_data. push ( buf[ inidx] ) ;
468
- outidx += 1 ;
469
- inidx += 1 ;
470
- }
443
+ out_data. push ( buf[ inidx] ) ;
444
+ outidx += 1 ;
445
+ inidx += 1 ;
471
446
}
472
447
}
473
448
}
0 commit comments