Exemplo n.º 1
0
        public static Mesh CreateMesh(GradationMaterial material, Vector2 drawSize, Color lightColor, Color darkColor)
        {
            var result = CreateMesh(material);

            if (material.keys.Any(x => x.color.a < 1.0f))
            {
                var cellSize    = new Vector2(32.0f / drawSize.x, 32.0f / drawSize.y);
                var checkerMesh = CreateCheckerMesh(new Rect(-1.0f, -1.0f, 2.0f, 2.0f), cellSize, Color.white, Color.gray);

                var vertices = new Vector3[result.vertices.Length + checkerMesh.vertices.Length];
                Array.Copy(checkerMesh.vertices, 0, vertices, 0, checkerMesh.vertices.Length);
                Array.Copy(result.vertices, 0, vertices, checkerMesh.vertices.Length, result.vertices.Length);

                var colors = new Color[result.colors.Length + checkerMesh.colors.Length];
                Array.Copy(checkerMesh.colors, 0, colors, 0, checkerMesh.colors.Length);
                Array.Copy(result.colors, 0, colors, checkerMesh.colors.Length, result.colors.Length);

                var indices = checkerMesh.GetIndices(0)
                              .Concat(result.GetIndices(0)
                                      .Select(x => x + checkerMesh.vertices.Length)
                                      )
                              .ToArray();

                result.Clear();
                result.vertices = vertices;
                result.colors   = colors;
                result.SetIndices(indices, MeshTopology.Triangles, 0);
            }
            return(result);
        }
Exemplo n.º 2
0
        public virtual void Insert(int addr, Bytecode opcode, string s)
        {
            //System.out.println("before insert of "+opcode+"("+s+"):"+ Arrays.toString(impl.instrs));
            EnsureCapacity(1 + Instruction.OperandSizeInBytes);
            int instrSize = 1 + Instruction.OperandSizeInBytes;

            // make room for opcode, opnd
            Array.Copy(impl.instrs, addr, impl.instrs, addr + instrSize, ip - addr);
            int save = ip;

            ip = addr;
            Emit1(null, opcode, s);
            ip = save + instrSize;
            //System.out.println("after  insert of "+opcode+"("+s+"):"+ Arrays.toString(impl.instrs));
            // adjust addresses for BR and BRF
            int a = addr + instrSize;

            while (a < ip)
            {
                Bytecode    op = (Bytecode)impl.instrs[a];
                Instruction I  = Instruction.instructions[(int)op];
                if (op == Bytecode.INSTR_BR || op == Bytecode.INSTR_BRF)
                {
                    int opnd = BytecodeDisassembler.GetShort(impl.instrs, a + 1);
                    WriteShort(impl.instrs, a + 1, (short)(opnd + instrSize));
                }
                a += I.nopnds * Instruction.OperandSizeInBytes + 1;
            }
            //System.out.println("after  insert of "+opcode+"("+s+"):"+ Arrays.toString(impl.instrs));
        }
Exemplo n.º 3
0
 public void WriteMarix(Buffer buffer, float[][] matrix, bool transpose = false)
 {
     using (var ws = NewWriteStream(buffer)) {
         int     rows    = matrix.Length;
         int     columns = matrix[0].Length;
         float[] buf     = new float[rows * columns];
         if (transpose)
         {
             int idx = 0;
             for (int col = 0; col < columns; col++)
             {
                 for (int row = 0; row < rows; row++)
                 {
                     buf[idx++] = matrix[row][col];
                 }
             }
         }
         else
         {
             for (int row = 0; row < rows; row++)
             {
                 Array.Copy(matrix[row], 0, buf, row * columns, columns);
             }
         }
         ws.WriteRange(buf);
     }
 }
