Wir hassen Umlaute! (We hate umlauts!)

0

1

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

SuperNerd

Posted 2017-11-29T00:18:16.747

Reputation: 61

1Inverse. – Adám – 2017-11-29T00:44:59.393

1

I feel like this is highly related. Seems to be kinda sorta the opposite challenge.

– Carcigenicate – 2017-11-29T02:41:05.783

1Related – Shaggy – 2017-11-29T11:13:05.753

That one reminded me of https://geekandpoke.typepad.com/geekandpoke/2011/08/coders-love-unicode.html ;-)

– Marco13 – 2019-07-20T22:38:22.643

I don't understand if the challenge is about replacing a single word or entire text blocks, ie whether to deal with word separation. – Ingo Bürk – 2019-07-21T14:53:53.150

Answers

0

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

Nahuel Fouilleul

Posted 2017-11-29T00:18:16.747

Reputation: 5 582

saved bytes using -Mutf8 and chaging \x{308} by unicode character – Nahuel Fouilleul – 2019-07-18T08:16:55.320

2

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}

Adám

Posted 2017-11-29T00:18:16.747

Reputation: 37 779