From e776070311f776aafe24ad5a93144183798e8af0 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Fri, 22 Jul 2022 17:26:29 -0700 Subject: [PATCH] Factor out AS_DIGIT macro --- src/macros.rs | 8 +++----- src/scanner.rs | 10 +++------- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/src/macros.rs b/src/macros.rs index 6ba1e75..961d7d4 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -149,12 +149,10 @@ macro_rules! IS_DIGIT { }; } -macro_rules! AS_DIGIT_AT { - () => {}; // TODO -} - macro_rules! AS_DIGIT { - () => {}; // TODO + ($string:expr) => { + *$string.pointer as libc::c_int - '0' as i32 as yaml_char_t as libc::c_int + }; } macro_rules! IS_HEX_AT { diff --git a/src/scanner.rs b/src/scanner.rs index b318e48..e4ef974 100644 --- a/src/scanner.rs +++ b/src/scanner.rs @@ -1532,9 +1532,7 @@ unsafe fn yaml_parser_scan_version_directive_number( b"found extremely long version number\0" as *const u8 as *const libc::c_char, ); } - value = value * 10_i32 - + (*((*parser).buffer.pointer) as libc::c_int - - '0' as i32 as yaml_char_t as libc::c_int); + value = value * 10_i32 + AS_DIGIT!((*parser).buffer); SKIP!(parser); if CACHE!(parser, 1_u64) == 0 { return 0_i32; @@ -2323,8 +2321,7 @@ unsafe fn yaml_parser_scan_block_scalar( ); current_block = 14984465786483313892; } else { - increment = *((*parser).buffer.pointer) as libc::c_int - - '0' as i32 as yaml_char_t as libc::c_int; + increment = AS_DIGIT!((*parser).buffer); SKIP!(parser); current_block = 11913429853522160501; } @@ -2345,8 +2342,7 @@ unsafe fn yaml_parser_scan_block_scalar( ); current_block = 14984465786483313892; } else { - increment = *((*parser).buffer.pointer) as libc::c_int - - '0' as i32 as yaml_char_t as libc::c_int; + increment = AS_DIGIT!((*parser).buffer); SKIP!(parser); if CACHE!(parser, 1_u64) == 0 { current_block = 14984465786483313892;