Exemplo n.º 4
0
        /** <summary>Grows the set to a larger number of bits.</summary>
         *  <param name="bit">element that must fit in set</param>
         */
        public virtual void GrowToInclude(int bit)
        {
            int newSize = Math.Max(_bits.Length << 1, NumWordsToHold(bit));

            ulong[] newbits = new ulong[newSize];
            Array.Copy(_bits, newbits, _bits.Length);
            _bits = newbits;
        }
Exemplo n.º 5
0
        /// <summary>
        /// Creates a copy of this buffer and all it's contents.
        /// </summary>
        /// <returns>A new clone BufferStream.</returns>
        /// <exception cref="System.ArgumentNullException"/>
        public BufferStream CloneBufferStream()
        {
            BufferStream clone = new BufferStream(memory.Length, alignment);

            Array.Copy(memory, clone.Memory, memory.Length);
            clone.iterator = iterator;
            return(clone);
        }
Exemplo n.º 6
0
        /** <summary>Sets the size of a set.</summary>
         *  <param name="nwords">how many words the new set should be</param>
         */
        private void SetSize(int nwords)
        {
            ulong[] newbits = new ulong[nwords];
            int     n       = Math.Min(nwords, _bits.Length);

            Array.Copy(_bits, newbits, n);
            _bits = newbits;
        }
Exemplo n.º 7
0
        public BitStream Clone()
        {
            BitStream stream = new BitStream(Length, BlockSize);

            Array.Copy(memory, stream.Memory, Capacity);
            stream.Iterator = Iterator;
            return(stream);
        }
Exemplo n.º 8
0
 protected virtual int[] Trim(int[] X, int n)
 {
     if (n < X.Length)
     {
         int[] trimmed = new int[n];
         Array.Copy(X, 0, trimmed, 0, n);
         X = trimmed;
     }
     return(X);
 }
Exemplo n.º 9
0
 /** <summary>Push a rule's follow set using our own hardcoded stack</summary> */
 protected virtual void PushFollow(BitSet fset)
 {
     if ((state._fsp + 1) >= state.following.Length)
     {
         BitSet[] f = new BitSet[state.following.Length * 2];
         Array.Copy(state.following, f, state.following.Length);
         state.following = f;
     }
     state.following[++state._fsp] = fset;
 }
Exemplo n.º 10
0
        double ParseNumber(char[] json, ref int index)
        {
            EatWhitespace(json, ref index);

            int lastIndex  = GetLastIndexOfNumber(json, index);
            int charLength = (lastIndex - index) + 1;

            char[] numberCharArray = new char[charLength];

            Array.Copy(json, index, numberCharArray, 0, charLength);
            index = lastIndex + 1;
            return(double.Parse(new string(numberCharArray)));
        }
Exemplo n.º 11
0
        public byte[] GetSharedSecret(byte[] pK)
        {
            byte[] p1 = new byte[pK[0] | (pK[1] << 8) | (pK[2] << 16) | (pK[3] << 24)];             // Reconstruct x-axis size
            byte[] p2 = new byte[pK.Length - p1.Length - 4];
            Array.Copy(pK, 4, p1, 0, p1.Length);
            Array.Copy(pK, 4 + p1.Length, p2, 0, p2.Length);

            CurvePoint remotePublic = new CurvePoint(new BigInteger(p1), new BigInteger(p2));

            byte[] secret = curve.Multiply(remotePublic, priv).X.ToByteArray();             // Use the x-coordinate as the shared secret

            // PBKDF2-HMAC-SHA1 (Common shared secret generation method)
            return(new Rfc2898DeriveBytes(secret, Encoding.UTF8.GetBytes("P1sN0R4inb0wPl5P1sPls"), 1000).GetBytes(32));
        }
Exemplo n.º 12
0
        public byte[] GetPublicKey()
        {
            byte[] p1 = pub.X.ToByteArray();
            byte[] p2 = pub.Y.ToByteArray();

            byte[] ser = new byte[4 + p1.Length + p2.Length];
            ser[0] = (byte)(p1.Length & 255);
            ser[1] = (byte)((p1.Length >> 8) & 255);
            ser[2] = (byte)((p1.Length >> 16) & 255);
            ser[3] = (byte)((p1.Length >> 24) & 255);
            Array.Copy(p1, 0, ser, 4, p1.Length);
            Array.Copy(p2, 0, ser, 4 + p1.Length, p2.Length);

            return(ser);
        }
