コード例 #1
0
ファイル: Encoding.cs プロジェクト: Inzaghi2012/teamlab.v7.5
 /// <summary>
 /// </summary>
 /// <param name="buf"> </param>
 /// <param name="off"> </param>
 /// <param name="end"> </param>
 /// <param name="pos"> </param>
 protected abstract void movePosition(byte[] buf, int off, int end, Position pos);
コード例 #2
0
        /// <summary>
        /// </summary>
        /// <param name="buf"> </param>
        /// <param name="off"> </param>
        /// <param name="end"> </param>
        /// <param name="pos"> </param>
        protected override void movePosition(byte[] buf, int off, int end, Position pos)
        {
            /* Maintain the invariant: off - colDiff == colNumber. */
            int colDiff = off - pos.ColumnNumber;
            int lineNumber = pos.LineNumber;
            while (off != end)
            {
                byte b = buf[off];
                if (b >= 0)
                {
                    ++off;
                    switch (b)
                    {
                        case (byte) '\n':
                            lineNumber += 1;
                            colDiff = off;
                            break;
                        case (byte) '\r':
                            lineNumber += 1;
                            if (off != end && buf[off] == '\n')
                            {
                                off++;
                            }

                            colDiff = off;
                            break;
                    }
                }
                else
                {
                    switch (utf8TypeTable[b & 0xFF])
                    {
                        default:
                            off += 1;
                            break;
                        case BT_LEAD2:
                            off += 2;
                            colDiff++;
                            break;
                        case BT_LEAD3:
                            off += 3;
                            colDiff += 2;
                            break;
                        case BT_LEAD4:
                            off += 4;
                            colDiff += 3;
                            break;
                    }
                }
            }

            pos.ColumnNumber = off - colDiff;
            pos.LineNumber = lineNumber;
        }