How Giacomo Casanova (1725-1798) wrote and edited his memoirs: what did he know and when did he know it?