text
stringlengths 0
601k
|
---|
let scan_int_list = scan_list scan_int_elem ; ; |
let test29 ( ) = scan_int_list ( Scanning . from_string " [ ] " ) = [ ] && scan_int_list ( Scanning . from_string " [ ] " ) = [ ] && scan_int_list ( Scanning . from_string " [ 1 ] " ) = [ 1 ] && scan_int_list ( Scanning . from_string " [ 1 ; 2 ; 3 ; 4 ] " ) = [ 1 ; 2 ; 3 ; 4 ] && scan_int_list ( Scanning . from_string " [ 1 ; 2 ; 3 ; 4 ; ] " ) = [ 1 ; 2 ; 3 ; 4 ] ; ; ; ; |
let scan_string_elem ib f ek = kscanf ib ek " % S % 1 [ ; ] " f ; ; |
let scan_string_list = scan_list scan_string_elem ; ; |
let test30 ( ) = scan_string_list ( Scanning . from_string " [ ] " ) = [ ] && scan_string_list ( Scanning . from_string " [ ] " ) = [ ] && scan_string_list ( Scanning . from_string " [ " \ 1 " \ ] " ) = [ " 1 " ] && scan_string_list ( Scanning . from_string " [ " \ 1 " ; \ " \ 2 " ; \ " \ 3 " ; \ " \ 4 " ] " ) \ = [ " 1 " ; " 2 " ; " 3 " ; " 4 " ] && scan_string_list ( Scanning . from_string " [ " \ 1 " ; \ " \ 2 " ; \ " \ 3 " ; \ " \ 4 " ; ] " ) \ = [ " 1 " ; " 2 " ; " 3 " ; " 4 " ] ; ; ; ; |
let scan_elem fmt ib f ek = kscanf ib ek fmt f ; ; |
let scan_int_list = scan_list ( scan_elem " % i % 1 [ ; ] " ) ; ; |
let scan_string_list = scan_list ( scan_elem " % S % 1 [ ; ] " ) ; ; |
let scan_bool_list = scan_list ( scan_elem " % B % 1 [ ; ] " ) ; ; |
let scan_char_list = scan_list ( scan_elem " % C % 1 [ ; ] " ) ; ; |
let scan_float_list = scan_list ( scan_elem " % f % 1 [ ; ] " ) ; ; |
let rec scan_elems ib scan_elem accu = scan_elem ib ( fun i -> let accu = i :: accu in kscanf ib ( fun ib exc -> accu ) " % 1 [ ; ] " ( fun s -> if s = " " then accu else scan_elems ib scan_elem accu ) ) ( fun ib exc -> accu ) ; ; |
let scan_list scan_elem ib = bscanf ib " [ " ( ) ; let accu = scan_elems ib scan_elem [ ] in bscanf ib " ] " ( ) ; List . rev accu ; ; |
let scan_int_list = scan_list ( scan_elem " % i " ) ; ; |
let scan_string_list = scan_list ( scan_elem " % S " ) ; ; |
let scan_bool_list = scan_list ( scan_elem " % B " ) ; ; |
let scan_char_list = scan_list ( scan_elem " % C " ) ; ; |
let scan_float_list = scan_list ( scan_elem " % f " ) ; ; |
let test31 ( ) = scan_int_list ( Scanning . from_string " [ ] " ) = [ ] && scan_int_list ( Scanning . from_string " [ ] " ) = [ ] && scan_int_list ( Scanning . from_string " [ 1 ] " ) = [ 1 ] && scan_int_list ( Scanning . from_string " [ 1 ; 2 ; 3 ; 4 ] " ) = [ 1 ; 2 ; 3 ; 4 ] && scan_int_list ( Scanning . from_string " [ 1 ; 2 ; 3 ; 4 ; ] " ) = [ 1 ; 2 ; 3 ; 4 ] ; ; ; ; |
let test32 ( ) = scan_string_list ( Scanning . from_string " [ ] " ) = [ ] && scan_string_list ( Scanning . from_string " [ ] " ) = [ ] && scan_string_list ( Scanning . from_string " [ " \ 1 " \ ] " ) = [ " 1 " ] && scan_string_list ( Scanning . from_string " [ " \ 1 " ; \ " \ 2 " ; \ " \ 3 " ; \ " \ 4 " ] " ) \ = [ " 1 " ; " 2 " ; " 3 " ; " 4 " ] && scan_string_list ( Scanning . from_string " [ " \ 1 " ; \ " \ 2 " ; \ " \ 3 " ; \ " \ 4 " ; ] " ) \ = [ " 1 " ; " 2 " ; " 3 " ; " 4 " ] ; ; ; ; |
let rec scan_elems ib scan_elem_fmt accu = kscanf ib ( fun ib exc -> accu ) scan_elem_fmt ( fun i -> let accu = i :: accu in bscanf ib " % 1 [ ; ] " ( function | " " -> accu | _ -> scan_elems ib scan_elem_fmt accu ) ) ; ; |
let scan_list scan_elem_fmt ib = bscanf ib " [ " ( ) ; let accu = scan_elems ib scan_elem_fmt [ ] in bscanf ib " ] " ( ) ; List . rev accu ; ; |
let scan_int_list = scan_list " % i " ; ; |
let scan_string_list = scan_list " % S " ; ; |
let scan_bool_list = scan_list " % B " ; ; |
let scan_char_list = scan_list " % C " ; ; |
let scan_float_list = scan_list " % f " ; ; |
let test33 ( ) = scan_int_list ( Scanning . from_string " [ ] " ) = [ ] && scan_int_list ( Scanning . from_string " [ ] " ) = [ ] && scan_int_list ( Scanning . from_string " [ 1 ] " ) = [ 1 ] && scan_int_list ( Scanning . from_string " [ 1 ; 2 ; 3 ; 4 ] " ) = [ 1 ; 2 ; 3 ; 4 ] && scan_int_list ( Scanning . from_string " [ 1 ; 2 ; 3 ; 4 ; ] " ) = [ 1 ; 2 ; 3 ; 4 ] ; ; ; ; |
let test34 ( ) = scan_string_list ( Scanning . from_string " [ ] " ) = [ ] && scan_string_list ( Scanning . from_string " [ ] " ) = [ ] && scan_string_list ( Scanning . from_string " [ " \ 1 " \ ] " ) = [ " 1 " ] && scan_string_list ( Scanning . from_string " [ " \ 1 " ; \ " \ 2 " ; \ " \ 3 " ; \ " \ 4 " ] " ) \ = [ " 1 " ; " 2 " ; " 3 " ; " 4 " ] && scan_string_list ( Scanning . from_string " [ " \ 1 " ; \ " \ 2 " ; \ " \ 3 " ; \ " \ 4 " ; ] " ) \ = [ " 1 " ; " 2 " ; " 3 " ; " 4 " ] ; ; ; ; |
let rec scan_elems scan_elem accu ib = kscanf ib ( fun ib exc -> accu ) " % r " ( function ib -> scan_elem ib ( function elem -> let accu = elem :: accu in bscanf ib " % 1 [ ; ] " ( function | " " -> accu | _ -> scan_elems scan_elem accu ib ) ) ) ( function l -> l ) ; ; |
let scan_list scan_elem ib = bscanf ib " [ " ( ) ; let accu = scan_elems scan_elem [ ] ib in bscanf ib " ] " ( ) ; List . rev accu ; ; kscanf ib ( fun ib exc -> accu ) " % r % 1 [ ; ] " ( scan_elem ( function elem -> elem :: accu ) ) ( fun accu s -> if s = " " then accu else scan_elems scan_elem accu ib ) ; ; |
let scan_list scan_elem ib = bscanf ib " [ % r ] " ( scan_elems scan_elem [ ] ) List . rev ; ; |
let make_scan_elem fmt f ib = Scanf . bscanf ib fmt f ; ; |
let list_scanner fmt = scan_list ( make_scan_elem fmt ) ; ; |
let scan_float = make_scan_elem " % f " ; ; ) * |
let scan_float ib = Scanf . bscanf ib " % f " ; ; |
let scan_float_list = scan_list scan_float ; ; |
let scan_int_list = scan_list ( fun ib -> Scanf . bscanf ib " % i " ) ; ; |
let scan_string_list = scan_list ( fun ib -> Scanf . bscanf ib " % S " ) ; ; |
let scan_bool_list = scan_list ( fun ib -> Scanf . bscanf ib " % B " ) ; ; |
let scan_char_list = scan_list ( fun ib -> Scanf . bscanf ib " % C " ) ; ; |
let scan_float_list_list = scan_list ( fun ib k -> k ( scan_list ( fun ib -> Scanf . bscanf ib " % f " ) ib ) ) ; ; |
let scan_float_list_list = scan_list ( fun ib k -> k ( scan_list scan_float ib ) ) ; ; |
let scan_float_list_list = scan_list ( fun ib k -> k ( scan_float_list ib ) ) ; ; |
let test340 ( ) = scan_float_list_list ( Scanning . from_string " [ [ 1 . 0 ] ; [ ] ; [ 2 . 0 ; 3 ; 5 . 0 ; 6 . ] ; ] " ) = [ [ 1 . ] ; [ ] ; [ 2 . ; 3 . ; 5 . ; 6 . ] ] ; ; |
let scan_list_list scan_elems ib = scan_list ( fun ib k -> k ( scan_elems ib ) ) ib ; ; |
let scan_float_list_list = scan_list_list scan_float_list ; ; |
let scan_float_item ib k = k ( scan_float ib ( fun x -> x ) ) ; ; |
let scan_float_list ib k = k ( scan_list scan_float_item ib ) ; ; |
let scan_float_list_list ib k = k ( scan_list scan_float_list ib ) ; ; |
let test35 ( ) = sscanf " " " % N " ( fun x -> x ) = 0 && sscanf " 456 " " % N " ( fun x -> x ) = 0 && sscanf " 456 " " % d % N " ( fun x y -> x , y ) = ( 456 , 1 ) && sscanf " " " % N % s % N " ( fun x s y -> x , s , y ) = ( 0 , " " , 1 ) ; ; ; ; |
let rec read_elems read_elem accu ib = kscanf ib ( fun ib exc -> accu ) " % r % 1 [ ; ] " ( read_elem ( function elem -> elem :: accu ) ) ( fun accu s -> if s = " " then accu else read_elems read_elem accu ib ) ; ; |
let read_list read_elem ib = bscanf ib " [ % r ] " ( read_elems read_elem [ ] ) List . rev ; ; |
let make_read_elem fmt f ib = Scanf . bscanf ib fmt f ; ; |
let scan_List fmt = read_list ( make_read_elem fmt ) ; ; |
let rec read_elems read_elem accu ib = kscanf ib ( fun ib exc -> accu ) " % r " ( read_elem ( function elem -> elem :: accu ) ) ( fun accu -> read_elems read_elem accu ib ) ; ; |
let read_list read_elem ib = List . rev ( read_elems read_elem [ ] ib ) ; ; |
let scan_list fmt = read_list ( make_read_elem fmt ) ; ; ) * |
let test36 ( ) = sscanf " " " % n " ( fun x -> x ) = 0 && sscanf " 456 " " % n " ( fun x -> x ) = 0 && sscanf " 456 " " % d % n " ( fun x y -> x , y ) = ( 456 , 3 ) && sscanf " " " % n % s % n " ( fun x s y -> x , s , y ) = ( 0 , " " , 0 ) ; ; ; ; |
let test37 ( ) = sscanf " " " " true && sscanf " " " " ( fun x -> x ) 1 = 1 && sscanf " 123 " " " ( fun x -> x ) 1 = 1 ; ; ; ; |
let test38 ( ) = sscanf " a " " a " %! true && sscanf " a " " a " %!%! true && sscanf " a " " a " %! true && sscanf " a " " a " %! true && sscanf " " " " %! true && sscanf " " " " %! true && sscanf " " " " %! true && sscanf " " " " %!%! true ; ; ; ; |
let test39 ( ) = let is_empty_buff ib = Scanning . beginning_of_input ib && Scanning . end_of_input ib in let ib = Scanning . from_string " " in is_empty_buff ib && is_empty_buff ib ; ; ; ; |
let test40 ( ) = let s = " cba " in let ib = Scanning . from_string s in bscanf ib " [ %^ ab ] % s " %! ( fun s1 s2 -> s1 = " c " && s2 = " ba " ) ; ; ; ; |
let test41 ( ) = let s = " cba " in let ib = Scanning . from_string s in bscanf ib " [ %^ abc ] [ % cba ] " %! ( fun s1 s2 -> s1 = " " && s2 = " cba " ) ; ; ; ; |
let test42 ( ) = let s = " defcbaaghi " in let ib = Scanning . from_string s in bscanf ib " [ %^ abc ] [ % abc ] % s " %! ( fun s1 s2 s3 -> s1 = " def " && s2 = " cbaa " && s3 = " ghi " ) && let ib = Scanning . from_string s in bscanf ib " % s @\ t " ( fun s -> s = " defcbaaghi " ) ; ; ; ; |
let test43 , test44 = let s = " " in let ib = Scanning . from_string s in ( fun ( ) -> bscanf ib " % i " %! ( fun i -> i ) ) , ( fun ( ) -> bscanf ib " %!% i " ( fun i -> i ) ) ; ; ; ; |
let test45 ( ) = let s = " 12 . 2 " in let ib = Scanning . from_string s in bscanf ib " [ % 0 - 9 ] . [ % 0 - 9 ] % s " %! ( fun s1 s2 s3 -> s1 = " 12 " && s2 = " 2 " && s3 = " " ) ; ; ; ; |
let test46 , test47 = ( fun ( ) -> Printf . sprintf " % i ( %% s ) . " % 1 " spells one , % s " " in english " ) , ( fun ( ) -> Printf . sprintf " % i { %% s } , % % s . " 1 " spells one % s " " in english " ) ; ; ; ; ; ; |
let test48 ( ) = let test_meta_read s fmt efmt = format_from_string s fmt = efmt in let s , fmt = " % i " , format_of_string " % i " in test_meta_read s fmt fmt && let s , fmt = " % i " , format_of_string " % d " in test_meta_read s fmt " % i " && sscanf " 12 " \% i " \ 89 " " % i { %% d } %% s " %! ( fun i f s -> i = 12 && f = " % i " && s = " 89 " ) && let k s = Scanf . sscanf s " ( %% f ) " % ( fun _fmt i -> i ) in k " " \ : % 1f " \: 987654321 " = 9 . 0 && k " " \ : % 2f " \: 987654321 " = 98 . 0 && k " " \ : % 3f " \: 9 . 87654321 " = 9 . 8 && k " " \ : % 4f " \: 9 . 87654321 " = 9 . 87 && let h s = Scanf . sscanf s " Read integers with ( %% i ) " % ( fun _fmt i -> i ) in h " Read integers with " \% 1d " \ 987654321 " = 9 && h " Read integers with " \% 2d " \ 987654321 " = 98 && h " Read integers with " \% 3u " \ 987654321 " = 987 && h " Read integers with " \% 4x " \ 987654321 " = 39030 && let i s = Scanf . sscanf s " with ( %% i % s ) " % ( fun _fmt amount currency -> amount , currency ) in i " with " \ : % d % s " \ : 21 euros " = ( 21 , " euros " ) && i " with " \ : % d % s " \ : 987654321 dollars " = ( 987654321 , " dollars " ) && i " with " \ : % u % s " \ : 54321 pounds " = ( 54321 , " pounds " ) && i " with " \ : % x % s " \ : 321 yens " = ( 801 , " yens " ) && let j s = Scanf . sscanf s " with ( %% i % _s % s ) " % ( fun _fmt amount currency -> amount , currency ) in j " with " \ : % 1d % _s % s " \ : 987654321 euros " = ( 9 , " euros " ) && j " with " \ : % 2d % _s % s " \ : 987654321 dollars " = ( 98 , " dollars " ) && j " with " \ : % 3u % _s % s " \ : 987654321 pounds " = ( 987 , " pounds " ) && j " with " \ : % 4x % _s % s " \ : 987654321 yens " = ( 39030 , " yens " ) ; ; ; ; |
let test49 ( ) = sscanf " as " " [ ] " %\\ ( fun s -> s = " " ) && sscanf " as " " [ ] %\\% s " ( fun s t -> s = " " && t = " as " ) && sscanf " as " " [ ] %\\% s " %! ( fun s t -> s = " " && t = " as " ) && sscanf " as " " [ % a . . z ] " ( fun s -> s = " a " ) && sscanf " as " " [ % a - z ] " ( fun s -> s = " as " ) && sscanf " as " " [ % a . . z ] % s " ( fun s t -> s = " a " && t = " s " ) && sscanf " as " " [ % a - z ] % s " ( fun s t -> s = " as " && t = " " ) && sscanf " - as " " [ %- a - z ] " ( fun s -> s = " - as " ) && sscanf " - as " " [ %- a - z ] @ s " ( fun s -> s = " - a " ) && sscanf " - as " " [ -% a ] @ s " ( fun s -> s = " a " ) && sscanf " - asb " " [ -% a ] @ sb " %! ( fun s -> s = " a " ) && sscanf " - asb " " [ -% a ] @ s % s " ( fun s t -> s = " a " && t = " b " ) ; ; ; ; |
let next_char ob ( ) = let s = Buffer . contents ob in let len = String . length s in if len = 0 then raise End_of_file else let c = s . [ 0 ] in Buffer . clear ob ; Buffer . add_string ob ( String . sub s 1 ( len - 1 ) ) ; c ; ; |
let send_string ob s = Buffer . add_string ob s ; Buffer . add_char ob ' \ n ' ; ; |
let send_int ob i = send_string ob ( Int . to_string i ) ; ; |
let rec reader = let count = ref 0 in ( fun ib ob -> if Scanf . Scanning . beginning_of_input ib then begin count := 0 ; send_string ob " start " ; writer ib ob end else Scanf . bscanf ib " [ %^\ n ] \ n " ( function | " stop " -> send_string ob " stop " ; writer ib ob | s -> let l = String . length s in count := l + ! count ; if ! count >= 100 then begin send_string ob " stop " ; send_int ob ! count end else send_int ob l ; writer ib ob ) ) Scanf . bscanf ib " % s \ n " ( function | " start " -> send_string ob " Hello World " ; ! reader ib ob | " stop " -> Scanf . bscanf ib " % i " ( function i -> i ) | s -> send_int ob ( int_of_string s ) ; reader ib ob ) ; ; |
let go ( ) = let ob = Buffer . create 17 in let ib = Scanf . Scanning . from_function ( next_char ob ) in reader ib ob ; ; |
let test50 ( ) = go ( ) = 100 ; ; ; ; |
let test51 ( ) = sscanf " Hello " " % s " id = " Hello " && sscanf " Hello \ n " " % s \ n " id = " Hello " && sscanf " Hello \ n " " % s % s \ n " ( fun s1 s2 -> s1 = " Hello " && s2 = " " ) && sscanf " Hello \ nWorld " " % s \ n % s " %! ( fun s1 s2 -> s1 = " Hello " && s2 = " World " ) && sscanf " Hello \ nWorld " ! " % s \ n % s " ( fun s1 s2 -> s1 = " Hello " && s2 = " World " ) ! && sscanf " Hello \ n " " % s @\ n % s " ( fun s1 s2 -> s1 = " Hello " && s2 = " " ) && sscanf " Hello \ n " " % s @\ n % s " ( fun s1 s2 -> s1 = " Hello " && s2 = " " ) ; ; ; ; |
let test52 ( ) = sscanf " Hello \ n " " % s @\ n " id = " Hello " && sscanf " Hello " " % s @\ n " id = " Hello " && sscanf " Hello " " % s % s @\ n " ( fun s1 s2 -> s1 = " Hello " && s2 = " " ) && sscanf " Hello \ nWorld " " % s @\ n % s " %! ( fun s1 s2 -> s1 = " Hello " && s2 = " World " ) && sscanf " Hello \ nWorld " ! " % s @\ n % s @\ n " ( fun s1 s2 -> s1 = " Hello " && s2 = " World " ) ! && sscanf " Hello \ n " " % s @\ n % s " ( fun s1 s2 -> s1 = " Hello " && s2 = " " ) && sscanf " Hello \ n " " % s % s @\ n " ( fun s1 s2 -> s1 = " Hello " && s2 = " " ) && s1 = " Hello " && s2 = " " ) && sscanf " Hello \ n " " % s % _1 [ ] % s \ n " ( fun s1 s2 -> s1 = " Hello " && s2 = " " ) && sscanf " Hello \ nWorld " " % s \ n % s " %! ( fun s1 s2 -> s1 = " Hello " && s2 = " World " ) && sscanf " Hello \ nWorld " ! " % s \ n % s " %! ( fun s1 s2 -> s1 = " Hello " && s2 = " World " ) ! && sscanf " Hello \ nWorld " ! " % s \ n % s " @!%! ( fun s1 s2 -> s1 = " Hello " && s2 = " World " ) && sscanf " Hello { foo } " " % s { @% s " ( fun s1 s2 -> s1 = " Hello " && s2 = " foo } " ) && sscanf " Hello [ foo ] " " % s [ @% s " ( fun s1 s2 -> s1 = " Hello " && s2 = " foo ] " ) ; ; ; ; |
let test53 ( ) = sscanf " 123 " " % nd " id = 123n && sscanf " 124 " " % nd " ( fun i -> Nativeint . pred i = 123n ) && sscanf " 123 " " % ld " id = 123l && sscanf " 124 " " % ld " ( fun i -> Int32 . succ i = 125l ) && sscanf " 123 " " % Ld " id = 123L && sscanf " 124 " " % Ld " ( fun i -> Int64 . pred i = 123L ) ; ; ; ; |
let create_tscanf_data ob lines = let add_line ( p , e ) = Buffer . add_string ob ( Printf . sprintf " % S " p ) ; Buffer . add_string ob " -> " ; Buffer . add_string ob ( Printf . sprintf " % S " e ) ; Buffer . add_string ob " ; \ n " in List . iter add_line lines ; ; |
let write_tscanf_data_file fname lines = let oc = open_out fname in let ob = Buffer . create 42 in create_tscanf_data ob lines ; Buffer . output_buffer oc ob ; close_out oc ; ; |
let tscanf_data_file_lines = [ " Objective " , " Caml " ; ] ; ; ; ; |
let get_lines fname = let ib = Scanf . Scanning . from_file fname in let l = ref [ ] in try while not ( Scanf . Scanning . end_of_input ib ) do Scanf . bscanf ib " % S -> % S ; " ( fun x y -> l := ( x , y ) :: ! l ) done ; List . rev ! l with | Scanf . Scan_failure s -> failwith ( Printf . sprintf " in file % s , % s " fname s ) | End_of_file -> failwith ( Printf . sprintf " in file % s , unexpected end of file " fname ) ; ; |
let test54 ( ) = get_lines tscanf_data_file = tscanf_data_file_lines ; ; ; ; |
let add_digest_ib ob ib = let digest s = String . uppercase_ascii ( Digest . to_hex ( Digest . string s ) ) in let scan_line ib f = Scanf . bscanf ib " [ %^\ n \ r ] \ n " f in let output_line_digest s = Buffer . add_string ob s ; Buffer . add_char ob ' ' ; # Buffer . add_string ob ( digest s ) ; Buffer . add_char ob ' \ n ' in try while true do scan_line ib output_line_digest done ; with | End_of_file -> ( ) ; ; |
let digest_file fname = let ib = Scanf . Scanning . from_file fname in let ob = Buffer . create 42 in add_digest_ib ob ib ; Buffer . contents ob ; ; |
let test55 ( ) = let ob = Buffer . create 42 in let ib = create_tscanf_data ob tscanf_data_file_lines ; let s = Buffer . contents ob in Buffer . clear ob ; Scanning . from_string s in let tscanf_data_file_lines_digest = add_digest_ib ob ib ; Buffer . contents ob in digest_file tscanf_data_file = tscanf_data_file_lines_digest ; ; ; ; |
let test56 ( ) = let g s = Scanf . sscanf s " % d % n " ( fun i n -> ( i , n ) ) in g " 99 " = ( 99 , 2 ) && g " 99 syntaxes all in a row " = ( 99 , 2 ) && g " - 20 degrees Celsius " = ( - 20 , 3 ) ; ; ; ; |
let test57 ( ) = let test_format_scan s fmt efmt = format_from_string s fmt = efmt in let s , fmt = " % i " , format_of_string " % i " in test_format_scan s fmt " % i " && let s , fmt = " % i " , format_of_string " % d " in test_format_scan s fmt " % i " && let s , fmt = " Read an int % i then a string % s . " , format_of_string " Spec % difi % scation " in test_format_scan s fmt " Read an int % i then a string % s . " && let s , fmt = " Read an int % i then a string " \% s " . " , \ format_of_string " Spec % difi % Scation " in test_format_scan s fmt " Read an int % i then a string " \% s " . " \ && let s , fmt = " Read an int % i then a string " \% s " . " , \ format_of_string " Spec % difi % scation " in test_format_scan s fmt " Read an int % i then a string " \% s " . " \ && sscanf " 12 " \% i " \ 89 " " % i { %% d } %% s " %! ( fun i f s -> i = 12 && f = " % i " && s = " 89 " ) ; ; ; ; |
let test58 ( ) = sscanf " string1 % string2 " " % s @%% s " id = " string1 " && sscanf " string1 % string2 " " % s @%%% s " ( ) ^ = " string1string2 " && sscanf " string1 @ string2 " " [ % a - z0 - 9 ] @% s " ( ) ^ = " string1string2 " && sscanf " string1 @% string2 " " [ % a - z0 - 9 ] %@%%% s " ( ) ^ = " string1string2 " ; ; ; ; |
let ( ) = test ( true ) ; ; |
let rec scan_fields ib scan_field accu = kscanf ib ( fun ib exc -> accu ) scan_field ( fun i -> let accu = i :: accu in kscanf ib ( fun ib exc -> accu ) " % 1 [ ; ] " ( fun s -> if s = " " then accu else scan_fields ib scan_field accu ) ) ; ; |
let scan_record scan_field ib = bscanf ib " { " ( ) ; let accu = scan_fields ib scan_field [ ] in bscanf ib " } " ( ) ; List . rev accu ; ; |
let scan_field ib = bscanf ib " % s = [ ; ] " %^ ( fun finame ficont -> finame , ficont ) ; ; ) * |
let test60 ( ) = sscanf " abc " " % 0c % 0c % c % n " ( fun c1 c2 c3 n -> c1 = ' a ' && c2 = ' a ' && c3 = ' a ' && n = 1 ) && sscanf " abc " " % 0s % s " ( fun s1 s2 -> s1 = " " && s2 = " abc " ) && sscanf " abc " " % 1s % s " ( fun s1 s2 -> s1 = " a " && s2 = " bc " ) ; ; ; ; |
let test61 ( ) = let test fmt = format_from_string ( string_of_format fmt ) fmt = fmt in test " % s /% a " && test " \\ " && test " \\ x " && test " \\ x25s " && test " " \\\% s " && test " " \\ ; ; ; ; |
let ic , oc = Unix . open_process worker ; ; |
let ib = Scanf . Scanning . from_channel ic ; ; |
let ob = Buffer . create 1024 ; ; |
let send_string_ping ob = send_string ob oc " Ping " ; ; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.