Skip to content

Instantly share code, notes, and snippets.

@mattcolman
Created June 16, 2015 07:17
Show Gist options
  • Save mattcolman/186d18c1421d39d8194e to your computer and use it in GitHub Desktop.
Save mattcolman/186d18c1421d39d8194e to your computer and use it in GitHub Desktop.
fnt to coffee
<textarea name="input" id="input" placeholder="Input"></textarea>
<textarea name="output" id="output" placeholder="Output"></textarea>
<button>Convert</button>
$("button").on "click", ->
input = $("#input").val()
pattern = /\bchar id=(\d+)?\b/g
matches = input.match(pattern)
for match in matches
input = input.replace(match, match+'":')
input = input.replace(/char id=/g, '"')
input = input.replace(/=/g, ":")
pattern = /\b:(\d+)?\b/g
i = 0
while (match=pattern.exec(input))
if ++i > 10000
throw new Error("oh dear")
index = match.index + match[0].length
start = input.slice(0, index)
end = input.slice(index, input.length)
input = start + "," + end
input = input.replace(/chnl:0,/g, "chnl:0")
$("#output").val(input)
String.prototype.splice = (idx, rem, s ) ->
@slice(0,idx) + s + @slice(idx + Math.abs(rem))
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
textarea {
position: relative;
top: 40px;
border-radius: 4px;
width: 400px;
height: 180px;
margin: 0 auto;
}
form textarea {
border-radius: 2px;
box-shadow: 0px 2px 11px 0px rgba(0, 0, 0, 0.3);
border: 1px solid #e2e6e6;
margin: 10px 0 10px 0;
font-family: 'Open Sans', sans-serif;
outline: none;
width: 395px;
height: 100px;
font-size: 14px;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment