Factor out WIDTH_AT macro

This commit is contained in:
David Tolnay 2022-07-22 18:32:00 -07:00
parent 5305f1811a
commit 440e55a6af
No known key found for this signature in database
GPG key ID: F9BA143B95FF6D82
2 changed files with 20 additions and 20 deletions

View file

@ -2500,25 +2500,7 @@ unsafe fn yaml_emitter_write_folded_scalar(
{ {
let mut k: libc::c_int = 0_i32; let mut k: libc::c_int = 0_i32;
while IS_BREAK_AT!(string, k as isize) { while IS_BREAK_AT!(string, k as isize) {
k += if *string.pointer.wrapping_offset(k as isize) as libc::c_int & 0x80_i32 k += WIDTH_AT!(string, k as isize);
== 0_i32
{
1_i32
} else if *string.pointer.wrapping_offset(k as isize) as libc::c_int & 0xe0_i32
== 0xc0_i32
{
2_i32
} else if *string.pointer.wrapping_offset(k as isize) as libc::c_int & 0xf0_i32
== 0xe0_i32
{
3_i32
} else if *string.pointer.wrapping_offset(k as isize) as libc::c_int & 0xf8_i32
== 0xf0_i32
{
4_i32
} else {
0_i32
};
} }
if !IS_BLANKZ_AT!(string, k) { if !IS_BLANKZ_AT!(string, k) {
if !(PUT_BREAK!(emitter)) { if !(PUT_BREAK!(emitter)) {

View file

@ -351,7 +351,25 @@ macro_rules! IS_BLANKZ {
} }
macro_rules! WIDTH_AT { macro_rules! WIDTH_AT {
() => {}; // TODO ($string:expr, $offset:expr) => {
if *$string.pointer.wrapping_offset($offset as isize) as libc::c_int & 0x80_i32 == 0_i32 {
1_i32
} else if *$string.pointer.wrapping_offset($offset as isize) as libc::c_int & 0xe0_i32
== 0xc0_i32
{
2_i32
} else if *$string.pointer.wrapping_offset($offset as isize) as libc::c_int & 0xf0_i32
== 0xe0_i32
{
3_i32
} else if *$string.pointer.wrapping_offset($offset as isize) as libc::c_int & 0xf8_i32
== 0xf0_i32
{
4_i32
} else {
0_i32
}
};
} }
macro_rules! WIDTH { macro_rules! WIDTH {