Skip to content

Instantly share code, notes, and snippets.

@kaja47
Created December 4, 2017 21:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kaja47/5252063daabdd19b69caac524d8b0e6c to your computer and use it in GitHub Desktop.
Save kaja47/5252063daabdd19b69caac524d8b0e6c to your computer and use it in GitHub Desktop.
def parseLine(l: String) = {
def march(l: String, pos: Int, ch: Char): Int = {
var i = pos; while (i < l.length) {
if (l.charAt(i) == ch) return i
i += 1
}
sys.error("")
}
def marchUntilStringEnds(l: String, pos: Int): Int = {
if (l.charAt(pos) != '"') return sys.error("")
var i = pos+1; while (i < l.length) {
if (l.charAt(i) == '"' && l.charAt(i-1) != '\\') return i+1
i += 1
}
sys.error("")
}
var pos, end = 0
end = march(l, pos, ' ')
val ip = l.substring(pos, end)
pos = end+1
end = march(l, pos, ' ')
pos = end+1
end = march(l, pos, ' ')
pos = end+1
end = march(l, pos, ']')
val date = l.substring(pos+1, end)
pos = end+2
end = marchUntilStringEnds(l, pos)
val req = l.substring(pos+1, end-1)
pos = end+1
end = march(l, pos, ' ')
val resp = l.substring(pos, end)
pos = end+1
end = march(l, pos, ' ')
val bytes = l.substring(pos, end)
pos = end+1
end = marchUntilStringEnds(l, pos)
val ref = l.substring(pos+1, end-1)
pos = end+1
end = marchUntilStringEnds(l, pos)
val ua = l.substring(pos+1, end-1)
pos = end+1
Array(ip, date, req, resp, bytes, ref, ua)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment