123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108(*********************************************************************************)(* Xtmpl *)(* *)(* Copyright (C) 2012-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 *)(* *)(* *)(*********************************************************************************)(** *)(*c==v=[File.string_of_file]=1.1====*)letstring_of_filename=letchanin=open_in_binnameinletlen=1024inlets=Bytes.createleninletbuf=Buffer.createleninletreciter()=tryletn=inputchanins0leninifn=0then()else(Buffer.add_subbytesbufs0n;iter())withEnd_of_file->()initer();close_inchanin;Buffer.contentsbuf(*/c==v=[File.string_of_file]=1.1====*)(*c==v=[String.split_string]=1.2====*)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""0(*/c==v=[String.split_string]=1.2====*)(*c==v=[String.strip_string]=1.0====*)letstrip_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)(*/c==v=[String.strip_string]=1.0====*)(*c==v=[File.file_of_string]=1.1====*)letfile_of_string~files=letoc=open_outfileinoutput_stringocs;close_outoc(*/c==v=[File.file_of_string]=1.1====*)