Backslashes need to be escaped in strings in Postgres, which is non-standard and annoying, but which probably won't change since it dates 'way back into early Postgres history and there are probably too many people who use the feature to change it.
Perhaps the "DoubleApos" routine needs to escape backslashes just as it doubles apostrophes?