All pastes #147429 Raw Edit

Anonymous

public text v1 · immutable
#147429 ·published 2006-08-24 11:14 UTC
rendered paste body
using System;
using System.Text;

public class Test
{
	public static void Main ()
	{
		byte [] bytes = new byte [256];
		for (int i = 1; i < 0x100; i++)
			bytes [i] = (byte) i;
		DecoderFallback fb = new DecoderReplacementFallback ("");

		for (int i = 1; i < 0x10000; i++) {
			Encoding e = null;
			try {
				e = Encoding.GetEncoding (i, EncoderFallback.ReplacementFallback, fb);
			} catch {
				continue;
			}

			foreach (NormalizationForm f in Enum.GetValues (typeof (NormalizationForm))) {
				if (f != NormalizationForm.FormC) {
					if (e.IsAlwaysNormalized (f))
						Console.WriteLine ("{0}({1}) {2}", e.CodePage, e.EncodingName, f);
					continue;
				}
				if (!e.IsSingleByte) {
					if (e.IsAlwaysNormalized (f))
						Console.WriteLine ("MultiByte: {0}", e.IsAlwaysNormalized (f));
					continue;
				}
//				if (!e.IsAlwaysNormalized (f))
//					Console.WriteLine ("NO: {0}({1}) {2}", e.CodePage, e.EncodingName, f);
				if (e.IsAlwaysNormalized (f))
					Console.WriteLine ("YES: {0}({1}) {2}", e.CodePage, e.EncodingName, f);
				string s = e.GetString (bytes);
				bool diff = (s.Normalize (f) != s);
				if (diff && e.IsAlwaysNormalized (f))
					Console.WriteLine ("DIFF: {0}({1}) {2} {3} {4}", e.CodePage, e.EncodingName, f, !diff, e.IsAlwaysNormalized (f));
				if (!diff && !e.IsAlwaysNormalized (f))
					Console.WriteLine ("SAME: {0}({1}) {2} {3} {4}", e.CodePage, e.EncodingName, f, !diff, e.IsAlwaysNormalized (f));
			}
		}
	}
}