Exemplo n.º 13
0
        private void Insert(int index, T value)
        {
            if (_Size == _Array.Length)
            {
                EnsureCapacity(_Size + 1);
            }
            if (index < _Size)
            {
                SysArray.Copy(_Array, index, _Array, index + 1, _Size - index);
            }
            _Array[index] = value;
#if USE_MIN_MAX_VARIABLES
            _Min = _Array[0];
            _Max = _Array[_Size];
#endif
            _Size++;
        }
Exemplo n.º 14
0
        }         //FitBufferSize

        public static double[,] Perform(double[] real, int smallerSize, int shift)
        {
            if (smallerSize > real.Length)
            {
                smallerSize = real.Length;
            }
            double[] shortened = new double[smallerSize];
            Array.Copy(real, shift, shortened, 0, smallerSize);
            var LomontArray = CreateLomontArray(shortened);
            var fft         = new Lomont.LomontFFT();

            fft.FFT(LomontArray, true);
            var split = SplitIntoComplex(LomontArray);
            var max   = NormalizeArray(split);

            convertToAmplitudePhase(split);
            return(split);
        }         //Perform
Exemplo n.º 15
0
        // [272, 45, 75, 81, 501, 2, 24, 66]
        // It sorts by the least significant digits
        // Sorts by 2, 5, 5, 1, 1, 2, 4, 6
        // The single digits.
        // 81, 501, 272, 2, 24, 45, 75, 66
        // Next it looks at the second digits
        // 2 becomes 02
        // 501, 02, 24, 45, 66, 272, 75, 81,
        //catch, ctreating a new array every time


        protected override IEnumerator Sort()
        {
            int nodeCount = nodes.Length;
            int i, j;

            Node[] temp = new Node[nodes.Length];

            //Integer cannot have more than 31 digits
            for (int shift = 31; shift > -1; --shift)
            {
                //Reset j to zero
                j = 0;

                //loop through the whole array
                //Why is removing -1 changes it
                //for (i = 0; i < nodeCount - 1; i++)
                //Why does this works??? for (i = 0; i < nodeCount; ++i)
                for (i = 0; i < nodeCount; ++i)
                {
                    //Determine if the bit shifted is above 0
                    //If it is above 0, it means there is a number
                    //e.g. shifting 2 << 1 = 0. Shifting 12 << 1 becaues we're in the next digit.
                    bool move = (nodes[i].Index << shift) >= 0;

                    if (shift == 0 ? !move : move)
                    {
                        nodes[i - j] = nodes[i];
                    }
                    else
                    {
                        temp[j++] = nodes[i];
                    }
                }

                //Copy the data to the temp array
                Array.Copy(temp, 0, nodes, nodes.Length - j, j);

                //Simply visualization, not part of algorithm
                StartFrame(0, 1);
                yield return(null);

                EndFrame(0, 1);
            }
        }
Exemplo n.º 16
0
        public override void Update()
        {
            base.Update();
            if (CachedValue == null)
            {
                return;
            }
            var array = (Array)CachedValue;

            _arrayLength = array.Length;
            if (_newLength >= 0 && _newLength != _arrayLength)
            {
                var newArray = Array.CreateInstance(_elementType, _newLength);
                Array.Copy(array, newArray, Mathf.Min(_arrayLength, _newLength));
                _arrayLength = _newLength;
                CachedValue  = array = newArray;
                Accessor.SetValue(array);
            }
        }
