Created
December 4, 2017 21:37
-
-
Save kaja47/5252063daabdd19b69caac524d8b0e6c to your computer and use it in GitHub Desktop.
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
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