text
stringlengths
12
786k
let owner_key padded_owner keylength r = let digest1 = Digest . string ( string_of_int_array padded_owner ) in let digest2 = if r >= 3 then let d = ref digest1 in for x = 1 to 50 do d := Digest . string ! d done ; ! d else digest1 in int_array_of_string ( String . sub digest2 0 ( keylength ...
let mkkey key x = let key ' = Array . copy key in for k = 0 to Array . length key - 1 do key ' . ( k ) <- key . ( k ) lxor x done ; key '
let decrypt_single_stream user_pw owner_pw pdf obj gen stream = match Pdf . lookup_direct pdf " / Encrypt " pdf . Pdf . trailerdict with | None -> stream | Some encrypt_dict -> let crypt_type , u , o , p , id , ue , oe = get_encryption_values pdf in let r , keylength = match crypt_type w...
let key_or_user_password_from_owner ? encryption_values owner_pw pdf = let padded_owner = pad_password ( int_array_of_string owner_pw ) in let crypt_type , u , o , oe = match encryption_values with Some e -> e | None -> let crypt_type , u , o , _ , _ , _ , oe = get_encryption_values pdf...
let decrypt_pdf_owner owner_pw pdf = match Pdf . lookup_direct pdf " / Encrypt " pdf . Pdf . trailerdict with None -> Some pdf | _ -> match key_or_user_password_from_owner owner_pw pdf with None -> None | Some ( key , user_pw ) -> fst ( decrypt_pdf user_pw ~ keyfromowner : key pdf )
let mk_owner r owner_pw user_pw keylength = let padded_owner = let source = if owner_pw = " " then user_pw else owner_pw in pad_password ( int_array_of_string source ) in let key = owner_key padded_owner keylength r in let padded_user = pad_password ( int_array_of_string user_pw ) in if r = 2 then s...
let mk_user no_encrypt_metadata user_pw o p id r keylength = let key = find_key no_encrypt_metadata user_pw r o p id keylength in if r = 2 then string_of_bytes ( Pdfcryptprimitives . crypt key ( bytes_of_int_array paddings ) ) else let digest_input = [ paddings ; int_array_of_string id ] in let d ...
let get_or_add_id pdf = match Pdf . lookup_direct pdf " / ID " pdf . Pdf . trailerdict with | Some ( Pdf . Array [ Pdf . String s ; _ ] ) -> s , pdf | _ -> let idobj = Pdf . generate_id pdf " " ( fun ( ) -> Random . float 1 . ) in let pdf ' = { pdf with Pdf . ...
let encrypt_pdf_40bit_inner owner user p user_pw id pdf = let crypt_dict = Pdf . Dictionary [ " / Filter " , Pdf . Name " / Standard " ; " / V " , Pdf . Integer 1 ; " / R " , Pdf . Integer 2 ; " / O " , Pdf . String owner ; " / U " , Pdf . String user ; ...
let encrypt_pdf_40bit user_pw owner_pw banlist pdf = let p = p_of_banlist banlist in let owner = mk_owner 2 owner_pw user_pw 40 in let id , pdf = get_or_add_id pdf in let user = mk_user false user_pw owner p id 2 40 in encrypt_pdf_40bit_inner owner user p user_pw id pdf
let encrypt_pdf_128bit_inner owner user p user_pw id pdf = let crypt_dict = Pdf . Dictionary [ " / Filter " , Pdf . Name " / Standard " ; " / V " , Pdf . Integer 2 ; " / R " , Pdf . Integer 3 ; " / O " , Pdf . String owner ; " / U " , Pdf . String user ;...
let encrypt_pdf_128bit_inner_r4 owner user p user_pw id pdf encrypt_metadata = let crypt_dict = Pdf . Dictionary [ " / Filter " , Pdf . Name " / Standard " ; " / V " , Pdf . Integer 4 ; " / CF " , Pdf . Dictionary [ " / StdCF " , Pdf . Dictionary [ " / Length "...
let encrypt_pdf_128bit user_pw owner_pw banlist pdf = let p = p_of_banlist banlist in let owner = mk_owner 3 owner_pw user_pw 128 in let id , pdf = get_or_add_id pdf in let user = mk_user false user_pw owner p id 3 128 in encrypt_pdf_128bit_inner owner user p user_pw id pdf
let encrypt_pdf_AES_inner owner user p user_pw id encrypt_metadata pdf = let crypt_dict = Pdf . Dictionary [ " / Filter " , Pdf . Name " / Standard " ; " / V " , Pdf . Integer 4 ; " / CF " , Pdf . Dictionary [ " / StdCF " , Pdf . Dictionary [ " / Length " , ...
let encrypt_pdf_AES encrypt_metadata user_pw owner_pw banlist pdf = let p = p_of_banlist banlist in let owner = mk_owner 4 owner_pw user_pw 128 in let id , pdf = get_or_add_id pdf in let user = mk_user ( not encrypt_metadata ) user_pw owner p id 4 128 in encrypt_pdf_AES_inner owner user p user_pw id encr...
let encrypt_pdf_AES256_inner iso encrypt_metadata owner user p perms oe ue id key pdf = if ! crypt_debug then Printf . eprintf " encrypt_pdf_AES256_inner , ISO = % b \ n " %! iso ; let crypt_dict = Pdf . Dictionary [ " / Filter " , Pdf . Name " / Standard " ; " / V " , Pdf . ...
let perms_of_p ? digest iso encrypt_metadata p utf8pw o oe u = let extendedp = lor64 0xFFFFFFFF00000000L ( i64ofi32 p ) in let b = Array . make 16 0 in for n = 0 to 7 do b . ( n ) <- i64toi ( land64 0x00000000000000FFL ( lsr64 ( land64 ( lsl64 0xFFL ( n * 8 ) ) extendedp ) ( ...
let make_ue iso file_encryption_key user_pw user_validation_salt user_key_salt = let hash = if iso then shamix user_pw None else ( fun x -> Pdfcryptprimitives . sha256 ( Pdfio . input_of_string x ) ) in let u = String . concat " " [ ( hash ( String . concat " " [ user_pw ; user_val...
let make_oe iso file_encryption_key owner_pw owner_validation_salt owner_key_salt u = let hash = if iso then shamix owner_pw ( Some u ) else ( fun x -> Pdfcryptprimitives . sha256 ( Pdfio . input_of_string x ) ) in let o = String . concat " " [ ( hash ( String . concat " " [ owne...
let mksalt ( ) = let s = Array . make 8 0 in for x = 0 to 7 do s . ( x ) <- Random . int 255 done ; string_of_int_array s
let mkfilekey ( ) = let s = Array . make 32 0 in for x = 0 to 31 do s . ( x ) <- Random . int 255 done ; string_of_int_array s
let encrypt_pdf_AES256_call iso encrypt_metadata user_pw owner_pw banlist pdf = let user_pw = make_utf8 user_pw and owner_pw = make_utf8 owner_pw and user_validation_salt = mksalt ( ) and user_key_salt = mksalt ( ) and owner_validation_salt = mksalt ( ) and owner_key_salt = mksalt ( ) and file_en...
let encrypt_pdf_AES256 = encrypt_pdf_AES256_call false
let encrypt_pdf_AES256ISO = encrypt_pdf_AES256_call true
let is_encrypted pdf = match Pdf . lookup_direct pdf " / Encrypt " pdf . Pdf . trailerdict with | Some _ -> true | None -> false
let recrypt_pdf_user pdf pw = let ( crypt_type , u , o , p , id , ue , oe ) , encrypt_metadata , perms = match pdf . Pdf . saved_encryption with None -> raise ( Pdf . PDFError " recrypt_pdf : no saved encryption " ) | Some x -> ( x . Pdf . from_get_encryption_values , x ....
let recrypt_pdf_owner pdf owner_pw = let ( crypt_type , u , o , p , id , ue , oe ) , encrypt_metadata , perms = match pdf . Pdf . saved_encryption with None -> raise ( Pdf . PDFError " recrypt_pdf : no saved encryption " ) | Some x -> ( x . Pdf . from_get_encryption_values ...
let recrypt_pdf ( ? renumber = true ) pdf pw = let pdf = if renumber then Pdf . renumber ( Pdf . changes pdf ) pdf else pdf in try try recrypt_pdf_user pdf pw with _ -> recrypt_pdf_owner pdf pw with _ -> raise ( Pdf . PDFError " recrypt_pdf failed . Wrong password " ) ?
type encryption = | ARC4 of int * int | AESV2 | AESV3 of bool " camlpdf_caml_aes_encrypt " " camlpdf_caml_aes_decrypt "
let key_expansion nk key = aes_cook_encrypt_key ( string_of_int_array key )
let key_expansion_decrypt nk key = aes_cook_decrypt_key ( string_of_int_array key )
let ksa s key = let keylength = Array . length key in for i = 0 to 255 do s . ( i ) <- i done ; let j = ref 0 in for i = 0 to 255 do j := ( ! j + s . ( i ) + key . ( i mod keylength ) ) mod 256 ; swap s i ! j done
let prga s pi pj = pi := ( ! pi + 1 ) mod 256 ; pj := ( ! pj + s . ( ! pi ) ) mod 256 ; swap s ! pi ! pj ; s . ( ( s . ( ! pi ) + s . ( ! pj ) ) mod 256 )
let crypt key data = let s , pi , pj , out = Array . make 256 0 , ref 0 , ref 0 , mkbytes ( bytes_size data ) in ksa s key ; for x = 0 to bytes_size data - 1 do bset out x ( bget data x lxor prga s pi pj ) done ; out
let _ = Random . self_init ( )
let ran255 ( ) = Random . int 255
let mkiv ( ) = let r = ran255 in [ | r ( ) ; r ( ) ; r ( ) ; r ( ) ; r ( ) ; r ( ) ; r ( ) ; r ( ) ; r ( ) ; r ( ) ; r ( ) ; r ( ) ; r ( ) ; r ( ) ; r ( ) ; r ( ) ] |
let get_blocks data = let l = bytes_size data in let fullblocks = if l < 16 then [ ] else let blocks = ref [ ] in for x = 0 to l / 16 - 1 do blocks =| let a = Array . make 16 0 in for y = 0 to 15 do Array . unsafe_set a y ( bget_unsafe data ( x * 16 + y ) ) done ; a done ; ...
let bytes_of_blocks blocks = let len = 16 * length blocks in let s = mkbytes len in let p = ref 0 in iter ( fun a -> Array . iter ( fun v -> bset s ! p v ; incr p ) a ) blocks ; s
let get_padding s = let l = bytes_size s in assert ( l >= 16 ) ; let potential = bget s ( l - 1 ) in if potential > 0x10 || potential < 0x01 then ( None ) else let rec elts_equal p f t = if f = t then p = bget s t else p = bget s f && elts_equal p ( f + 1 ) t in if elts_equal potent...
let cutshort s = if bytes_size s = 0 then mkbytes 0 else if bytes_size s < 16 then s else match get_padding s with | None -> s | Some padding -> let s ' = mkbytes ( bytes_size s - padding ) in for x = 0 to bytes_size s ' - 1 do bset_unsafe s ' x ( bget_unsafe s x ) done ; s '
let print_txt d p = for x = p to p + 15 do Printf . printf " % 02x " ( bget d x ) done ; flprint " \ n "
let aes_decrypt_data ( ? remove_padding = true ) nk key data = let key = key_expansion_decrypt nk key in let len = bytes_size data in if len <= 16 then mkbytes 0 else let output = mkbytes ( len - 16 ) and prev_ciphertext = mkbytes 16 in for x = 0 to 15 do bset_unsafe prev_ciphertext x ( bget_u...
let aes_decrypt_data_ecb ( ? remove_padding = true ) nk key data = let key = key_expansion_decrypt nk key in let size = bytes_size data in if size = 0 then mkbytes 0 else let output = mkbytes size and pos = ref 0 in while ! pos < size do let i = Bytes . make 16 ' ' and o = Bytes . make 16 '...
let aes_encrypt_data ( ? firstblock = mkiv ( ) ) nk key data = let key = key_expansion nk key in let outblocks = ref [ ] in let prev_ciphertext = ref firstblock in iter ( fun block -> let ciphertext = let src = let a = array_map2 ( lxor ) block ! prev_ciphertext in Bytes . init ( Array ...
let aes_encrypt_data_ecb nk key data = let key = key_expansion nk key in let size = bytes_size data in if size = 0 then mkbytes 0 else let output = mkbytes size and pos = ref 0 in while ! pos < size do let i = Bytes . make 16 ' ' and o = Bytes . make 16 ' ' in for x = 0 to 15 do Bytes . ...
let string_of_input i = let b = Buffer . create 100 in try while true do match i . input_char ( ) with Some c -> Buffer . add_char b c | None -> raise End_of_file done ; assert false with End_of_file -> Buffer . contents b
let sha256 i = sha_256 ( string_of_input i )
let sha384 i = sha_384 ( string_of_input i )
let sha512 i = sha_512 ( string_of_input i )
let find_hash crypt_type obj gen key keylength = let from_obj = [ | i32toi ( land32 obj 0x000000ffl ) ; i32toi ( lsr32 ( land32 obj 0x0000ff00l ) 8 ) ; i32toi ( lsr32 ( land32 obj 0x00ff0000l ) 16 ) ] | in let from_gen = [ | i32toi ( land32 gen 0x000000ffl ) ; i32toi ( ...
let decrypt_stream_data crypt_type encrypt file_encryption_key obj gen key keylength r data = let f = ( if crypt_type = AESV2 then ( if encrypt then aes_encrypt_data 4 else aes_decrypt_data 4 ) else if ( match crypt_type with AESV3 _ -> true | _ -> false ) then ( if encrypt then aes_encrypt_data 8...
type t = { year : int ; month : int ; day : int ; hour : int ; minute : int ; second : int ; hour_offset : int ; minute_offset : int }
let check_date d = try assert ( d . year >= 0 && d . year <= 9999 ) ; assert ( d . month >= 1 && d . month <= 12 ) ; assert ( d . day >= 1 && d . day <= 31 ) ; assert ( d . hour >= 0 && d . hour <= 23 ) ; assert ( d . minute >= 0 && d . minute <= 59...
let string_of_date d = check_date d ; let ostr = if d . hour_offset < 0 then Printf . sprintf " -% 02i ' % 02i ' " ( abs d . hour_offset ) ( abs d . minute_offset ) else if d . hour_offset > 0 then Printf . sprintf " +% 02i ' % 02i ' " ( abs d . hour_offset ) ( ...
let date_of_string s = let safe_int_string chars = try int_of_string ( implode chars ) with _ -> raise BadDate in let hour_offset = ref 0 in let minute_offset = ref 0 in let o = ref 0 in let rec optional_twochar def cs = match cs with | ( ' ' - | ' ' + | ' Z ' ) :: _ -> parse_loca...
type targetpage = | PageObject of int | OtherDocPageNumber of int
type t = | Action of Pdf . pdfobject | NullDestination | NamedDestinationElsewhere of string | XYZ of targetpage * float option * float option * float option | Fit of targetpage | FitH of targetpage * float option | FitV of targetpage * float option | FitR of targetpage * float * float * float * flo...
let read_targetpage = function | Pdf . Indirect i -> PageObject i | Pdf . Integer i -> OtherDocPageNumber i | _ -> assert false
let read_destination_error n s = Printf . eprintf " Warning : Could not read destination % s % s \ n " %! n s ; NullDestination
let rec read_destination pdf pdfobject = let option_getnum = function | Pdf . Null -> None | x -> Some ( Pdf . getnum x ) in match Pdf . direct pdf pdfobject with | Pdf . Dictionary d -> begin match Pdf . lookup_direct pdf " / D " ( Pdf . Dictionary d ) with | Some dest -> read_destin...
let pdf_of_targetpage = function | PageObject i -> Pdf . Indirect i | OtherDocPageNumber i -> Pdf . Integer i
let pos_null = function None -> Pdf . Null
let pdfobject_of_destination = function | Action a -> a | NullDestination -> Pdf . Null | NamedDestinationElsewhere s -> Pdf . String s | XYZ ( p , left , top , zoom ) -> Pdf . Array [ pdf_of_targetpage p ; Pdf . Name " / XYZ " ; pos_null left ; pos_null top ; pos_null zoom ] ...
let clip_pair ( a , b ) = let clip f = if f < - 32768 . 0 then - 32768 . 0 else if f > 32768 . 0 then 32768 . 0 else f in ( clip a , clip b )
let transform_destination t = function | FitH ( PageObject _ as p , Some top ) -> let ( _ , top ) = clip_pair ( Pdftransform . transform_matrix t ( 0 . , top ) ) in FitH ( p , Some top ) | FitV ( PageObject _ as p , Some left ) -> let ( left , _ ) = clip_pair ( ...
let isimage pdf ( _ , xobj ) = Pdf . lookup_direct pdf " / Subtype " xobj = Some ( Pdf . Name " / Image " )
let xobject_isimage pdf resources name = match resources with | Pdf . Dictionary _ -> begin match Pdf . lookup_direct pdf " / XObject " resources with | Some xobjects -> isimage pdf ( " " , Pdf . lookup_fail " xobject not there " pdf name xobjects ) | _ -> false end | _ -> failwith ...
let remove_image_xobjects pdf resources = match resources with | Pdf . Dictionary res -> begin match Pdf . lookup_direct pdf " / XObject " resources with | Some ( Pdf . Dictionary xobjects ) -> Pdf . Dictionary ( replace " / XObject " ( Pdf . Dictionary ( lose ( isimage pdf ) xobj...
let substitute = rev [ Pdfops . Op_q ; Pdfops . Op_w 0 . ; Pdfops . Op_G 0 . ; Pdfops . Op_re ( 0 . , 0 . , 1 . , 1 . ) ; Pdfops . Op_m ( 0 . , 0 . ) ; Pdfops . Op_l ( 1 . , 1 . ) ; Pdfops . Op_m ( 0 . , 1 . ) ; Pdfops . Op...
let rec remove_images_stream pdf resources prev = function | [ ] -> rev prev | ( Pdfops . Op_Do name ) as h :: t -> if xobject_isimage pdf resources name then remove_images_stream pdf resources ( substitute @ prev ) t else remove_images_stream pdf resources ( h :: prev ) t | Pdfops . Inline...
let remove_images_page pdf page = let content ' = remove_images_stream pdf page . Pdfpage . resources [ ] ( Pdfops . parse_operators pdf page . Pdfpage . resources page . Pdfpage . content ) in { page with Pdfpage . content = ( let stream = Pdfops . stream_of_ops content ' in Pdfco...
let remove_images pdf = let pages = Pdfpage . pages_of_pagetree pdf in let pages ' = map ( remove_images_page pdf ) pages in let pdf , pagetree_num = Pdfpage . add_pagetree pages ' pdf in let pdf = Pdfpage . add_root pagetree_num [ ] pdf in Pdf . remove_unreferenced pdf ; pdf
let _ = match Array . to_list Sys . argv with | [ _ ; in_file ; out_file ] -> begin try let ch = open_in_bin in_file in let pdf = Pdfread . pdf_of_channel None None ch in Pdfwrite . pdf_to_file ( remove_images pdf ) out_file ; close_in ch with err -> Printf . printf " Failed to produce...
let _ = Callback . register_exception " Pdfflate . Error " ( Error ( " " , " " ) )
type flush_command = Z_NO_FLUSH | Z_SYNC_FLUSH | Z_FULL_FLUSH | Z_FINISH stream -> bytes -> int -> int -> bytes -> int -> int -> flush_command -> bool * int * int = " camlpdf_camlzip_deflate_bytecode " " camlpdf_camlzip_deflate " stream -> bytes -> int -> int -> bytes -> int -> int -> flus...
let compress ( ? level = 6 ) ( ? header = true ) refill flush = let inbuf = Bytes . create buffer_size and outbuf = Bytes . create buffer_size in let zs = deflate_init level header in let rec compr inpos inavail = if inavail = 0 then begin let incount = refill inbuf in if incount = 0 then com...
let uncompress ( ? header = true ) refill flush = let inbuf = Bytes . create buffer_size and outbuf = Bytes . create buffer_size in let zs = inflate_init header in let rec uncompr inpos inavail = if inavail = 0 then begin let incount = refill inbuf in if incount = 0 then uncompr_finish true else unc...
type calculator = | If of calculator list | IfElse of calculator list * calculator list | Bool of bool | Float of float | Int of int32 | Abs | Add | Atan | Ceiling | Cos | Cvi | Cvr | Div | Exp | Floor | Idiv | Ln | Log | Mod | Mul | Neg | Round | Sin | Sqrt | Sub | Truncate | And | Bitshi...
type sampled = { size : int list ; order : int ; encode : float list ; decode : float list ; bps : int ; samples : int32 array } { c0 : float list ; c1 : float list ; n : float } { functions : t list ; bounds : float list ; stitch_encode : float list } | Interpolation of inte...
let rec string_of_calculator_inner = function | If l -> string_of_calculator l ^ " if " | IfElse ( l , l ' ) -> string_of_calculator l ^ " " ^ string_of_calculator l ' ^ " ifelse " | Bool true -> " true " | Bool false -> " false " | Float f -> string_of_float f | Int i -> ...
let rec print_function f = print_string " Domain . . . \ n " ; print_floats f . domain ; begin match f . range with | None -> print_string " null range \ n " | Some values -> print_floats values end ; match f . func with | Sampled s -> print_string " Sampled \ n " ; print_strin...
let keyword_of_string = function | " abs " -> Abs | " add " -> Add | " atan " -> Atan | " ceiling " -> Ceiling | " cos " -> Cos | " cvr " -> Cvr | " div " -> Div | " exp " -> Exp | " floor " -> Floor | " idiv " -> Idiv | " ln " -> Ln | " log " -> ...
let parse_calculator s = let lexemes = Pdfgenlex . lex ( Pdfio . input_of_string s ) in let rec strip_outer_braces = function | Pdfgenlex . LexName ( " { " | " } " ) :: t -> rev ( strip_outer_braces ( rev t ) ) | x -> x and group_operators = function | [ ] -> [ ] |...
let rec parse_function pdf f = let f = Pdf . direct pdf f in let getnum_direct o = Pdf . getnum ( Pdf . direct pdf o ) in let domain = match Pdf . lookup_fail " No / Domain " pdf " / Domain " f with | Pdf . Array ns -> map getnum_direct ns | _ -> raise ( Pdf . PDFError " Bad / Do...
let interpolate x xmin xmax ymin ymax = ymin . + ( ( x . - xmin ) . * ( ( ymax . - ymin ) . / ( xmax . - xmin ) ) )
let eval_function_sampled f s clamped_inputs = let range = match f . range with | None -> raise ( BadFunctionEvaluation " No Range " ) | Some r -> r in let d , d ' = split ( pairs_of_list f . domain ) in let e , e ' = split ( pairs_of_list s . encode ) in let dec , dec ' = spl...
let eval_function_calculator clamped_inputs ops = let s = ref ( map ( fun i -> Float i ) ( rev clamped_inputs ) ) in let typecheck ( ) = raise ( BadFunctionEvaluation " Type error " ) in let rec getfloat ( ) = match ! s with | Int i :: r -> s := r ; i32tof i | Float f :: r -> ...
let rec eval_function f inputs = let rec clampvals vals domain = let clampval v d d ' = if v < d then d else if v > d ' then d ' else v in match vals , domain with | [ ] , [ ] -> [ ] | v :: vs , d :: d ' :: ds -> clampval v d d ' :: clampvals vs ds | _ -> raise ( BadFunctio...
let funtype_of_function f = match f . func with | Interpolation _ -> 2 | Stitching _ -> 3 | Sampled _ -> 0 | Calculator _ -> 4
let mkreal x = Pdf . Real x
let entries_of_interpolation i = [ " / C0 " , Pdf . Array ( map mkreal i . c0 ) ; " / C1 " , Pdf . Array ( map mkreal i . c1 ) ; " / N " , Pdf . Real i . n ]
let rec entries_of_stitching pdf i = let numbers = map ( fun f -> Pdf . Indirect ( Pdf . addobj pdf ( pdfobject_of_function pdf f ) ) ) i . functions in [ " / Functions " , Pdf . Array numbers ; " / Bounds " , Pdf . Array ( map mkreal i . bounds ) ; " / Encode " ,...
type t = | LexNull | LexBool of bool | LexInt of int | LexReal of float | LexString of string | LexName of string | LexLeftSquare | LexRightSquare | LexLeftDict | LexRightDict | LexStream of Pdf . stream | LexEndStream | LexObj | LexEndObj | LexR | LexComment | StopLexing | LexNone
let string_of_token = function | LexInt i -> " Int " ^ string_of_int i | LexReal f -> " Float " ^ string_of_float f | LexString s -> " String " ^ s | LexName s -> " Ident " ^ s | LexNull -> " Nothing " | _ -> " GenLexNone "
let string_of_tokens ts = fold_left ( fun a b -> a ^ " \ n " ^ b ) " " ( map string_of_token ts )
let is_delimiter = function | ' ( ' | ' ) ' | ' ' < | ' ' > | ' [ ' | ' ] ' | ' { ' | ' } ' | ' ' % | ' ' / -> true | _ -> false
let is_not_whitespace = function | ' \ 000 ' | ' \ 009 ' | ' \ 010 ' | ' \ 012 ' | ' ' | ' \ 013 ' -> false | _ -> true
let is_whitespace_or_delimiter = function | ' \ 000 ' | ' \ 009 ' | ' \ 010 ' | ' \ 012 ' | ' ' | ' \ 013 ' | ' ( ' | ' ) ' | ' ' < | ' ' > | ' [ ' | ' ] ' | ' { ' | ' } ' | ' ' % | ' ' / -> true | _ -> false
let string_copy s = Bytes . unsafe_to_string ( Bytes . copy ( Bytes . unsafe_of_string s ) )