Exemplo n.º 17
0
        public void RemoveAt(int index)
        {
#if DEBUG
            if (index < 0 || _Size <= index)
            {
                throw (new ArgumentOutOfRangeException(nameof(index)));
            }
#endif
            _Size--;
            if (index < _Size)
            {
                SysArray.Copy(_Array, index + 1, _Array, index, _Size - index);
            }
            _Array[_Size] = default(T);
#if USE_MIN_MAX_VARIABLES
            _Min = _Array[0];
            _Max = _Array[_Size - 1];
#endif
        }
Exemplo n.º 18
0
        /*public SortedList< T > SplitInTwo()
         * {
         *  var half = (_Size >> 1);
         *  var other = new SortedList< T >( _Comparer )
         *  {
         *      _Array = new T[ _Array.Length ],
         *      _Size  = half,
         *  };
         *  _Size -= half;
         *  SysArray.Copy( _Array, _Size, other._Array, 0, half );
         *  SysArray.Clear( _Array, _Size, half );
         *
         *  return (other);
         * }*/
        public void SplitInTwo <X>(X other)
            where X : SortedList <T>
        {
            var half = (_Size >> 1);

            other._Comparer = _Comparer;
            other._Array    = new T[_Array.Length];
            other._Size     = half;

            _Size -= half;
            SysArray.Copy(_Array, _Size, other._Array, 0, half);
            SysArray.Clear(_Array, _Size, half);
#if USE_MIN_MAX_VARIABLES
            _Min       = _Array[0];
            _Max       = _Array[_Size - 1];
            other._Min = other._Array[0];
            other._Max = other._Array[other._Size - 1];
#endif
            //return (other);
        }
Exemplo n.º 19
0
 private void QueueReceivedData(byte[] buf, int len)
 {
     Log(9, "Queueing " + len + " bytes.");
     if (rxQueue == null)
     {
         rxQueue = new byte[rxQueueSize];
     }
     if (rxQueueUsed + len > rxQueueSize)
     {
         // ignore old data on overflow
         rxQueueUsed = 0;
         Log(3, "RX queue overflow.");
     }
     if (len > rxQueueSize)
     {
         // Ignore if new data block is too large for queue.
         return;
     }
     Array.Copy(buf, 0, rxQueue, rxQueueUsed, len);
     rxQueueUsed += len;
 }
        public virtual string[] GetEventElements(string @event)
        {
            if (@event == null)
            {
                return(null);
            }
            string[] elements = new string[MAX_EVENT_ELEMENTS];
            string   str      = null; // a string element if present (must be last)

            try
            {
                int firstQuoteIndex = @event.IndexOf('"');
                if (firstQuoteIndex >= 0)
                {
                    // treat specially; has a string argument like "a comment\n
                    // Note that the string is terminated by \n not end quote.
                    // Easier to parse that way.
                    string eventWithoutString = @event.Substring(0, firstQuoteIndex);
                    str    = @event.Substring(firstQuoteIndex + 1);
                    @event = eventWithoutString;
                }

                string[] tokens = @event.Split('\t');
                Array.Copy(tokens, elements, Math.Min(tokens.Length, MAX_EVENT_ELEMENTS));
                if (tokens.Length >= MAX_EVENT_ELEMENTS)
                {
                    return(elements);
                }

                if (str != null)
                {
                    elements[tokens.Length] = str;
                }
            }
            catch (Exception e)
            {
                ExceptionExtensions.PrintStackTrace(e, Console.Error);
            }
            return(elements);
        }
