@@ -1413,87 +1413,87 @@ impl Function for ReplaceAll {
14131413 }
14141414}
14151415
1416- pub struct CountTableDims ;
1416+ struct CountTableDims ;
14171417impl CountTableDims {
14181418 /// For an `mtable` element, count the number of rows and columns in the table.
14191419 ///
14201420 /// This function is relatively permissive. Non-`mtr` rows are
14211421 /// ignored. The number of columns is determined only from the first
14221422 /// row, if it exists. Within that row, non-`mtd` elements are ignored.
14231423 fn count_table_dims < ' d > ( e : Element < ' _ > ) -> Result < ( Value < ' d > , Value < ' d > ) , Error > {
1424- let mut num_cols = 0 ;
1425- let mut num_rows = 0 ;
1426- for child in e. children ( ) {
1427- let ChildOfElement :: Element ( row) = child else {
1428- continue
1429- } ;
1430-
1431- // each child of mtable should be an mtr. Ignore non-mtr rows.
1432- let row_name = name ( row) ;
1433-
1434- let labeled_row = if row_name == "mlabeledtr" {
1435- true
1436- } else if row_name == "mtr" {
1437- false
1438- } else {
1439- continue ;
1440- } ;
1441- num_rows += 1 ;
1442-
1443- // count columns based on the number of rows.
1444- if num_rows == 1 {
1445- // count the number of columns, including column spans, in the first row.
1446- let mut first_elem = true ;
1447- for row_child in row. children ( ) {
1448- let ChildOfElement :: Element ( mtd) = row_child else {
1449- continue ;
1450- } ;
1451- if name ( mtd) != "mtd" {
1452- continue ;
1453- }
1454- // Add the contributing columns, taking colspan into account. Don't contribute if
1455- // this is the first element of a labeled row.
1456- let colspan = mtd. attribute_value ( "colspan" ) . map_or ( 1 , |e| e. parse :: < usize > ( ) . unwrap_or ( 0 ) ) ;
1457- if !( labeled_row && first_elem) {
1458- num_cols += colspan;
1459- }
1460- first_elem = false ;
1461- }
1462- }
1463- }
1464-
1465- Ok ( ( Value :: Number ( num_rows as f64 ) , Value :: Number ( num_cols as f64 ) ) )
1424+ let mut num_cols = 0 ;
1425+ let mut num_rows = 0 ;
1426+ for child in e. children ( ) {
1427+ let ChildOfElement :: Element ( row) = child else {
1428+ continue
1429+ } ;
1430+
1431+ // each child of mtable should be an mtr. Ignore non-mtr rows.
1432+ let row_name = name ( row) ;
1433+
1434+ let labeled_row = if row_name == "mlabeledtr" {
1435+ true
1436+ } else if row_name == "mtr" {
1437+ false
1438+ } else {
1439+ continue ;
1440+ } ;
1441+ num_rows += 1 ;
1442+
1443+ // count columns based on the number of rows.
1444+ if num_rows == 1 {
1445+ // count the number of columns, including column spans, in the first row.
1446+ let mut first_elem = true ;
1447+ for row_child in row. children ( ) {
1448+ let ChildOfElement :: Element ( mtd) = row_child else {
1449+ continue ;
1450+ } ;
1451+ if name ( mtd) != "mtd" {
1452+ continue ;
1453+ }
1454+ // Add the contributing columns, taking colspan into account. Don't contribute if
1455+ // this is the first element of a labeled row.
1456+ let colspan = mtd. attribute_value ( "colspan" ) . map_or ( 1 , |e| e. parse :: < usize > ( ) . unwrap_or ( 0 ) ) ;
1457+ if !( labeled_row && first_elem) {
1458+ num_cols += colspan;
1459+ }
1460+ first_elem = false ;
1461+ }
1462+ }
1463+ }
1464+
1465+ Ok ( ( Value :: Number ( num_rows as f64 ) , Value :: Number ( num_cols as f64 ) ) )
14661466 }
14671467
14681468 fn evaluate < ' d > ( fn_name : & str ,
14691469 args : Vec < Value < ' d > > ) -> Result < ( Value < ' d > , Value < ' d > ) , Error > {
1470- let mut args = Args ( args) ;
1471- args. exactly ( 1 ) ?;
1472- let element = args. pop_nodeset ( ) ?;
1473- let node = validate_one_node ( element, fn_name) ?;
1474- if let Node :: Element ( e) = node {
1475- return Self :: count_table_dims ( e) ;
1476- }
1477-
1478- Err ( Error :: Other ( "couldn't count table rows" . to_string ( ) ) )
1470+ let mut args = Args ( args) ;
1471+ args. exactly ( 1 ) ?;
1472+ let element = args. pop_nodeset ( ) ?;
1473+ let node = validate_one_node ( element, fn_name) ?;
1474+ if let Node :: Element ( e) = node {
1475+ return Self :: count_table_dims ( e) ;
1476+ }
1477+
1478+ Err ( Error :: Other ( "couldn't count table rows" . to_string ( ) ) )
14791479 }
14801480}
14811481
1482- pub struct CountTableRows ;
1482+ struct CountTableRows ;
14831483impl Function for CountTableRows {
14841484 fn evaluate < ' c , ' d > ( & self ,
14851485 _context : & context:: Evaluation < ' c , ' d > ,
14861486 args : Vec < Value < ' d > > ) -> Result < Value < ' d > , Error > {
1487- CountTableDims :: evaluate ( "CountTableRows" , args) . map ( |a| a. 0 )
1487+ CountTableDims :: evaluate ( "CountTableRows" , args) . map ( |a| a. 0 )
14881488 }
14891489}
14901490
1491- pub struct CountTableColumns ;
1491+ struct CountTableColumns ;
14921492impl Function for CountTableColumns {
14931493 fn evaluate < ' c , ' d > ( & self ,
14941494 _context : & context:: Evaluation < ' c , ' d > ,
14951495 args : Vec < Value < ' d > > ) -> Result < Value < ' d > , Error > {
1496- CountTableDims :: evaluate ( "CountTableColumns" , args) . map ( |a| a. 1 )
1496+ CountTableDims :: evaluate ( "CountTableColumns" , args) . map ( |a| a. 1 )
14971497 }
14981498}
14991499
0 commit comments