0xDEADBEEF

RSS odkazy english edition

log parser

5. 12. 2017 #kód
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)
}
píše k47 (@kaja47, k47)