开发者

Is there any library for Shift JIS encoding on Silverlight? [closed]

Closed. T开发者_开发知识库his question does not meet Stack Overflow guidelines. It is not currently accepting answers.

We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.

Closed 3 years ago.

Improve this question

Is there any library that can be used to decode Shift JIS text on Silverlight?


I was able to port Mono's implementation to .NET in less than an hour. This is the (minimal?) set of classes that needs to be ported (sorted by dependency):

  1. I18N.Common.Strings
  2. I18N.Common.MonoEncoding
  3. I18N.CJK.CodeTable
  4. I18N.CJK.DbcsConvert
  5. I18N.CJK.DbcsEncoding
  6. I18N.CJK.JISConvert
  7. I18N.CJK.CP932

Additionally, the following file needs to be copied (loaded in the constructor of I18N.CJK.CodeTable):

  • jis.table

The class that implements the "shift_jis" encoding is I18N.CJK.CP932. Note that it must be instantiated manually, not through Encoding.GetEncoding().


I found some info here:
http://www.eggheadcafe.com/community/aspnet/14/14621/covert-shiftjis-to-unicode.aspx

This is the sample C# code from the link above (credits to Peter Bromberg). I cannot say for sure that it will work in Silverlight. I suppose it all depends on whether Encoding.GetEncoding("shift-jis") is available in SL:

public class FileConverter
{
    const int BufferSize = 8096;

    public static void Main(string[] args)
    {
        if (args.Length != 2)
        {
            Console.WriteLine 
                ("Usage: FileConverter <input file> <output file>");
            return;
        }
        //NOTE: you may need to use " Encoding enc = Encoding.GetEncoding("shift-jis"); " for non-standard code pages
        // Open a TextReader for the appropriate file
        using (TextReader input = new StreamReader 
               (new FileStream (args[0], FileMode.Open),
                Encoding.UTF8))
        {
            // Open a TextWriter for the appropriate file
            using (TextWriter output = new StreamWriter 
                   (new FileStream (args[1], FileMode.Create),
                    Encoding.Unicode))
            {

                // Create the buffer
                char[] buffer = new char[BufferSize];
                int len;

                // Repeatedly copy data until we've finished
                while ( (len = input.Read (buffer, 0, BufferSize)) > 0)
                {
                    output.Write (buffer, 0, len);
                }
            }
        }
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