Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.