Exemplo n.º 21
0
 public override void ExitDecision(int decisionNumber)
 {
     //System.out.println("exitDecision "+decisionNumber);
     // track how many of acyclic, cyclic here as we don't know what kind
     // yet in enterDecision event.
     if (parser.isCyclicDecision)
     {
         numCyclicDecisions++;
     }
     else
     {
         numFixedDecisions++;
     }
     lookaheadStack.Pop(); // pop lookahead depth counter
     decisionLevel--;
     if (parser.isCyclicDecision)
     {
         if (numCyclicDecisions >= decisionMaxCyclicLookaheads.Length)
         {
             int[] bigger = new int[decisionMaxCyclicLookaheads.Length * 2];
             Array.Copy(decisionMaxCyclicLookaheads, bigger, decisionMaxCyclicLookaheads.Length);
             decisionMaxCyclicLookaheads = bigger;
         }
         decisionMaxCyclicLookaheads[numCyclicDecisions - 1] = maxLookaheadInCurrentDecision;
     }
     else
     {
         if (numFixedDecisions >= decisionMaxFixedLookaheads.Length)
         {
             int[] bigger = new int[decisionMaxFixedLookaheads.Length * 2];
             Array.Copy(decisionMaxFixedLookaheads, bigger, decisionMaxFixedLookaheads.Length);
             decisionMaxFixedLookaheads = bigger;
         }
         decisionMaxFixedLookaheads[numFixedDecisions - 1] = maxLookaheadInCurrentDecision;
     }
     parser.isCyclicDecision       = false; // can't nest so just reset to false
     maxLookaheadInCurrentDecision = 0;
 }
Exemplo n.º 22
0
        private static Mesh CreateCheckerMesh(Rect r, Vector2 cellSize, Color lightColor, Color darkColor)
        {
            var result = new Mesh();

            var vertexXCount = Mathf.CeilToInt(r.width / cellSize.x) + 1;
            var vertexYCount = Mathf.CeilToInt(r.height / cellSize.y) + 1;
            var vertexCount  = vertexXCount * vertexYCount;

            var vertices = new Vector3[vertexCount + 4];

            vertices[0] = new Vector3(r.xMin, r.yMax, 0.0f);
            vertices[1] = new Vector3(r.xMax, r.yMax, 0.0f);
            vertices[2] = new Vector3(r.xMin, r.yMin, 0.0f);
            vertices[3] = new Vector3(r.xMax, r.yMin, 0.0f);
            for (int y = 0, yMax = vertexYCount; y < yMax; ++y)
            {
                for (int x = 0, xMax = vertexXCount; x < xMax; ++x)
                {
                    var positon = new Vector3(r.xMax, r.yMin, 0.0f);
                    if (x < (vertexXCount - 1))
                    {
                        positon.x = cellSize.x * x + r.xMin;
                    }
                    if (y < (vertexYCount - 1))
                    {
                        positon.y = r.yMax - cellSize.y * y;
                    }
                    var index = x + y * vertexXCount + 4;
                    vertices[index] = positon;
                }
            }
            result.vertices = vertices;

            var colors = new Color[vertexCount + 4];

            for (int i = 0, iMax = 4; i < iMax; ++i)
            {
                colors[i] = lightColor;
            }
            for (int i = 4, iMax = vertexCount + 4; i < iMax; ++i)
            {
                colors[i] = darkColor;
            }
            result.colors = colors;

            var indices = new int[((vertexXCount - 1) * (vertexYCount - 1) / 2 + 1) * 6];

            {
                Array.Copy(new[] { 0, 1, 2, 1, 3, 2 }, indices, 6);
                var index = 6;
                for (int y = 0, yMax = vertexYCount - 1; y < yMax; ++y)
                {
                    for (int x = 0, xMax = vertexXCount - 1; x < xMax; ++x)
                    {
                        if (((x + y) & 0x01) == 1)
                        {
                            var upperLeftIndex  = x + y * vertexXCount + 4;
                            var upperRightIndex = upperLeftIndex + 1;
                            var lowerRightIndex = upperRightIndex + vertexXCount;
                            var lowerLeftIndex  = upperLeftIndex + vertexXCount;
                            indices[index++] = upperLeftIndex;
                            indices[index++] = upperRightIndex;
                            indices[index++] = lowerLeftIndex;
                            indices[index++] = upperRightIndex;
                            indices[index++] = lowerRightIndex;
                            indices[index++] = lowerLeftIndex;
                        }
                    }
                }
            }
            result.SetIndices(indices, MeshTopology.Triangles, 0);

            return(result);
        }
