I was just looking through some old posts and I noticed that a "ß" in a question title magically turns into an "ss" in the URL slug.

What function is being used to format the slugs? Clearly it has some advanced behavior in terms of determining character equivalents, rather than just ignoring special characters.

(Note: I just tried this with "fi" and "fl" and they're not converted to "fi" and "fl"...)

share|improve this question
String url = post.Title.Replace("ß", "ss"); –  Time Traveling Bobby Mar 28 '12 at 20:45
+1 Oh.. I see what you did there :P (ß) –  Lix Mar 28 '12 at 20:45
he co҉mè̑ͧ̌s –  fredley Mar 28 '12 at 20:47
@fredley: Okay... String url = System.Text.RegularExpressions.RegEx.Replace(post.Title, "ß", "ss"); ... I might have those parameters reversed, though. –  Time Traveling Bobby Mar 28 '12 at 20:49
No way, unicode has ligatures? –  Ben Brocka Mar 28 '12 at 20:59
@BenBrocka - Unicode has the full complement of crazy pony stripes. –  cdeszaq Mar 28 '12 at 21:22
@BenBrocka whenever I think about about ligature, diacritical, or digraph support in Unicode it makes me go CYRILLIC CAPITAL LETTER UK –  Some Helpful Commenter Mar 28 '12 at 21:36
possible duplicate of Non US-ASCII characters dropped from full (profile) URL –  Cody Gray Apr 2 '12 at 1:25
add comment

1 Answer

up vote 11 down vote accepted

Assuming the current implementation is still similar (although Jeff mentions looking into another approach)...

Taking 80 characters from the raw title, , ,, ., /, \, and _ are replaced with -, collapsing consecutive such characters into a single dash. Latin alphabetic characters are converted to lowercase, and the following substitutions are made:

àåáâäãåą => a
èéêëę    => e
ìíîïı    => i
òóôõöø   => o
ùúûü     => u
çćč      => c
żźž      => z
śşš      => s
ñń       => n
ýŸ       => y
ł        => l
đ        => d
ß        => ss
ğ        => g
Þ        => th
ĥ        => h
ĵ        => j

Finally, if the above process resulted in the trailing dash, it is removed.

share|improve this answer
Only these particular substitutions? Is there not some library function which can de-adorn any Latin-ish character? –  jtbandes Mar 28 '12 at 21:11
Do you describe an observation, or do you know the actual algorithm? –  CodesInChaos Mar 28 '12 at 21:15
TIM STONE KNOWS ALL @CodeInChaos –  The Unhandled Exception Mar 28 '12 at 21:17
I would have used something like s.Normalize(NormalizationForm.FormD).Where(c=>CharUnicodeInfo.GetUnicodeCategor‌​y(c)!=UnicodeCategory.NonSpacingMark); to get rid of diacritics. Which would not have handles ß. –  CodesInChaos Mar 28 '12 at 21:17
See Jeff's answer in Non US-ASCII characters dropped from full (profile) URL, @jtbandes. –  Arjan Mar 28 '12 at 21:19
@Arjan Ah, that's more up-to-date than where I was pulling the list from, good stuff. –  Tim Stone Mar 28 '12 at 21:28
add comment

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .