1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677(*********************************************************************************)(* Higlo *)(* *)(* Copyright (C) 2014-2021 Institut National de Recherche en Informatique *)(* et en Automatique. All rights reserved. *)(* *)(* This program is free software; you can redistribute it and/or modify *)(* it under the terms of the GNU Lesser General Public License version *)(* 3 as published by the Free Software Foundation. *)(* *)(* This program 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 Library General Public License for more details. *)(* *)(* You should have received a copy of the GNU Lesser General Public *)(* License along with this program; if not, write to the Free Software *)(* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA *)(* 02111-1307 USA *)(* *)(* Contact: Maxence.Guesdon@inria.fr *)(* *)(* *)(*********************************************************************************)(** Utilities *)letsplit_string?(keep_empty=false)schars=letlen=String.lengthsinletreciteraccpos=ifpos>=lenthenmatchaccwith""->ifkeep_emptythen[""]else[]|_->[acc]elseifList.mems.[pos]charsthenmatchaccwith""->ifkeep_emptythen""::iter""(pos+1)elseiter""(pos+1)|_->acc::(iter""(pos+1))elseiter(Printf.sprintf"%s%c"accs.[pos])(pos+1)initer""0letis_prefix~of_:s1s2=letlen1=String.lengths1inletlen2=String.lengths2inlen1>=len2&&(String.subs10len2)=s2letstrip_strings=letlen=String.lengthsinletreciter_firstn=ifn>=lenthenNoneelsematchs.[n]with' '|'\t'|'\n'|'\r'->iter_first(n+1)|_->Someninmatchiter_first0withNone->""|Somefirst->letreciter_lastn=ifn<=firstthenNoneelsematchs.[n]with' '|'\t'|'\n'|'\r'->iter_last(n-1)|_->Someninmatchiter_last(len-1)withNone->String.subsfirst1|Somelast->String.subsfirst((last-first)+1)