Exemplo n.º 23
0
 /// <summary>
 /// Copes the specified number of bytes from this buffer to the destination buffer, given the shared start position for both buffers.
 /// </summary>
 /// <param name="destBuffer">Buffer to copy the contents of this buffer too.</param>
 /// <param name="startIndex">Shared start index of both buffers to start copying data from/to.</param>
 /// <param name="length">Number of bytes to copy from this buffer to the destination buffer.</param>
 /// <exception cref="System.ArgumentNullException"/>
 /// <exception cref="System.ArgumentOutOfRangeException"/>
 /// <exception cref="System.ArgumentException"/>
 public void BlockCopy(BufferStream destBuffer, int startIndex, int length)
 {
     Array.Copy(memory, startIndex, destBuffer.Memory, startIndex, length);
 }
Exemplo n.º 24
0
        public static Mesh CreateMesh(GradationMaterial material)
        {
            var result = new Mesh();

            var grid            = material.GetGrid();
            var mainVertexCount = grid.xThresholds.Length * grid.yThresholds.Length;
            var subVertexCount  = mainVertexCount - grid.xThresholds.Length - grid.yThresholds.Length + 1;
            var vertexCount     = mainVertexCount + subVertexCount;

            var vertices = new Vector3[vertexCount];

            for (int y = 0, yMax = grid.yThresholds.Length; y < yMax; ++y)
            {
                for (int x = 0, xMax = grid.xThresholds.Length; x < xMax; ++x)
                {
                    var index = x + y * xMax;
                    vertices[index] = new Vector3(grid.xThresholds[x] * 2.0f - 1.0f
                                                  , 1.0f - grid.yThresholds[y] * 2.0f
                                                  , 0.0f
                                                  );
                }
            }
            for (int y = 0, yMax = grid.yThresholds.Length - 1; y < yMax; ++y)
            {
                for (int x = 0, xMax = grid.xThresholds.Length - 1; x < xMax; ++x)
                {
                    var index = x + y * xMax + mainVertexCount;
                    vertices[index] = new Vector3((grid.xThresholds[x] + grid.xThresholds[x + 1]) - 1.0f
                                                  , 1.0f - (grid.yThresholds[y] + grid.yThresholds[y + 1])
                                                  , 0.0f
                                                  );
                }
            }
            result.vertices = vertices;

            var colors = new Color[vertexCount];

            Array.Copy(grid.colors, colors, grid.colors.Length);
            for (int y = 0, yMax = grid.yThresholds.Length - 1; y < yMax; ++y)
            {
                for (int x = 0, xMax = grid.xThresholds.Length - 1; x < xMax; ++x)
                {
                    var index = x + y * xMax + mainVertexCount;
                    colors[index] = (grid.GetColor(x, y) + grid.GetColor(x + 1, y) + grid.GetColor(x + 1, y + 1) + grid.GetColor(x, y + 1)) * 0.25f;
                }
            }
            result.colors = colors;

            var indices = new int[12 * (grid.yThresholds.Length - 1) * (grid.xThresholds.Length - 1)];

            for (int y = 0, yMax = grid.yThresholds.Length - 1; y < yMax; ++y)
            {
                for (int x = 0, xMax = grid.xThresholds.Length - 1; x < xMax; ++x)
                {
                    var index           = x + y * xMax;
                    var upperLeftIndex  = x + y * grid.xThresholds.Length;
                    var upperRightIndex = upperLeftIndex + 1;
                    var lowerLeftIndex  = upperLeftIndex + grid.xThresholds.Length;
                    var lowerRightIndex = lowerLeftIndex + 1;
                    var centerIndex     = index + mainVertexCount;
                    indices[index * 12 + 0]  = centerIndex;
                    indices[index * 12 + 1]  = upperLeftIndex;
                    indices[index * 12 + 2]  = upperRightIndex;
                    indices[index * 12 + 3]  = centerIndex;
                    indices[index * 12 + 4]  = upperRightIndex;
                    indices[index * 12 + 5]  = lowerRightIndex;
                    indices[index * 12 + 6]  = centerIndex;
                    indices[index * 12 + 7]  = lowerRightIndex;
                    indices[index * 12 + 8]  = lowerLeftIndex;
                    indices[index * 12 + 9]  = centerIndex;
                    indices[index * 12 + 10] = lowerLeftIndex;
                    indices[index * 12 + 11] = upperLeftIndex;
                }
            }
            result.SetIndices(indices, MeshTopology.Triangles, 0);

            return(result);
        }
