[Mono-dev] Possible Bug in Mono?

anidotnet anidotnet at gmail.com
Mon Sep 6 05:10:32 EDT 2010


I have the following functions to get the Unicode representation of a string

-------------------------------------------------------------------------
public static string ToUnicode(this string strA)
{
      var writer = new StringWriter();
      try
      {
           foreach (char c in strA)
           {
                char h1 = IntToHex((c >> 12) & '\x000f');
                char h2 = IntToHex((c >> 8) & '\x000f');
                char h3 = IntToHex((c >> 4) & '\x000f');
                char h4 = IntToHex(c & '\x000f');

                writer.Write('\\');
                writer.Write('u');
                writer.Write(h1);
                writer.Write(h2);

                writer.Write(h3);
                writer.Write(h4);
           }

           string str = writer.ToString();
           writer.Dispose();
           return str;
     }
     catch (Exception)
     {
           writer.Dispose();
           throw;
     }
}

private static char IntToHex(int n)
{
     if (n <= 9)
     {
          return (char) (n + 48);
     }
     return (char) ((n - 10) + 97);
}

----------------------------------------------------------------

While unit testing the above code from Nunit

for .Net framework 3.5 I got

Assert.AreEqual("£".ToUnicode(), @"\u00a3");

working, but in Mono it is failing. It says

Expected: "\\ufffd", But was:  "\\u00a3"

Why Mono is giving different result than .Net for a same piece of code? Is
it a bug or am I missing something?


--------------------

Regards,
Anindya Chatterjee
http://abstractclass.org

-- 
View this message in context: http://mono.1490590.n4.nabble.com/Possible-Bug-in-Mono-tp2528103p2528103.html
Sent from the Mono - Dev mailing list archive at Nabble.com.


More information about the Mono-devel-list mailing list