g | x | w | all
Bytes Lang Time Link
110AWK250409T193707Zxrs
035Perl 6180327T173350Znwellnho
106Elixir180327T181403ZOkx
165Excel180328T100216ZWernisch
134Excel VBA180410T024836ZTaylor R
3634Pyth180330T151356ZRK.
154C# .NET Core180328T164328ZAnderson
098PowerShell Core180404T165635ZJeff Fre
079Unix180402T192614ZAli ISSA
155Clojure180329T184316ZBob Jarv
134C++ 14 g++180328T133616ZO.O.Bala
062APL Dyalog Classic180330T180227ZAdalynn
073Jelly180330T153705ZAdalynn
073APL Dyalog Classic180328T225917ZAdalynn
080Python 3180330T135423Zetene
104Python180328T095519Zdieter
094JavaScript180327T182804ZShaggy
049Ruby180327T193644ZReinstat
132PHP180329T172842ZChris Fo
059Pyth180328T185606Zhakr14
106Java 8180328T095613ZKevin Cr
045PHP180329T091542ZBerry M.
142Red180328T084757ZGalen Iv
027Jstx180329T041450ZQuantum6
039Perl 5 p180327T181627ZXcali
069Ruby180327T200342Zanna328p
068K4180327T202511Zmkst
087JavaScript Node.js180328T165522ZDanielIn
092Python 2180327T192734ZChas Bro
034vim180327T231440ZRay
114Python 3180327T201833ZDat
027V180327T171726Zuser4180
03005AB1E180328T092117ZEmigna
029Retina180327T213553ZMartin E
032V180327T181857ZEndenite
026Stax180327T184011Zrecursiv
038SOGL V0.12180327T170306Zdzaima
144Python180327T164405Ztouch my

AWK, 110 bytes

{for(;i++<NF;)s=s (i~1?toupper($i):tolower($i))
t=sub(/ey$/,X,s)?2:sub(/y$/,X,s)}$0=s (t~2?"e":X)"y Mc"s"face"

Attempt This Online!

{for(;i++<NF;)       # for each char
s=s                  # create/append to string
(i~1?toupper($i)     # 1st uppercase
:tolower($i))        # rest lower
t=sub(/ey$/,X,s)?2:  # delete ey or
sub(/y$/,X,s)}       # delete y
$0=s                 # set output to string
(t~2?"e":X)          # put e back if nec
"y Mc"s"face"        # add y and remainder

Perl 6, 42 37 35 bytes

{S/y$//~"y Mc{S/e?y$//}face"}o&tclc

Try it online!

Elixir, 112 110 107 106 bytes

now as short as java

fn x->x=String.capitalize x;"#{x<>if x=~~r/y$/,do: "",else: "y"} Mc#{String.replace x,~r/e?y$/,""}face"end

Try it online!

Explanation:

x=String.capitalize x

Gets x with the first character in uppercase and all others lowercase.

#{ code }

Evaluate the code and insert it into the string.

#{x<>if x=~ ~r/y$/, do: "", else: "y"}

Concatenates x with y if it does not end with y (ie it does not match the regex y$).

#{String.replace x, ~r/e?y$/, "")}

Removes trailing ey and trailing y.

Excel, 204 144 137 165 bytes

=SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(REPT(REPLACE(LOWER(A1),1,1,UPPER(LEFT(A1)))&"~",2),"~","y Mc",1),"yy ","y "),"ey~","~"),"y~","~"),"~","face")

From the inside outwards:

REPLACE(LOWER(A1),1,1,UPPER(LEFT(A1)))      Replaces PROPER to handle space-delimited cases
REPT(%&"~",2)                   Duplicate.                    Donkey~Donkey~
SUBSTITUTE(%,"~","y Mc",1)      Replace first ~.              Donkeyy McDonkey~
SUBSTITUTE(%,"yy ","y ")        Handle words ending in 'y'.   Donkey McDonkey~
SUBSTITUTE(%,"ey~","~")         Handle words ending in 'ey'   Donkey McDonk~
SUBSTITUTE(%,"y~","~")          Handle words ending in 'y'    Donkey McDonk~
SUBSTITUTE(%,"~","face")        Adding face.                  Donkey McDonkface

Old answer, creating all bits separately, and then concatenating (176 bytes). Does not handle space-delimited cases correctly.

=PROPER(A1)&IF(LOWER(RIGHT(A1,1))="y",,"y")&" Mc"&IF(LOWER(RIGHT(A1,2))="ey",LEFT(PROPER(A1),LEN(A1)-2),IF(LOWER(RIGHT(A1,1))="y",LEFT(PROPER(A1),LEN(A1)-1),PROPER(A1)))&"face"

Excel VBA, 134 bytes

An anonymous VBE Immediate Window Function that takes input from range [A1] and outputs to the Immediate Window.

b=[Left(Upper(A1))]+Mid([Lower(A1)],2):l=len(b):y=[Right(A1)="y"]:?b;IIf(y,"","y")" Mc"IIf(y,Left(b,l-1+(InStrRev(b,"e")=l-1)),b)"face

Pyth, 36 34 bytes

++Jrz4*\yqJK:J"e?y$"k+" Mc"+K"face

Try it online!

Explanation:

++Jrz4*\yqJK:J"(e)?y$"k+" Mc"+K"face

  Jrz4                                  Set J to the titlecase of z (input)
           K:J"e?y$"k                   Set K to (replace all matches of the regex e?y$ in J with k (empty string))
         qJ                             Compare if equal to J
      *\y                               Multiply by "y" (if True, aka if no matches, this gives "y", else it gives "")
 +                                      Concatenate (with J)
                             +K"face    Concatenate K with "face"
                       +" Mc"           Concatenate " Mc" with that
+                                       Concatenate

C# (.NET Core), 122 108 139 175 180 179 154 bytes

Thanks a lot, lee!

s=>((s.EndsWith("y")?s:s+"y")+" Mc"+(s+"$").Replace("ey$","")+"face").Replace(s,s.ToUpper()[0]+s.Substring(1).ToLower()).Replace("y$","").Replace("$","");

Try it online!

C# (.NET Core, with LINQ), 152 bytes

s=>((s.Last()=='y'?s:s+"y")+" Mc"+(s+"$").Replace("ey$","")+"face").Replace(s,s.ToUpper()[0]+s.Substring(1).ToLower()).Replace("y$","").Replace("$","");

Try it online!

PowerShell Core, 98 bytes

(("y$","e?(?=y)y$"|%{$o.ToUpper()[0]+$o.ToLower().Substring(1)-replace $_,""})-join "y Mc")+"face"

Try it online!

Many thanks to @Anderson Pimentel for inspiring a solution using regex replacements!

Unix (79 bytes)

Using Standard input :

 rev|sed -r 's/(.*)(.)$/\L\1\U\2/;s/^(ye?)?(.*)$/ecaF\2cM y\1\2/;s/ yy/ y/'|rev

test :

echo -e "Lady\nFace\nDonkey\nyyy"|rev|sed -r 's/(.*)(.)$/\L\1\U\2/;s/^(ye?)?(.*)$/ecaF\2cM y\1\2/;s/ yy/ y/'|rev
Lady McLadFace
Facey McFaceFace
Donkey McDonkFace
Yyy McYyFace

or ( by Function) :

F(){ echo $1|rev|sed -r 's/(.*)(.)$/\L\1\U\2/;s/^(ye?)?(.*)$/ecaF\2cM y\1\2/;s/ yy/ y/'|rev;}

test :

 F donkey
 Donkey McDonkFace

Clojure: 161 155

