Move find_prefix function from database.cc to message.cc