/* Awhile ago I posted a piece of code which preserves case when * replacing ala emacs. This code is a refinement of that idea. * The modification is to Lugaru code in search.e -[Shane]-> * * The idea is that if you query replace foo with bar and there is * a Foo, FOO, foo, you get Bar, BAR and bar. If either the replace * string or the target contains case shifts, the replacement is * verbatim (the same is true if case fold is 0). */ /* Add this routine */ casify (rep, old, with) char *rep; char *old; char *with; { int i; int replen = strlen (rep); int oldlen = strlen (old); int withlen = strlen (with); int len = oldlen < withlen ? oldlen : withlen; int all_upper = 1; for (i = 0; i < len; i++) { if (isupper (with[i]) || !case_fold || (i < replen && isupper(rep[i]))) { strcpy (old, with); return; } if (isupper (old[i])) old[i] = toupper (with[i]); else { all_upper = 0; old[i] = with[i]; } } for ( ; i < withlen; i++) { if (all_upper) old[i] = toupper (with[i]); else old[i] = with[i]; } old[i] = 0; } /* Changes in routine string_replace in search.e * This is just a fragment which exhibits all the changes required. * My search is so hacked I can't really post the whole thing * because it requires my entire environment. */ #if 0 do_replace: if (!skip) { if (flags & REGEX) fromorig(with); else { int olen = strlen (str); int nlen = strlen (with); char *old = malloc ((olen > nlen ? olen : nlen) + 1); grab (point - olen, point, old); delete (point - olen, point); casify (str, old, with); stuff (old); free (old); } } #endif