Exemplo n.º 25
0
 /// <summary>
 /// Copes the specified number of bytes from the start of this buffer to the start of the destination buffer.
 /// </summary>
 /// <param name="destBuffer">Buffer to copy the contents of this buffer too.</param>
 /// <param name="length">Number of bytes to copy from this buffer to the destination buffer.</param>
 /// <exception cref="System.ArgumentNullException"/>
 /// <exception cref="System.ArgumentOutOfRangeException"/>
 /// <exception cref="System.ArgumentException"/>
 public void BlockCopy(BufferStream destBuffer, int length)
 {
     Array.Copy(memory, destBuffer.Memory, length);
 }
Exemplo n.º 26
0
        string ParseString(char[] json, ref int index)
        {
            string s = "";
            char   c;

            EatWhitespace(json, ref index);

            // "
            c = json[index++];

            bool complete = false;

            while (!complete)
            {
                if (index == json.Length)
                {
                    break;
                }

                c = json[index++];
                if (c == '"')
                {
                    complete = true;
                    break;
                }
                else if (c == '\\')
                {
                    if (index == json.Length)
                    {
                        break;
                    }
                    c = json[index++];
                    if (c == '"')
                    {
                        s += '"';
                    }
                    else if (c == '\\')
                    {
                        s += '\\';
                    }
                    else if (c == '/')
                    {
                        s += '/';
                    }
                    else if (c == 'b')
                    {
                        s += '\b';
                    }
                    else if (c == 'f')
                    {
                        s += '\f';
                    }
                    else if (c == 'n')
                    {
                        s += '\n';
                    }
                    else if (c == 'r')
                    {
                        s += '\r';
                    }
                    else if (c == 't')
                    {
                        s += '\t';
                    }
                    else if (c == 'u')
                    {
                        int remainingLength = json.Length - index;
                        if (remainingLength >= 4)
                        {
                            char[] unicodeCharArray = new char[4];
                            Array.Copy(json, index, unicodeCharArray, 0, 4);

                            // Drop in the HTML markup for the unicode character
                            //s += "&#x" + new string(unicodeCharArray) + ";";

                            // TN: Working version of the code below
                            s += char.ConvertFromUtf32(int.Parse(new string(unicodeCharArray), System.Globalization.NumberStyles.HexNumber));

                            //uint codePoint = System.UInt32.Parse(new string(unicodeCharArray), System.Globalization.NumberStyles.HexNumber);
                            // convert the integer codepoint to a unicode char and add to string
                            //s += Char.ConvertFromUtf32((int)codePoint);

                            // skip 4 chars
                            index += 4;
                        }
                        else
                        {
                            break;
                        }
                    }
                }
                else
                {
                    s += c;
                }
            }

            if (!complete)
            {
                return(null);
            }

            return(s);
        }
Exemplo n.º 27
0
        /// <summary>
        /// Copies the entire contents of this buffer to the destination buffer.
        /// </summary>
        /// <param name="destBuffer">Buffer to copy the contents of this buffer too.</param>
        public void BlockCopy(BufferStream destBuffer)
        {
            int length = (destBuffer.Memory.Length > memory.Length) ? memory.Length : destBuffer.Memory.Length;

            Array.Copy(memory, destBuffer.Memory, length);
        }