using System;
using System.Text;
using System.Globalization;

/* Proof of concept for a function to safely strip accents from Latin text */
class ForeignStripper
{
	public static string strip (string s)
	{
		s = s.ToLower ();
		StringBuilder sb = new StringBuilder ();
		UnicodeCategory category;
		bool has_ascii = false;
		
		foreach (char c in s.Normalize (NormalizationForm.FormKD))
		{
			category = Char.GetUnicodeCategory (c);
			// Special case: considered the same as ö
			if (c == 'ø')
				sb.Append ('o');
			// Skip punctuation
			else if (category == UnicodeCategory.OtherPunctuation) {}
			else if(!(has_ascii && category == UnicodeCategory.NonSpacingMark))
				sb.Append (c);
			has_ascii = (c >= 'a' && c <= 'z');
		}
		return sb.ToString ().Normalize (NormalizationForm.FormKC);
	}
	
	public static void Main (string[] argv)
	{
		Console.WriteLine (strip (argv[0]));
	}
}
