123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990(**************************************************************************)(* *)(* Copyright 2011 Jun Furuse *)(* Copyright 2012,2013 OCamlPro *)(* *)(* All rights reserved.This file is distributed under the terms of the *)(* GNU Lesser General Public License version 2.1 with linking *)(* exception. *)(* *)(* TypeRex 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 *)(* Lesser GNU General Public License for more details. *)(* *)(**************************************************************************)letcompose:('b->'c)->('a->'b)->'a->'c=funfgx->f(g(x))let(@*)=composeletdefaultd=functionSomex->x|None->dletstring_splitcharstr=letrecauxaccpos=leti=trySome(String.rindex_fromstrposchar)withNot_found|Invalid_argument_->Noneinmatchiwith|Somei->aux(String.substr(i+1)(pos-i)::acc)(predi)|None->String.substr0(pos+1)::accinaux[](String.lengthstr-1)letstring_split_charscharsstr=letlen=String.lengthstrinletrecsplitpos=letreclookupi=ifi>=lenthenraiseNot_foundelseifString.containscharsstr.[i]thenielselookup(succi)intryleti=lookupposinifi>posthenString.substrpos(i-pos)::split(succi)elsesplit(succi)withNot_found|Invalid_argument_->[String.substrpos(len-pos)]insplit0letis_prefixpfxstr=letpfxlen=String.lengthpfxinletrecchecki=i>=pfxlen||pfx.[i]=str.[i]&&check(i+1)inString.lengthstr>=pfxlen&&check0letends_with_escapes=letrecauxn=n>=0&&s.[n]='\\'&¬(aux(n-1))inaux(String.lengths-1)letcount_leading_spacess=letrecauxi=ifi>=String.lengths||s.[i]<>' 'thenielseaux(i+1)inaux0letshorten_stringns=matchstring_split'\n'swith|[]->""|[s]->ifString.lengths<=nthenselseletn1=(n-3)/2inletn2=n-3-n1inString.subs0n1^"..."^String.subs(String.lengths-n2)n2|s1::r1::r->lets2=letreclastx=functionx::r->lastxr|[]->xinlastr1rinletl1=String.lengths1andl2=String.lengths2inletn1=minl1(max((n-3)/2)(n-3-l2))inletn2=minl2(n-3-n1)inString.subs10n1^"..."^String.subs2(l2-n2)n2