Foldy–Wouthuysen transformation applied to the interaction of an electron with ultrafast electromagnetic fields