Last active
August 29, 2015 14:18
-
-
Save michaelfward/99280f293d1e7f9aa787 to your computer and use it in GitHub Desktop.
Load a file and write it into a string declaration in your language of choice
This file contains hidden or 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
#!/bin/usr/ruby | |
#reads a file and parses into a single string declaration in language of choice | |
#another little snippet to make my job easier when writing lots of code | |
#programmed by michael ward | |
# [email protected] | gists.github.com/michaelfward | |
# *************************************** | |
# example scrips | |
# with readfiles | |
# | writefiles [file with paths] [file to write*] | |
# | makestring [file to write* (actually is read, but same as above)] [lang] | |
#**************************************** | |
def readFile(path) | |
str = File.read(path).gsub("\n", '\n') | |
str = str.gsub('"', '\"') | |
str | |
end | |
def usage | |
puts "makestring [file to read] [language output]" | |
exit | |
end | |
langs = {"rb"=>"str =", "js" => "var str =", "c"=> "char str[] ="} | |
usage unless ARGV.length == 2 | |
lang = ARGV[1] | |
path = ARGV[0] | |
str = readFile(path) | |
if langs[lang] == nil | |
if lang == "c++" || lang == "cpp" || lang == "c#" | |
puts "#{lang[c]}\"#{str}\"" | |
else | |
puts "unrecognized language found. supported languages are" | |
langs.each_key {|k| puts " #{k}"} | |
exit | |
end | |
else | |
puts "#{langs[lang]}\" #{str}\"" | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment