0
\$\begingroup\$

Introduction

As you all know, German has umlauts. They're these things: ¨

However, most keyboards don't have an umlaut key. That's fine, though, because you can write ö, ä, and ü as oe, ae, and ue.

Challenge

  • Your job is to to replace ö, ä, and ü with oe, ae, and ue (and likewise for their capital versions).
  • You have to deal with both the combining diacritical mark and single characters. (Thank you @ETHProductions for pointing this out.)
  • Capitalization of the base letter stays intact.
  • Capitalization of the e depends on the capitalization of the surrounding letters after replacement. You should write it as e unless it's adjacent to a capital letter on both sides, in which case write it as E. (End of line and space are not capital letters.)
  • Standard loopholes and I/O rules apply.
  • This is code-golf, so shortest code in UTF-8 bytes wins!

Example Input and Output

Test cases using precomposed characters

ü = ue
üb = ueb
üB = ueB
Ü = Ue
Üb = Ueb
ÜB = UEB

Test cases using combining diacritics

ö = oe
öb = oeb
öB = oeB
Ö = Oe
Öb = Oeb
ÖB = OEB
\$\endgroup\$
6
  • 1
    \$\begingroup\$ Inverse. \$\endgroup\$
    – Adám
    Nov 29, 2017 at 0:44
  • 1
    \$\begingroup\$ I feel like this is highly related. Seems to be kinda sorta the opposite challenge. \$\endgroup\$ Nov 29, 2017 at 2:41
  • 1
    \$\begingroup\$ Related \$\endgroup\$
    – Shaggy
    Nov 29, 2017 at 11:13
  • \$\begingroup\$ That one reminded me of geekandpoke.typepad.com/geekandpoke/2011/08/… ;-) \$\endgroup\$
    – Marco13
    Jul 20, 2019 at 22:38
  • \$\begingroup\$ I don't understand if the challenge is about replacing a single word or entire text blocks, ie whether to deal with word separation. \$\endgroup\$
    – Ingo Bürk
    Jul 21, 2019 at 14:53

2 Answers 2

2
\$\begingroup\$

QuadR, 112 bytes

[öäüÖÄÜ].?
.̈.?
1(819⌶⍣(2=+/M≠819⌶M))(∊'oauOAU'M)['öäüÖÄÜ'⍳⊃M]'e',⍵p↓1↓M←⍵M

Try it online!

Replace…

[öäüÖÄÜ].? any umlaut'ed character, optionally followed by a character

… or…

.̈.? any character and a combining umlaut, optionally followed by a character

… with the result of the following function:

⍵M the Match
M← store in M
1↓ drop one character from the left
⍵p↓ drop one character if match had combing umlaut (⍵p is 0-indexed pattern number)
 …'e', prepend the following character and an e:
  ()[] index using:
   ⊃M the first character of the Match
   'öäüÖÄÜ'⍳ …'s index in the list of umlaut'ed characters
  … into:
   'oauOAU'M the two-element list of the de-umlaut'ed characters and the Match
   enlisted (flattened)
1() apply the following derived function with 1 as left argument:
  819⌶⍣() casefold (to uppercase, because left argument would be 1) if:
   819⌶M the lowercased Match
   M≠ Boolean where the Match differs from that (i.e. is uppercase)
   +/ sum that
   2= 2 is equal to that

Equivalent to the tacit Dyalog APL function:

'[öäüÖÄÜ].?' '.̈.?'⎕R{1(819⌶⍣(2=+/M≠819⌶M))(∊'oauOAU'M)['öäüÖÄÜ'⍳⊃M]'e',⍵.PatternNum↓1↓M←⍵.Match}
\$\endgroup\$
0
0
\$\begingroup\$

Perl 5 (-pC -MUnicode::Normalize -Mutf8 -MList::Util=max), 63, 58, 53 bytes

$_=NFD$_;s/([oau])\K̈(?=(.?))/max($1,$2)lt a?E:e/gei

try it online

\$\endgroup\$
1
  • \$\begingroup\$ saved bytes using -Mutf8 and chaging \x{308} by unicode character \$\endgroup\$ Jul 18, 2019 at 8:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.