123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051(* This file is part of Markup.ml, released under the MIT license. See
LICENSE.md for details, or visit https://github.com/aantron/markup.ml. *)openCommontypet={mutablestrings:stringlist;buffer:Buffer.t;mutablelocation:locationoption}(* This is changed for unit testing. *)letlength_limit=ref(Sys.max_string_length/2)letprepare()={strings=[];buffer=Buffer.create256;location=None}letnote_locationtextlocation=beginmatchtext.locationwith|None->text.location<-Somelocation|Some_->()endletaddingtextlocation=note_locationtextlocation;ifBuffer.lengthtext.buffer>=!length_limitthenbegintext.strings<-(Buffer.contentstext.buffer)::text.strings;Buffer.cleartext.bufferendletaddtextlocationc=addingtextlocation;add_utf_8text.bufferc(* This is only used for strings that are expected to be very small, at the
moment. *)letadd_stringtextlocations=addingtextlocation;Buffer.add_stringtext.buffersletemittext=matchtext.locationwith|None->None|Somelocation->text.location<-None;ifBuffer.lengthtext.buffer=0thenNoneelsebeginletstrings=(Buffer.contentstext.buffer)::text.strings|>List.revintext.strings<-[];Buffer.cleartext.buffer;Some(location,strings)end