Factor out IS_SPACE_AT macro

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

View file

@ -2017,8 +2017,7 @@ unsafe fn yaml_emitter_write_plain_scalar(
if allow_breaks != 0 if allow_breaks != 0
&& spaces == 0 && spaces == 0
&& (*emitter).column > (*emitter).best_width && (*emitter).column > (*emitter).best_width
&& !(*string.pointer.wrapping_offset(1_isize) as libc::c_int && !IS_SPACE_AT!(string, 1)
== ' ' as i32 as yaml_char_t as libc::c_int)
{ {
if yaml_emitter_write_indent(emitter) == 0 { if yaml_emitter_write_indent(emitter) == 0 {
return 0_i32; return 0_i32;
@ -2086,8 +2085,7 @@ unsafe fn yaml_emitter_write_single_quoted_scalar(
&& (*emitter).column > (*emitter).best_width && (*emitter).column > (*emitter).best_width
&& string.pointer != string.start && string.pointer != string.start
&& string.pointer != string.end.wrapping_offset(-(1_isize)) && string.pointer != string.end.wrapping_offset(-(1_isize))
&& !(*string.pointer.wrapping_offset(1_isize) as libc::c_int && !IS_SPACE_AT!(string, 1)
== ' ' as i32 as yaml_char_t as libc::c_int)
{ {
if yaml_emitter_write_indent(emitter) == 0 { if yaml_emitter_write_indent(emitter) == 0 {
return 0_i32; return 0_i32;
@ -2336,9 +2334,7 @@ unsafe fn yaml_emitter_write_double_quoted_scalar(
if yaml_emitter_write_indent(emitter) == 0 { if yaml_emitter_write_indent(emitter) == 0 {
return 0_i32; return 0_i32;
} }
if *string.pointer.wrapping_offset(1_isize) as libc::c_int if IS_SPACE_AT!(string, 1) {
== ' ' as i32 as yaml_char_t as libc::c_int
{
if !(PUT!(emitter, '\\')) { if !(PUT!(emitter, '\\')) {
return 0_i32; return 0_i32;
} }
@ -2544,8 +2540,7 @@ unsafe fn yaml_emitter_write_folded_scalar(
} }
if breaks == 0 if breaks == 0
&& IS_SPACE!(string) && IS_SPACE!(string)
&& !(*string.pointer.wrapping_offset(1_isize) as libc::c_int && !IS_SPACE_AT!(string, 1)
== ' ' as i32 as yaml_char_t as libc::c_int)
&& (*emitter).column > (*emitter).best_width && (*emitter).column > (*emitter).best_width
{ {
if yaml_emitter_write_indent(emitter) == 0 { if yaml_emitter_write_indent(emitter) == 0 {

View file

@ -250,12 +250,15 @@ macro_rules! IS_BOM {
} }
macro_rules! IS_SPACE_AT { macro_rules! IS_SPACE_AT {
() => {}; // TODO ($string:expr, $offset:expr) => {
*$string.pointer.wrapping_offset($offset as isize) as libc::c_int
== ' ' as i32 as yaml_char_t as libc::c_int
};
} }
macro_rules! IS_SPACE { macro_rules! IS_SPACE {
($string:expr) => { ($string:expr) => {
*$string.pointer as libc::c_int == ' ' as i32 as yaml_char_t as libc::c_int IS_SPACE_AT!($string, 0)
}; };
} }
@ -274,9 +277,7 @@ macro_rules! IS_TAB {
macro_rules! IS_BLANK_AT { macro_rules! IS_BLANK_AT {
($string:expr, $offset:expr) => { ($string:expr, $offset:expr) => {
*$string.pointer.wrapping_offset($offset as isize) as libc::c_int IS_SPACE_AT!($string, $offset) || IS_TAB_AT!($string, $offset)
== ' ' as i32 as yaml_char_t as libc::c_int
|| IS_TAB_AT!($string, $offset)
}; };
} }