[Mono-dev] Possible Bug in Mono?

Atsushi Eno atsushieno at veritas-vos-liberabit.com
Mon Sep 6 08:11:12 EDT 2010


  (In general, avoid using such ambiguous email subject; it makes 
searching relevant messages difficult.)

It correctly works for me. Make sure that you don't have your source 
encoding and compiler -codepage argument or default encoding 
mismatching. The default encoding is platform dependent.
You can avoid such a problem by avoiding non-ASCII characters in your 
source code. In this case, use "¥u0083" instead of raw POUND SIGN.

Atsushi Eno

(10/09/06 18:10), anidotnet wrote:
> 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
>



More information about the Mono-devel-list mailing list