(use '[clojure.string :as s])
(defn f[t](s/join[(s/capitalize(cond(=(last t)\y)t :else(s/join[t "y"])))" Mc"(s/capitalize(s/replace t #"e*y$" ""))"face"]))

Ungolfed:

(defn facegen [s0]
  (let [ s1 (clojure.string/capitalize (cond
                                         (= (last s0) \y)  s0
                                         :else             (clojure.string/join [s0 "y"])))
         s2 (clojure.string/capitalize (clojure.string/replace s0 #"e*y$" ""))]
    (clojure.string/join [s1 " Mc" s2 "face"])))

Try it online!

C++ 14 (g++), 181 171 148 147 134 bytes

[](auto s){s[0]&=95;int i=1,b;for(;s[i];)s[i++]|=32;b=s[--i]-'y';return s+(b?"y":"")+" Mc"+(b?s:s.substr(0,s[i-1]-'e'?i:i-1))+"face";}

Note that clang will not compile this.

Credit goes to Kevin Cruijssen and Olivier Grégoire for the &95 trick.

Thanks to Chris for golfing 11 bytes.

Try it online here.

Ungolfed version:

[] (auto s) { // lambda taking an std::string as argument and returning an std::string
    s[0] &= 95; // convert the first character to upper case
    int i = 1, // for iterating over the string
    b; // we'll need this later
    for(; s[i] ;) // iterate over the rest of the string
        s[i++] |= 32; // converting it to lower case
    // i is now s.length()
    b = s[--i] - 'y'; // whether the last character is not a 'y'
    // i is now s.length()-1
    return s + (b ? "y" : "") // append 'y' if not already present
    + " Mc"
    + (b ? s : s.substr(0, s[i-1] - 'e' ? i : i-1)) // remove one, two, or zero chars from the end depending on b and whether the second to last character is 'e'
    + "face";
}

APL (Dyalog Classic), 62 bytes

{'face',⍨(' Mc','e?y$'⎕r''⊢S),⍨S,(Y≠⊃⌽S←⍵(819⌶¨)⍨1=⍳⍴⍵)/Y←'y'}

Try it online!

Thanks to @ngn for this solution!

Jelly, 77 75 74 73 bytes

2ḶNṫ@€⁼"“y“ey”S
ØA;"ØaF
¢y⁸µ¢Uyµ1¦
Çṫ0n”yẋ@”y;@Ç;“ Mc”
⁸JU>ÑTị3Ŀ;@Ç;“face

Try it online!

Any golfing suggestions are welcome (and wanted)!

APL (Dyalog Classic), 95 90 88 87 86 85 84 82 80 78 77 73 bytes

{'face',⍨(' Mc',S↓⍨-+/∧/¨Y'ey'=¨↑∘S¨-⍳2),⍨S,(Y≠⊃⌽S←⍵(819⌶¨)⍨1=⍳⍴⍵)/Y←'y'}

Try it online!

This could be golfed down some more, and any suggestions are welcome!

Python 3, 80 bytes

Long time avid reader, my first submission at last !

lambda y:re.sub("([\w ]+?)((e)?y)?$",r"\1\3y Mc\1face",y.capitalize())
import re

Try it online

Python, 105 104

import re;r=re.sub;c=str.capitalize;f=lambda s:r('([^e^y])$','\\1y',c(s))+' Mc'+r('ey$','',c(s))+'face'

thx @Berry M. from noticing my dyslexia

JavaScript, 103 96 94 bytes

Pretty naïve first pass at this.

s=>(g=r=>s[0].toUpperCase()+s.slice(1).toLowerCase().split(r)[0])(/y$/)+`y Mc${g(/e?y$/)}face`

Try it online

Ruby, 61 49 bytes

->s{s.capitalize=~/(e)?y$|$/;"#$`#$1y Mc#$`face"}

Try it online!

Saved 12 sweet bytes thanks to @MartinEnder:

PHP: 132

<?php function f($s){$s=ucfirst(strtolower($s));return $s.(substr($s,-1)=='y'?'':'y').' Mc'.preg_replace('/(ey|y)$/','',$s).'face';}

Explanation:

<?php

function f($s)
{
    // Take the string, make it all lowercase, then make the first character uppercase
    $s = ucfirst(strtolower($s));

    // Return the string, followed by a 'y' if not already at the end, then ' Mc'
    // and the string again (this time, removing 'y' or 'ey' at the end), then
    // finally tacking on 'face'.
    return $s
        . (substr($s, -1) == 'y' ? '' : 'y')
        . ' Mc'
        . preg_replace('/(ey|y)$/', '', $s)
        . 'face';
}

Pyth, 60 59 bytesSBCS

K"ey"Jrz4Iq>2JK=<2J=kK.?=k\yIqeJk=<1J))%." s÷   WZÞàQ"[JkJ

Test suite

They don't display here, but three bytes, \x9c, \x82, and \x8c are in the packed string between s and ÷. Rest assured, the link includes them.

Python 3 translation:
K="ey"
J=input().capitalize()
if J[-2:]==K:
    J=J[:-2]
    k=K
else:
    k="y"
    if J[-1]==k:
        J=J[:-1]
print("{}{} Mc{}face".format(J,k,J))

Java 8, 121 112 107 106 bytes

s->(s=(char)(s.charAt(0)&95)+s.toLowerCase().substring(1)).split("y$")[0]+"y Mc"+s.split("e?y$")[0]+"face"

-1 byte thanks to @OliverGrégoire.

Explanation:

Try it online.

s->                         // Method with String as both parameter and return-type
  (s=                       //  Replace and return the input with:
     (char)(s.charAt(0)&95) //   The first character of the input as Uppercase
     +s.toLowerCase().substring(1))
                            //   + the rest as lowercase
  .split("y$")[0]           //  Remove single trailing "y" (if present)
  +"y Mc"                   //  Appended with "y Mc"
  +s.split("e?y$")[0]       //  Appended with the modified input, with "y" or "ey" removed
  +"face"                   //  Appended with "face"

PHP, 45 46 bytes

<?=($s=ucfirst(fgets(STDIN)))."y Mc{$s}face";

Try it online!

Red, 143 142 bytes

func[s][s: lowercase s s/1: uppercase s/1
w: copy s if"y"<> last s[append w"y"]rejoin[w" Mc"parse s[collect keep to[opt["y"|"ey"]end]]"face"]]

Try it online!

Ungolfed:

f: func[s][
   s: lowercase s                      ; make the entire string lowercase
   s/1: uppercase s/1                  ; raise only its first symbol to uppercase 
   w: copy s                           ; save a copy of it to w
   if "y" <> last s[append w "y"]     ; append 'y' to w if it doesn't have one at its end
   rejoin[w                            ; assemble the result by joining:
          " Mc"
          ; keep the string until "y", "ey" or its end
          parse s[collect keep to [opt ["y" | "ey"] end]]
          "face"
    ]
]

Jstx, 27 bytes

h</►yT↓►y/◙♂ Mc♀/◄eyg►yg/íå

Explanation

      # Command line args are automatically loaded onto the stack
h     # Title case the top of the stack
<     # Duplicate the top value on the stack twice
/     # Print the top value on the stack
►y    # Load 'y' onto the stack
T     # Returns true if the 2nd element on the stack ends with the top
↓     # Execute block if the top of the stack is false
  ►y  # Load 'y' onto the stack
  /   # Print the top value on the stack
◙     # End the conditional block
♂ Mc♀ # Load ' Mc' onto the stack
/     # Print the top value on the stack
◄ey   # Load 'ey' onto the stack
g     # Delete the top of the stack from the end of the 2nd element on the stack if it exists
►y    # Load 'y' onto the stack
g     # Delete the top of the stack from the end of the 2nd element on the stack if it exists
/     # Print the top of the stack
íå    # Load 'face' onto the stack
      # Print with newline is implied as the program exits

Try it online!

Perl 5 -p, 47 39 bytes

Saved 6 bytes with @OlegV.Volkov's suggestions, 1 with @mwellnhof's, and 1 on my own

$_=lc^$";$_=s/y?$/y Mc/r.s/e?y$//r.face

Try it online!

Ruby, 69 bytes

->s{"#{(s.capitalize!||s)[-1]==?y?s:s+?y} Mc#{s.gsub /e?y$/,""}face"}

Explanation:

->s{                                                                } # lambda 
    "#{                                 } Mc#{                }face" # string interpolation
       (s.capitalize!||s) # returns string capitalized or nil, in that case just use the original string
                         [-1]==?y # if the last character == character literal for y
                                 ?s:s+?y # then s, else s + "y"
                                              s.gsub /e?y$/,"" # global substitute
                                                               # remove "ey" from end

Try it online!

K4, 74 69 68 bytes

Solution:

{$[r;x;x,"y"]," Mc",_[r:0&1-2/:"ye"=2#|x;x:@[_x;0;.q.upper]],"face"}

Examples:

q)k)f:{$[r;x;x,"y"]," Mc",_[r:0&1-2/:"ye"=2#|x;x:@[_x;0;.q.upper]],"face"}
q)f each ("boat";"Face";"DOG";"Family";"Lady";"Donkey";"Player")
"Boaty McBoatface"
"Facey McFaceface"
"Dogy McDogface"
"Family McFamilface"
"Lady McLadface"
"Donkey McDonkface"
"Playery McPlayerface"

Explanation:

Figure out if the last characters are equal to "ey", convert result to base-2 so we can ignore words that end "e?". Index into a list of numbers of characters to trim.

Managed to shave 5 bytes off my code to determine whether the last two chars at "ey" but struggling to better it...

{$[r;x;x,"y"]," Mc",_[r:0&1-2/:"ye"=2#|x;x:@[_x;0;.q.upper]],"face"} / the solution
{                                                                  } / lambda function
                                                            ,"face"  / join with "face"
                    _[                  ;                  ]         / cut function
                                           @[_x; ;        ]          / apply (@) to lowercased input
                                                0                    / at index 0
                                                  .q.upper           / uppercase function
                                         x:                          / save back into x
                                      |x                             / reverse x
                                    2#                               / take first two chars of x
                               "ye"=                                 / equal to "ye"?
                             2/:                                     / convert to base 2
                           1-                                        / subtract from 1
                         0&                                          / and with 0 (take min)
                       r:                                            / save as r
             ," Mc",                                                 / join with " Mc"
 $[r;x;x,"y"]                                                        / join with x (add "y" if required)

Bonus:

67 byte port in K (oK):

{$[r;x;x,"y"]," Mc",((r:0&1-2/"ye"=2#|x)_x:@[_x;0;`c$-32+]),"face"}

Try it online!

JavaScript (Node.js), 87 bytes

s=>(g=r=>Buffer(s.replace(r,"")).map((x,i)=>i?x|32:x&~32))(/y$/)+`y Mc${g(/e?y$/)}face`

Try it online!

Python 2, 88 92 bytes

lambda s:(s+'y'*-~-(s[-1]in'yY')).title()+' Mc'+re.sub('e?y$','',s.title())+'face'
import re

Try it online!

vim, 35 34 bytes

Vu~Yp:s/ey$
:%s/y$
kgJiy Mc<ESC>Aface<ESC>

<ESC> is 0x1b

Ungolfed

Vu~                      # Caseify McCaseface
Yp                       # dup line
:s/ey$ 
:%s/y$                   # Get the suffixes right
kgJiy Mc<ESC>Aface<ESC>  # Join lines and add the extra chars

Try it online!

Saved 1 byte thanks to DJMcMayhem

Python 3, 117 114 bytes

-3 bytes thanks to Dead Possum

def f(s):s=s.title();return s+'y'*(s[-1]!='y')+' Mc'+([s,s[:-1],0,s[:-2]][(s[-1]=='y')+((s[-2:]=='ey')*2)])+'face'

Try it online!

V, 27 28 30 bytes

Vu~Ùóe¿y$
Hóy$
ÁyJaMc<Esc>Aface

Try it online!

<Esc> represents 0x1b

The input is in the buffer. The program begins by converting everything to lowercase

V selects the line and u lowercases it

~ toggles the case of the first character (converting it to uppercase)

and Ù duplicates this line above, leaving the cursor at the bottom line

ó and replaces e¿y$, compressed form of e\?y$ (optional e and a y at the end of the line), with nothing (happens on the second line)

H goes to the first line

ó replaces y$ (y at the end of the line) with nothing on the first line

Á appends a y to the end of the first line

J and joins the last line with the first with a space in the middle, and the cursor is moved to this space

a appends Mc (<Esc> returns to normal mode)

A finally, appends face at the end of the line

05AB1E, 30 bytes

™D'y©Ü®«s¤®Qi¨¤'eQi¨]’McÿŠÑ’ðý

Try it online! or as a Test suite

Retina, 29 bytes

.+
$T
0`(e)?y$|$
$1y Mc$`face

Try it online!

V, 38 36 32 bytes

-5 byte thanks to @Cows quack

Vu~hy$ó[^y]$/&y
A Mc<esc>póe¿y$
Aface

<esc> is a literal escape character and [^ is encoded as \x84

Try it online!

Stax, 26 bytes

ëO╛εh╕⌠î&!}∞┌C^U╟«äδ◙Bg⌠└¿

Run and debug it

^           convert input to upper case                     "FACE"
B~          chop first character and push it back to input  70 "ACE"
v+          lowercase and concatenate                       "Face"
c'yb        copy, push "y", then copy both                  "Face" "Face" "y" "Face" "y"
:]          string ends with?                               "Face" "Face" "y" 0
T           trim this many character                        "Face" "Face" "y"
+           concatenate                                     "Face" "Facey"
p           output with no newline                          "Face"
"e?y$"z     push some strings                               "Face" "e?y$" ""
" Mc`Rface  execute string template; `R means regex replace " Mc Faceface"
            result is printed because string is unterminated

Run this one

SOGL V0.12, 38 bytes

lW y≠F
u⁽³:F y*+pF‽j:lW e=⌡j}"‰θ`√►׀‘p

Try it Here!

Python, 144 bytes

def f(s):
 s=s[0].upper()+s[1:].lower()
 y=lambda s:s[:-1]if s[-1]=='y'else s
 t=y(s)
 u=s[:-2]if s[-2:]=='ey'else y(s)
 return t+'y Mc%sface'%u

Try it online here