123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263(********************************************************************************)(* crs - A tool for managing code review comments embedded in source code *)(* Copyright (C) 2024-2025 Mathieu Barbin <mathieu.barbin@gmail.com> *)(* *)(* This file is part of crs. *)(* *)(* crs is free software; you can redistribute it and/or modify it under the *)(* terms of the GNU Lesser General Public License as published by the Free *)(* Software Foundation either version 3 of the License, or any later version, *)(* with the LGPL-3.0 Linking Exception. *)(* *)(* crs is distributed in the hope that it will be useful, but WITHOUT ANY *)(* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *)(* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License and *)(* the file `NOTICE.md` at the root of this repository for more details. *)(* *)(* You should have received a copy of the GNU Lesser General Public License *)(* and the LGPL-3.0 Linking Exception along with this library. If not, see *)(* <http://www.gnu.org/licenses/> and <https://spdx.org>, respectively. *)(********************************************************************************)moduleColumn=structtypet={header:string;align:Text_table_ast.Align.t;cells:Text_table_ast.Cell.tlist;length:int}endtypet={columns:Column.tarray}letof_text_table(Text_table_ast.T{columns;rows})=letcolumns=Array.of_list_mapcolumns~f:(fun{header;align;make_cell}->letcells=List.maprows~f:(funrow->make_cellrow)inletlength=List.foldcells~init:0~f:(funlencell->Int.maxlen(String.lengthcell.text))iniflength=0thenNoneelse(letlength=Int.maxlength(String.lengthheader)inSome{Column.header;align;cells;length}))|>Array.filter_map~f:Fn.idin{columns};;letpads~len~align=letslen=String.lengthsinifslen>=lenthenselse(letpad=String.make(len-slen)' 'inmatch(align:Text_table_ast.Align.t)with|Left->s^pad|Right->pad^s|Center->letleft=(len-slen)/2inletright=len-slen-leftinString.makeleft' '^s^String.makeright' ');;