There isn't any "rule" way to do this. For example, some people prefer
MacArthur and some prefer Macarthur, so you'd need to go back to the sources
to figure out the proper presentation.
Having said that, your substitution does indeed make O'REILY into O'Reily. Is
that what you want, or not?