To evaluate principal value of $\int\limits_{-\infty}^{\infty} \frac{\cos z}{z-w} \ dz.$ 
Evaluate the principal value of the integral $$\int\limits_{-\infty}^{\infty} \frac{\cos z}{z-w} \ dz. \ \ \ \ \ |\text{Im} \ z|>0 $$

I could not solve this problem during tutorial class. Upon looking at the solution sheet that was uploaded the next day, I am still not clear about the method that is used to solve this. So the solution given is:
$$ \int\limits_{-\infty}^{\infty} \frac{\cos z}{z-w} \ dz = \begin{cases} 2\pi i \ \text{Res}_{z=w} \left(\frac{e^{iz}}{2(z-w)}\right) = \pi i e^{iw}, & \text{if} \ \text{Im} \ w >0 \\
-2\pi i \ \text{Res}_{z=w} \left(\frac{e^{-iz}}{2(z-w)}\right) = -\pi i e^{iw}, & \text{if} \ \text{Im} \ w <0 \end{cases}$$
The part which I don't understand is the beginning part of the solution where  they claim (without giving any reason) that $\int\limits_{-\infty}^{\infty} \frac{\cos z}{z-w} \ dz = \int\limits_{-\infty}^{\infty} \frac{e^{iz}}{z-w} \ dz$ $\text{if}$ $\text{Im} \ w>0$ and $\int\limits_{-\infty}^{\infty} \frac{\cos z}{z-w} \ dz = \int\limits_{-\infty}^{\infty} \frac{e^{-iz}}{z-w} \ dz$ if $\text{Im} \ w<0$. 
Evaluating the integrals with the exponential terms is clear to me. But what is the reasoning behind replacing the cosine with the exponential function? Need help understanding this.
 A: Using Euler's Formula, we can write
$$\int_{-\infty}^\infty \frac{\cos(z)}{z-w}\,dz=\int_{-\infty}^\infty \frac{e^{iz}}{z-w}\,dz+\int_{-\infty}^\infty \frac{e^{-iz}}{z-w}\,dz\tag 1$$

For $\text{Im}(w)>0$, the pole at $z=w$ is in the upper-half plane.  As a consequence, we assert that the second integral on the right-hand side of $(1)$ is zero. To see this more clearly, we proceed as follows.

Let $C_R$ be the contour comprised of the (i) real line segment from $-R$ to $R$ and (ii) the semicircular arc in the lower-half plane that has radius $R$ and is centered at $0$.  Since $\frac{e^{-iz}}{z-w}$ is analytic in and on $C_R$, Cauchy's Integral Theorem guarantees that 
$$\begin{align}
\oint_{C_R}\frac{e^{-iz}}{z-w}\,dz&=\int_{-R}^R \frac{e^{-iz}}{z-w}\,dz+\int_{2\pi}^\pi \frac{e^{-iRe^{i\phi}}}{Re^{i\phi}-w}\,iRe^{i\phi}\,d\phi\tag 2\\\\
&=0
\end{align}$$
As $R\to 0$, the second integral on the right-hand side of $(2)$ approaches zero.  Therefore, we arrive at the coveted result
$$\bbox[5px,border:2px solid #C0A000]{\int_{-\infty}^\infty \frac{e^{-iz}}{z-w}\,dz=0}$$
for $\text{Im}(w)>0$ as was to be shown!
The analysis for the case $\text{Im}(w)<0$ proceeds analogously and is left as an exercise for the reader.
