Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file string_table.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127(*Generated by Lem from string_table.lem.*)(** The [string_table] module implements string tables. An ELF file may have
* multiple different string tables used for different purposes. A string
* table is a string coupled with a delimiting character. Strings may be indexed
* at any position, not necessarily on a delimiter boundary.
*)openLem_basic_classesopenLem_listopenLem_maybeopenLem_numopenLem_stringopenByte_sequenceopenErroropenMissing_pervasivesopenShow(** [string_table] type, represents a string table with a fixed delimiting
* character and underlying string.
*)typestring_table=Stringsof(char*string)(*val dummy_strtab : string_table*)letdummy_strtab:string_table=(Strings('\n',""))(** [mk_string_table base sep] constructs a string table using [base] as the
* base string and [sep] as the delimiting character to use to split [base]
* when trying to access the string stored in the table using the functions below.
*)(*val mk_string_table : string -> char -> string_table*)letmk_string_tablebasesep:string_table=(Strings(sep,base))(** [string_table_of_byte_sequence seq] constructs a string table, using the NUL
* character as terminator, from a byte sequence. *)(*val string_table_of_byte_sequence : byte_sequence -> string_table*)letstring_table_of_byte_sequenceseq:string_table=(mk_string_table(string_of_byte_sequenceseq)null_char)(** [empty] is the empty string table with an arbitrary choice of delimiter.
*)(*val empty : string_table*)letempty0:string_table=(Strings(null_char,Xstring.implode[null_char]))(** [get_delimiating_character tbl] returns the delimiting character associated
* with the string table [tbl], used to split the strings.
*)(*val get_delimiting_character : string_table -> char*)letget_delimiting_charactertbl:char=((matchtblwith|Strings(sep,base)->sep))(** [get_base_string tbl] returns the base string of the string table [tbl].
*)(*val get_base_string : string_table -> string*)letget_base_stringtbl:string=((matchtblwith|Strings(sep,base)->base))(** [size tbl] returns the size in bytes of the string table [tbl].
*)(*val size : string_table -> natural*)letsize0tbl:Nat_big_num.num=(Nat_big_num.of_int(String.length(get_base_stringtbl)))(** [concat xs] concatenates several string tables into one providing they all
* have the same delimiting character.
*)(*val concat : list string_table -> error string_table*)letconcat0xs:(string_table)error=((matchxswith|[]->returnempty0|x::xs->letdelim=(get_delimiting_characterx)inif(List.for_all(funx->get_delimiting_characterx=delim)(x::xs))thenletbase=(List.fold_right(^)(Lem_list.mapget_base_string(x::xs))"")inreturn(mk_string_tablebasedelim)elsefail"concat: string tables must have same delimiting characters"))(** [get_string_at index tbl] returns the string starting at character [index]
* from the start of the base string until the first occurrence of the delimiting
* character.
*)(*val get_string_at : natural -> string_table -> error string*)letget_string_atindextbl:(string)error=((matchMl_bindings.string_suffixindex(get_base_stringtbl)with|None->Fail"get_string_at: index out of range"|Somesuffix->letdelim=(get_delimiting_charactertbl)in(matchMl_bindings.string_index_ofdelimsuffixwith|Someidx1->(matchMl_bindings.string_prefixidx1suffixwith|Somes->Successs|None->Fail"get_string_at: index out of range")|None->Successsuffix)))(*val find_string : string -> string_table -> maybe natural*)letfind_stringst:(Nat_big_num.num)option=((matchtwithStrings(delim,base)->Ml_bindings.find_substring(s^Xstring.implode[delim])base))(*val insert_string : string -> string_table -> (natural * string_table)*)letinsert_stringst:Nat_big_num.num*string_table=((*let _ = errln ("Inserting string `" ^ s ^ "' into a string table") in*)let(inserted_idx,new_strtab)=((matchfind_stringstwithNone->(matchtwithStrings(delim,base)->(Nat_big_num.of_int(String.lengthbase),Strings(delim,(base^(s^(Xstring.implode[delim]))))))|Somepos->(pos,t)))in(*let _ = errln ("Inserted string at idx " ^ (show inserted_idx) ^ ", see: " ^ (show (find_string s new_strtab)))
in*)(inserted_idx,new_strtab))letinstance_Show_Show_String_table_string_table_dict:(string_table)show_class=({show_method=(funtbl->Xstring.implode(Lem_list.map(func->ifc='\000'then'\n'elsec)(Xstring.explode(get_base_stringtbl))))})