Exemplo n.º 1
0
 /// <summary>
 /// 数字转换成字符串
 /// </summary>
 /// <param name="value">数字值</param>
 /// <param name="jsonStream">JSON输出流</param>
 public unsafe static void ToString(sbyte value, charStream jsonStream)
 {
     if (value == 0)
     {
         jsonStream.Write('0');
     }
     else
     {
         if (value < 0)
         {
             char *chars   = jsonStream.GetPrepLengthCurrent(5);
             uint  value32 = (uint)-(int)value;
             *(int *)chars = '-' + ('0' << 16);
             *(chars + 2)  = 'x';
             *(chars + 3)  = (char)((value32 >> 4) + '0');
             *(chars + 4)  = (char)number.ToHex(value32 & 15);
             jsonStream.UnsafeAddLength(5);
         }
         else
         {
             char *chars   = jsonStream.GetPrepLengthCurrent(4);
             uint  value32 = (uint)(int)value;
             *(int *)chars = '0' + ('x' << 16);
             *(chars + 2)  = (char)((value32 >> 4) + '0');
             *(chars + 3)  = (char)number.ToHex(value32 & 15);
             jsonStream.UnsafeAddLength(4);
         }
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// 查询条件
        /// </summary>
        /// <param name="sqlTable">数据库表格操作工具</param>
        /// <param name="sqlStream">SQL表达式流</param>
        /// <param name="expression">查询条件表达式</param>
        /// <param name="isCreatedIndex">是否已经创建查询索引</param>
        /// <returns></returns>
        internal static unsafe bool WriteWhere(fastCSharp.emit.sqlTable.sqlToolBase sqlTable, charStream sqlStream, Expression <Func <valueType, bool> > expression, ref bool isCreatedIndex)
        {
            if (expression == null)
            {
                return(true);
            }
            sqlStream.PrepLength(6);
            sqlStream.UnsafeAddLength(6);
            int  length                    = sqlStream.Length;
            bool logicConstantWhere        = false;
            keyValue <string, string> name = sqlTable.Client.GetWhere(expression, sqlStream, ref logicConstantWhere);

            if (length == sqlStream.Length)
            {
                sqlStream.UnsafeFreeLength(6);
                return(logicConstantWhere);
            }
            if (name.Key != null)
            {
                byte *where = (byte *)(sqlStream.Char + length);
                *(uint *)(where - sizeof(uint))     = 'e' + (' ' << 16);
                *(uint *)(where - sizeof(uint) * 2) = 'e' + ('r' << 16);
                *(uint *)(where - sizeof(uint) * 3) = 'w' + ('h' << 16);
                isCreatedIndex = true;
                sqlTable.CreateIndex(name.Key, name.Value);
            }
            return(true);
        }
Exemplo n.º 3
0
 /// <summary>
 /// 数字转换成字符串
 /// </summary>
 /// <param name="value"></param>
 /// <param name="jsonStream"></param>
 private unsafe static void toString(ulong value, charStream jsonStream)
 {
     if (value <= uint.MaxValue)
     {
         ToString((uint)value, jsonStream);
     }
     else
     {
         char *chars = jsonStream.GetPrepLengthCurrent(18), next;
         uint  value32 = (uint)(value >> 32);
         *(int *)chars = '0' + ('x' << 16);
         if (value32 >= 0x10000)
         {
             next = getToHex(value32 >> 16, chars + 2);
             toHex16(value32 & 0xffff, next);
             next += 4;
         }
         else
         {
             next = getToHex(value32, chars + 2);
         }
         toHex16((value32 = (uint)value) >> 16, next);
         toHex16(value32 & 0xffff, next + 4);
         jsonStream.UnsafeAddLength((int)(next - chars) + 8);
     }
 }
Exemplo n.º 4
0
        /// <summary>
        /// 字符
        /// </summary>
        /// <param name="value">字符</param>
        /// <param name="jsonStream">JSON输出流</param>
        public unsafe static void ToString(char value, charStream jsonStream)
        {
            char *chars = jsonStream.GetPrepLengthCurrent(3);

            *chars = Quote;
            *(chars + 1) = value;
            *(chars + 2) = Quote;
            jsonStream.UnsafeAddLength(3);
        }
Exemplo n.º 5
0
 /// <summary>
 /// 时间转字符串 第三方格式 /Date(xxx)/
 /// </summary>
 /// <param name="time">时间</param>
 /// <param name="jsonStream">JSON输出流</param>
 public static unsafe void ToStringOther(DateTime time, charStream jsonStream)
 {
     jsonStream.PrepLength(OtherDateStart.Length + (19 + 1 + 4));
     jsonStream.UnsafeWrite(fastCSharp.web.ajax.Quote);
     jsonStream.UnsafeSimpleWrite(OtherDateStart);
     toString((long)(((time.Kind == DateTimeKind.Utc ? time.Ticks + pub.LocalTimeTicks : time.Ticks) - JavascriptLocalMinTimeTicks) / date.MillisecondTicks), jsonStream);
     *(long *)jsonStream.CurrentChar = DateEnd + ('/' << 16) + ((long)fastCSharp.web.ajax.Quote << 32);
     jsonStream.UnsafeAddLength(3);
 }
Exemplo n.º 6
0
        /// <summary>
        /// Guid转换成字符串
        /// </summary>
        /// <param name="value">Guid</param>
        /// <param name="jsonStream">JSON输出流</param>
        public unsafe static void ToString(ref Guid value, charStream jsonStream)
        {
            byte *data = (byte *)jsonStream.GetPrepLengthCurrent(38);

            *(char *)data = fastCSharp.web.ajax.Quote;
            new guid {
                Value = value
            }.ToString((char *)(data + sizeof(char)));
            *(char *)(data + sizeof(char) * 37) = fastCSharp.web.ajax.Quote;
            jsonStream.UnsafeAddLength(38);
        }
Exemplo n.º 7
0
        /// <summary>
        /// 数字转换成字符串
        /// </summary>
        /// <param name="value">数字值</param>
        /// <param name="jsonStream">JSON输出流</param>
        public unsafe static void ToString(ushort value, charStream jsonStream)
        {
            char *chars;

            if (value < 10000)
            {
                if (value < 10)
                {
                    jsonStream.Write((char)(value + '0'));
                    return;
                }
                int div10 = (value * (int)fastCSharp.number.Div10_16Mul) >> fastCSharp.number.Div10_16Shift;
                if (div10 < 10)
                {
                    *(chars = jsonStream.GetPrepLengthCurrent(2)) = (char)(div10 + '0');
                    *(chars + 1) = (char)((value - div10 * 10) + '0');
                    jsonStream.UnsafeAddLength(2);
                    return;
                }
                int div100 = (div10 * (int)fastCSharp.number.Div10_16Mul) >> fastCSharp.number.Div10_16Shift;
                if (div100 < 10)
                {
                    *(chars = jsonStream.GetPrepLengthCurrent(3)) = (char)(div100 + '0');
                    *(chars + 1) = (char)((div10 - div100 * 10) + '0');
                    *(chars + 2) = (char)((value - div10 * 10) + '0');
                    jsonStream.UnsafeAddLength(3);
                    return;
                }
                int div1000 = (div100 * (int)fastCSharp.number.Div10_16Mul) >> fastCSharp.number.Div10_16Shift;
                *(chars = jsonStream.GetPrepLengthCurrent(4)) = (char)(div1000 + '0');
                *(chars + 1) = (char)((div100 - div1000 * 10) + '0');
                *(chars + 2) = (char)((div10 - div100 * 10) + '0');
                *(chars + 3) = (char)((value - div10 * 10) + '0');
                jsonStream.UnsafeAddLength(4);
                return;
            }
            *(int *)(chars = jsonStream.GetPrepLengthCurrent(6)) = '0' + ('x' << 16);
            toHex16(value, chars + 2);
            jsonStream.UnsafeAddLength(6);
        }
Exemplo n.º 8
0
 /// <summary>
 /// 数字转换成字符串
 /// </summary>
 /// <param name="value">数字值</param>
 /// <param name="jsonStream">JSON输出流</param>
 public unsafe static void ToString(byte value, charStream jsonStream)
 {
     if (value == 0)
     {
         jsonStream.Write('0');
     }
     else
     {
         byte *chars = (byte *)jsonStream.GetPrepLengthCurrent(4);
         *(int *)chars = '0' + ('x' << 16);
         *(char *)(chars + sizeof(char) * 2) = (char)number.ToHex((uint)value >> 4);
         *(char *)(chars + sizeof(char) * 3) = (char)number.ToHex((uint)value & 15);
         jsonStream.UnsafeAddLength(4);
     }
 }
Exemplo n.º 9
0
 /// <summary>
 /// 数字转换成字符串
 /// </summary>
 /// <param name="value">数字值</param>
 /// <param name="jsonStream">JSON输出流</param>
 public unsafe static void ToString(uint value, charStream jsonStream)
 {
     if (value <= ushort.MaxValue)
     {
         ToString((ushort)value, jsonStream);
     }
     else
     {
         char *chars = jsonStream.GetPrepLengthCurrent(10);
         *(int *)chars = '0' + ('x' << 16);
         char *next = getToHex(value >> 16, chars + 2);
         toHex16(value & 0xffff, next);
         jsonStream.UnsafeAddLength((int)(next - chars) + 4);
     }
 }
Exemplo n.º 10
0
 /// <summary>
 /// 格式化ajax字符串
 /// </summary>
 /// <param name="jsStream">JS字符流</param>
 /// <param name="formatStream">格式化JSON字符流</param>
 public unsafe static void UnsafeFormatJavascript(charStream jsStream, charStream formatStream)
 {
     if (jsStream.Length != 0)
     {
         char *start  = jsStream.Char;
         int   length = formatLength(jsStream);
         if (length == 0)
         {
             char *end = start + (length = jsStream.Length);
             formatStream.PrepLength(length);
             for (char *write = formatStream.CurrentChar; start != end; ++start)
             {
                 *write++ = *start == Quote ? '"' : *start;
             }
             formatStream.UnsafeAddLength(length);
         }
         else
         {
             formatStream.PrepLength(length += jsStream.Length);
             formatJavascript(start, start + jsStream.Length, formatStream.CurrentChar);
             formatStream.UnsafeAddLength(length);
         }
     }
 }
Exemplo n.º 11
0
        /// <summary>
        /// SQL语句字符串格式化(单引号变两个)
        /// </summary>
        /// <param name="sqlStream">SQL字符流</param>
        /// <param name="value">常量</param>
        protected virtual unsafe void convertString(charStream sqlStream, string value)
        {
            fixed(char *valueFixed = value)
            {
                int length = 0;

                for (char *start = valueFixed, end = valueFixed + value.Length; start != end; ++start)
                {
                    if (*start == '\'')
                    {
                        ++length;
                    }
                    else if (*start == '\\')
                    {
                        if ((*(start + 1) == '\r' || *(start + 1) == '\n') && (int)(end - start) >= 2)
                        {
                            length += 2;
                            ++start;
                        }
                    }
                }
                if (length == 0)
                {
                    sqlStream.PrepLength(value.Length + 2);
                    sqlStream.UnsafeWrite('\'');
                    sqlStream.WriteNotNull(value);
                    sqlStream.UnsafeWrite('\'');
                    return;
                }
                sqlStream.PrepLength((length += value.Length) + 2);
                sqlStream.UnsafeWrite('\'');
                byte *write = (byte *)sqlStream.CurrentChar;

                for (char *start = valueFixed, end = valueFixed + value.Length; start != end; ++start)
                {
                    if (*start != '\'')
                    {
                        if (*start == '\\')
                        {
                            if (*(start + 1) == '\n')
                            {
                                if ((int)(end - start) >= 2)
                                {
                                    *(long *)write = '\\' + ('\\' << 16) + ((long)'\n' << 32) + ((long)'\n' << 48);
                                    ++start;
                                    write += sizeof(long);
                                    continue;
                                }
                            }
                            else if (*(start + 1) == '\r' && (int)(end - start) >= 2)
                            {
                                *(long *)write = '\\' + ('\\' << 16) + ((long)'\n' << 32) + ((long)'\r' << 48);
                                ++start;
                                write += sizeof(long);
                                continue;
                            }
                        }
                        *(char *)write = *start;
                        write         += sizeof(char);
                    }
                    else
                    {
                        *(int *)write = ('\'' << 16) + '\'';
                        write        += sizeof(int);
                    }
                }
                sqlStream.UnsafeAddLength(length);
                sqlStream.UnsafeWrite('\'');
            }
        }
Exemplo n.º 12
0
 /// <summary>
 /// 输出非数字值
 /// </summary>
 public unsafe static void WriteNaN(charStream jsonStream)
 {
     *(long *)jsonStream.GetPrepLengthCurrent(4) = 'N' + ('a' << 16) + ((long)'N' << 32);
     jsonStream.UnsafeAddLength(3);
 }
Exemplo n.º 13
0
 /// <summary>
 /// 输出null值
 /// </summary>
 public unsafe static void WriteNull(charStream jsonStream)
 {
     *(long *)jsonStream.GetPrepLengthCurrent(4) = 'n' + ('u' << 16) + ((long)'l' << 32) + ((long)'l' << 48);
     jsonStream.UnsafeAddLength(4);
 }
Exemplo n.º 14
0
 /// <summary>
 /// 输出空数组
 /// </summary>
 public unsafe static void WriteArray(charStream jsonStream)
 {
     *(int *)jsonStream.GetPrepLengthCurrent(2) = '[' + (']' << 16);
     jsonStream.UnsafeAddLength(2);
 }
Exemplo n.º 15
0
 /// <summary>
 /// 输出空对象
 /// </summary>
 public unsafe static void WriteObject(charStream jsonStream)
 {
     *(int *)jsonStream.GetPrepLengthCurrent(2) = '{' + ('}' << 16);
     jsonStream.UnsafeAddLength(2);
 }