Created
September 27, 2011 23:23
-
-
Save mjambon/1246539 to your computer and use it in GitHub Desktop.
Embed the contents of a file into an OCaml program.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let quote ic = | |
let buf = Buffer.create 1000 in | |
Buffer.add_string buf "\ | |
let contents = | |
\""; | |
try | |
while true do | |
Buffer.add_string buf (String.escaped (input_line ic)); | |
Buffer.add_char buf '\n'; | |
done; | |
assert false | |
with End_of_file -> | |
Buffer.add_char buf '"'; | |
print_endline (Buffer.contents buf) | |
let () = quote stdin |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment