GetCharCount() приватный Метод

private GetCharCount ( byte bytes, int count ) : int
bytes byte
count int
Результат int
 private void DoPosTest(ASCIIEncoding ascii, byte[] bytes, int index, int count)
 {
     int actualValue;
     ascii = new ASCIIEncoding();
     actualValue = ascii.GetCharCount(bytes, index, count);
     Assert.Equal(count, actualValue);
 }
Пример #2
0
        /// <summary>
        /// Turn Base64 encoded text into ASCII.
        /// </summary>
        private string base64ToASCII(string text)
        {
            byte[] todecode_byte        = Convert.FromBase64String(text);
            System.Text.Decoder decoder = new System.Text.ASCIIEncoding().GetDecoder();

            int charCount = decoder.GetCharCount(todecode_byte, 0, todecode_byte.Length);

            char[] decoded_char = new char[charCount];
            decoder.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0);

            return(new String(decoded_char));
        }
 static public int GetCharCount__A_Byte(IntPtr l)
 {
     try {
         System.Text.ASCIIEncoding self = (System.Text.ASCIIEncoding)checkSelf(l);
         System.Byte[]             a1;
         checkArray(l, 2, out a1);
         var ret = self.GetCharCount(a1);
         pushValue(l, true);
         pushValue(l, ret);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Пример #4
0
        /// <summary>
        /// Turn Base64 encoded text into ASCII.
        /// </summary>        
        private string base64ToASCII(string text)
        {
            byte[] todecode_byte = Convert.FromBase64String(text);
            System.Text.Decoder decoder = new System.Text.ASCIIEncoding().GetDecoder();

            int charCount = decoder.GetCharCount(todecode_byte, 0, todecode_byte.Length);
            char[] decoded_char = new char[charCount];
            decoder.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0);

            return new String(decoded_char);
        }
Пример #5
0
        static public Property Parse(XmlNode firstProperty)
        {
            Property rootProperty = new Property();

            rootProperty.Name     = firstProperty.Attributes["name"].Value;
            rootProperty.FullName = firstProperty.Attributes["fullname"].Value;

            string propType = firstProperty.Attributes["type"].Value;

            if (propType != "array" && propType != "object")
            {
                if (firstProperty.Attributes["encoding"] != null)
                {
                    if (firstProperty.Attributes["encoding"].Value == "base64")
                    {
                        byte[] todecode_byte        = Convert.FromBase64String(firstProperty.InnerText);
                        System.Text.Decoder decoder = new System.Text.ASCIIEncoding().GetDecoder();

                        int    charCount    = decoder.GetCharCount(todecode_byte, 0, todecode_byte.Length);
                        char[] decoded_char = new char[charCount];
                        decoder.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0);
                        string result = new String(decoded_char);

                        rootProperty.Value = result;
                    }
                }
                else
                {
                    rootProperty.Value = firstProperty.InnerText;
                }

                rootProperty.isComplete = true;
                rootProperty.Type       = PropertyType.Scalar;

                return(rootProperty);
            }
            else
            {
                rootProperty.isComplete = false;
                rootProperty.Type       = (propType == "array") ? PropertyType.Array : PropertyType.Object;

                if (propType == "array")
                {
                    rootProperty.Value = "Array (" + firstProperty.Attributes["numchildren"].Value + ")";
                }
                else
                {
                    rootProperty.Value = "Instance of " + firstProperty.Attributes["classname"].Value;
                }

                if (firstProperty.Attributes["children"].Value == "0")
                {
                    rootProperty.isComplete = true;
                }
                else
                {
                    int numChildren = Convert.ToInt32(firstProperty.Attributes["numchildren"].Value);
                    rootProperty.isComplete = numChildren == firstProperty.ChildNodes.Count;

                    foreach (XmlNode node in firstProperty.ChildNodes)
                    {
                        rootProperty.ChildProperties.Add(Property.Parse(node));
                    }
                }
            }


            return(rootProperty);
        }
Пример #6
0
            /// <summary>Initializes the MPI environment.</summary>
        /// <param name="args">
        ///   Arguments passed to the <c>Main</c> function in your program. MPI 
        ///   may use some of these arguments for its initialization, and will remove 
        ///   them from this argument before returning.
        /// </param>
        /// <param name="threading">
        ///   The level of threading support requested of the MPI implementation. The
        ///   implementation will attempt to provide this level of threading support.
        ///   However, the actual level of threading support provided will be published
        ///   via the <see cref="MPI.Environment.Threading"/> property.
        /// </param>
        /// <remarks>
        ///   This routine must be invoked before using any other MPI facilities. 
        ///   Be sure to call <c>Dispose()</c> to finalize the MPI environment before exiting!
        /// </remarks>
        /// <example>This simple program initializes MPI and writes out the rank of each processor:
        /// <code>
        /// using MPI;
        /// 
        /// public class Hello 
        /// {
        ///     static void Main(string[] args)
        ///     {
        ///         using (MPI.Environment env = new MPI.Environment(ref args))
        ///         {
        ///             System.Console.WriteLine("Hello, from process number " 
        ///                 + MPI.Communicator.world.Rank.ToString() + " of "
        ///                 + MPI.Communicator.world.Size.ToString());
        ///         }
        ///     }
        /// }
        /// </code>
        /// </example>
        public Environment(ref string[] args, Threading threading)
        {
            if (!Initialized)
            {
                int requiredThreadLevel = 0;
                int providedThreadLevel;

                switch (threading)
                {
                    case Threading.Single:
                        requiredThreadLevel = Unsafe.MPI_THREAD_SINGLE;
                        break;
                    case Threading.Funneled:
                        requiredThreadLevel = Unsafe.MPI_THREAD_FUNNELED;
                        break;
                    case Threading.Serialized:
                        requiredThreadLevel = Unsafe.MPI_THREAD_SERIALIZED;
                        break;
                    case Threading.Multiple:
                        requiredThreadLevel = Unsafe.MPI_THREAD_MULTIPLE;
                        break;
                }

                if (args == null)
                {
                    unsafe
                    {
                        int argc = 0;
                        byte** argv = null;
                        Unsafe.MPI_Init_thread(ref argc, ref argv, requiredThreadLevel, out providedThreadLevel);
                    }
                }
                else
                {
                    ASCIIEncoding ascii = new ASCIIEncoding();
                    unsafe
                    {
                        // Copy args into C-style argc/argv
                        int my_argc = args.Length;
                        byte** my_argv = stackalloc byte*[my_argc];
                        for (int argidx = 0; argidx < my_argc; ++argidx)
                        {
                            // Copy argument into a byte array (C-style characters)
                            char[] arg = args[argidx].ToCharArray();
                            fixed (char* argp = arg)
                            {
                                int length = ascii.GetByteCount(arg);
                                byte* c_arg = stackalloc byte[length];
                                if (length > 0)
                                {
                                    ascii.GetBytes(argp, arg.Length, c_arg, length);
                                }
                                my_argv[argidx] = c_arg;
                            }
                        }

                        // Initialize MPI
                        int mpi_argc = my_argc;
                        byte** mpi_argv = my_argv;
                        Unsafe.MPI_Init_thread(ref mpi_argc, ref mpi_argv, requiredThreadLevel, out providedThreadLevel);

                        // \todo Copy c-style argc/argv back into args
                        if (mpi_argc != my_argc || mpi_argv != my_argv)
                        {
                            args = new string[mpi_argc];
                            for (int argidx = 0; argidx < args.Length; ++argidx)
                            {
                                // Find the end of the string
                                int byteCount = 0;
                                while (mpi_argv[argidx][byteCount] != 0)
                                    ++byteCount;

                                // Determine how many Unicode characters we need
                                int charCount = ascii.GetCharCount(mpi_argv[argidx], byteCount);

                                // Convert ASCII characters into unicode characters
                                char[] chars = new char[charCount];
                                fixed (char* argp = chars)
                                {
                                    ascii.GetChars(mpi_argv[argidx], byteCount, argp, charCount);
                                }

                                // Create the resulting string
                                args[argidx] = new string(chars);
                            }
                        }
                    }
                }

                switch (providedThreadLevel)
                {
                    case Unsafe.MPI_THREAD_SINGLE:
                        Environment.providedThreadLevel = Threading.Single;
                        break;
                    case Unsafe.MPI_THREAD_FUNNELED:
                        Environment.providedThreadLevel = Threading.Funneled;
                        break;
                    case Unsafe.MPI_THREAD_SERIALIZED:
                        Environment.providedThreadLevel = Threading.Serialized;
                        break;
                    case Unsafe.MPI_THREAD_MULTIPLE:
                        Environment.providedThreadLevel = Threading.Multiple;
                        break;
                    default:
                        throw new ApplicationException("MPI.NET: Underlying MPI library returned incorrect value for thread level");
                }

                // Setup communicators
                Communicator.world = Intracommunicator.Adopt(Unsafe.MPI_COMM_WORLD);
                Communicator.self = Intracommunicator.Adopt(Unsafe.MPI_COMM_SELF);
            }
        }
 private void DoNegAOORTest(ASCIIEncoding ascii, byte[] bytes, int index, int count)
 {
     Assert.Throws<ArgumentOutOfRangeException>(() =>
     {
         ascii.GetCharCount(bytes, index, count);
     });
 }
 public void NegTest5()
 {
     ASCIIEncoding ascii = new ASCIIEncoding();
     byte[] bytes = null;
     Assert.Throws<ArgumentNullException>(() =>
    {
        ascii.GetCharCount(bytes, 0, 0);
    });
 }
Пример #9
0
        public static Property Parse(XmlNode firstProperty, string context)
        {
            Property rootProperty = new Property();
            rootProperty.Context = context;

            rootProperty.Name = firstProperty.Attributes["name"].Value;
            rootProperty.FullName = firstProperty.Attributes["fullname"].Value;

            string propType = firstProperty.Attributes["type"].Value;

            if (propType != "array" && propType != "object")
            {
                if (firstProperty.Attributes["encoding"] != null)
                {
                    if (firstProperty.Attributes["encoding"].Value == "base64")
                    {
                        byte[] todecode_byte = Convert.FromBase64String(firstProperty.InnerText);
                        System.Text.Decoder decoder = new System.Text.ASCIIEncoding().GetDecoder();

                        int charCount = decoder.GetCharCount(todecode_byte, 0, todecode_byte.Length);
                        char[] decoded_char = new char[charCount];
                        decoder.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0);
                        string result = new String(decoded_char);

                        rootProperty.Value = result;
                    }
                }
                else
                {
                    rootProperty.Value = firstProperty.InnerText;
                }

                rootProperty.isComplete = true;
                rootProperty.Type = PropertyType.Scalar;

                return rootProperty;
            }
            else
            {
                rootProperty.isComplete = false;
                rootProperty.Type = (propType == "array") ? PropertyType.Array : PropertyType.Object;

                if (propType == "array")
                {
                    rootProperty.Value = "Array (" + (firstProperty.Attributes["numchildren"] != null ? firstProperty.Attributes["numchildren"].Value : "") + ")";
                } else {
                    rootProperty.Value = "Instance of " + firstProperty.Attributes["classname"].Value;
                 }

                if (firstProperty.Attributes["children"].Value == "0")
                {
                    rootProperty.isComplete = true;
                }
                else
                {
                    int numChildren = firstProperty.Attributes["numchildren"] != null ? Convert.ToInt32(firstProperty.Attributes["numchildren"].Value) : 0;
                    rootProperty.isComplete = numChildren > 0 && numChildren == firstProperty.ChildNodes.Count;

                    foreach (XmlNode node in firstProperty.ChildNodes)
                    {
                        if (node.Attributes["name"].Value == "CLASSNAME") continue; // this is to handle http://bugs.xdebug.org/bug_view_page.php?bug_id=00000518
                        rootProperty.ChildProperties.Add(Property.Parse(node, context));
                    }
                }
            }

            return rootProperty;
        }
Пример #10
0
        static public Property Parse(XmlNode firstProperty, string context)
        {
            Property rootProperty = new Property();

            rootProperty.Context = context;

            rootProperty.Name     = firstProperty.Attributes["name"].Value;
            rootProperty.FullName = firstProperty.Attributes["fullname"].Value;

            string propType = firstProperty.Attributes["type"].Value;

            if (propType != "array" && propType != "object")
            {
                if (firstProperty.Attributes["encoding"] != null)
                {
                    if (firstProperty.Attributes["encoding"].Value == "base64")
                    {
                        byte[] todecode_byte        = Convert.FromBase64String(firstProperty.InnerText);
                        System.Text.Decoder decoder = new System.Text.ASCIIEncoding().GetDecoder();

                        int    charCount    = decoder.GetCharCount(todecode_byte, 0, todecode_byte.Length);
                        char[] decoded_char = new char[charCount];
                        decoder.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0);
                        string result = new String(decoded_char);

                        rootProperty.Value = result;
                    }
                }
                else
                {
                    rootProperty.Value = firstProperty.InnerText;
                }

                rootProperty.isComplete = true;
                rootProperty.Type       = PropertyType.Scalar;

                return(rootProperty);
            }
            else
            {
                rootProperty.isComplete = false;
                rootProperty.Type       = (propType == "array") ? PropertyType.Array : PropertyType.Object;

                if (propType == "array")
                {
                    rootProperty.Value = "Array (" + (firstProperty.Attributes["numchildren"] != null ? firstProperty.Attributes["numchildren"].Value : "") + ")";
                }
                else
                {
                    rootProperty.Value = "Instance of " + firstProperty.Attributes["classname"].Value;
                }

                if (firstProperty.Attributes["children"].Value == "0")
                {
                    rootProperty.isComplete = true;
                }
                else
                {
                    int numChildren = firstProperty.Attributes["numchildren"] != null?Convert.ToInt32(firstProperty.Attributes["numchildren"].Value) : 0;

                    rootProperty.isComplete = numChildren > 0 && numChildren == firstProperty.ChildNodes.Count;

                    foreach (XmlNode node in firstProperty.ChildNodes)
                    {
                        if (node.Attributes["name"].Value == "CLASSNAME")
                        {
                            continue;                                               // this is to handle http://bugs.xdebug.org/bug_view_page.php?bug_id=00000518
                        }
                        rootProperty.ChildProperties.Add(Property.Parse(node, context));
                    }
                }
            }


            return(rootProperty);
        }