Review of the Structural Stability, Electronic and Magnetic Properties of Nonmetal-Doped TiO$_2$ from First-Principles Calculations