So some years ago in school I became friends with this guy who was genuinely just a good friend and a cool guy who liked things that I did.
But now, he just swears a lot, makes jokes that I think are really gross and crude (ex r*pe), and is generally just mean, even making fun of me at times for decisions he supported me on, saying "Haha, you thought __ was funny"(even though he had thought it was funny too) or "haha, you dated ___ person" (and not in a teasing way, in front of other people in an absolutely rude way). He's even gone so far to make fun of me and call me a pedo essentially, which was bad enough from other people bullying me, but my friend?? But the other half of the time he's fine, and we hang out and he's not rude, or like that.
It's really hard because I enjoy hanging out with him, but sometimes he's just mean and then I just want to get away from him. Plus even if I tried to stop being friends, he's in multiple of my classes.
Overall he's just a person I don't want to be around anymore, who does things I don't support, and therefore I really can't be friends with him.
So how can I tell him I don't want to be friends anymore, and how can I avoid him?