Beispiel #1
0
 /// <summary>
 /// 格式化ajax字符串
 /// </summary>
 /// <param name="jsStream">JS字符流</param>
 /// <param name="formatStream">格式化JSON字符流</param>
 internal unsafe static void FormatJavascript(charStream jsStream, unmanagedStream 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 <<= 1);
             for (char *write = (char *)(formatStream.CurrentData); start != end; ++start)
             {
                 *write++ = *start == Quote ? '"' : *start;
             }
             formatStream.UnsafeAddLength(length);
         }
         else
         {
             length += jsStream.Length;
             formatStream.PrepLength(length <<= 1);
             formatJavascript(start, start + jsStream.Length, (char *)(formatStream.CurrentData));
             formatStream.UnsafeAddLength(length);
         }
     }
 }
Beispiel #2
0
            /// <summary>
            /// 文本转HTML
            /// </summary>
            /// <param name="value">文本值</param>
            /// <param name="stream">HTML编码流</param>
            public unsafe void ToHtml(ref subString value, unmanagedStream stream)
            {
                if (value.Length != 0)
                {
                    if (stream == null)
                    {
                        log.Error.Throw(log.exceptionType.Null);
                    }
                    int length = value.Length;
                    fixed(char *valueFixed = value.value)
                    {
                        char *start = valueFixed + value.StartIndex, end = start + length;
                        int   count = encodeCount(start, end);

                        if (count == 0)
                        {
                            stream.PrepLength(length <<= 1);
                            unsafer.memory.Copy(start, stream.CurrentData, length);
                        }
                        else
                        {
                            length += count << 2;
                            stream.PrepLength(length <<= 1);
                            toHtml(start, end, (char *)stream.CurrentData);
                        }
                        stream.UnsafeAddLength(length);
                    }
                }
            }
Beispiel #3
0
        private unsafe static void serialize(fastCSharp.emit.dataSerializer serializer, fileBlockMember <valueType> value)
        {
            int indexCustom = value.index.Custom;

            if ((indexCustom & (int)custom.Serialize) == 0)
            {
                if (value.index.Size == 0)
                {
                    serializer.Stream.Write(fastCSharp.emit.binarySerializer.NullValue);
                }
                else
                {
                    unmanagedStream stream = serializer.Stream;
                    stream.PrepLength(sizeof(int) * 2 + sizeof(long));
                    byte *data = stream.CurrentData;
                    *(int *)data = (emit.pub.PuzzleValue & 0x7fffff00) + indexCustom;
                    *(int *)(data + sizeof(int))      = value.index.Size;
                    *(long *)(data + sizeof(int) * 2) = value.index.Index;
                    stream.UnsafeAddLength(sizeof(int) * 2 + sizeof(long));
                    stream.PrepLength();
                }
            }
            else if (value.value == null)
            {
                serializer.Stream.Write(fastCSharp.emit.binarySerializer.NullValue);
            }
            else
            {
                serializer.Stream.Write(indexCustom);
                fastCSharp.emit.dataSerializer.typeSerializer <valueType> .Serialize(serializer, value.value);
            }
        }
Beispiel #4
0
 /// <summary>
 /// 序列化
 /// </summary>
 /// <param name="stream"></param>
 /// <param name="map"></param>
 /// <param name="fieldCount"></param>
 internal static void FieldSerialize(unmanagedStream stream, ulong map, int fieldCount)
 {
     if (map == 0)
     {
         stream.Write(0);
     }
     else
     {
         stream.PrepLength(sizeof(int) + sizeof(ulong));
         byte *data = stream.CurrentData;
         *(int *)data = fieldCount;
         *(ulong *)(data + sizeof(int)) = map;
         stream.UnsafeAddLength(sizeof(int) + sizeof(ulong));
         stream.PrepLength();
     }
 }
Beispiel #5
0
 /// <summary>
 /// 中文分词词语集合写入文本文件
 /// </summary>
 private unsafe static void writeTxtFile()
 {
     string[] words = Words;
     using (unmanagedStream wordStream = new unmanagedStream())
     {
         *(int *)wordStream.Data = words.Length;
         wordStream.UnsafeAddLength(sizeof(int));
         foreach (string word in words)
         {
             wordStream.Write(word);
             wordStream.Write((char)0);
         }
         subArray <byte> data = io.compression.stream.Deflate.GetCompress(wordStream.GetArray(), 0);
         using (FileStream fileStream = new FileStream(fastCSharp.config.search.Default.WordTxtFileName, FileMode.Create, FileAccess.Write, FileShare.None))
         {
             fileStream.Write(data.UnsafeArray, data.StartIndex, data.Count);
         }
     }
 }
Beispiel #6
0
 /// <summary>
 /// 序列化
 /// </summary>
 /// <param name="stream"></param>
 /// <param name="map"></param>
 /// <param name="type"></param>
 internal static void FieldSerialize(unmanagedStream stream, byte *map, type type)
 {
     if (map == null)
     {
         stream.Write(0);
     }
     else
     {
         stream.PrepLength(type.FieldSerializeSize + sizeof(int));
         byte *data = stream.CurrentData, read = map;
         *(int *)data = type.FieldCount;
         data        += sizeof(int);
         for (byte *end = map + (type.FieldSerializeSize & (int.MaxValue - sizeof(ulong) + 1)); read != end; read += sizeof(ulong), data += sizeof(ulong))
         {
             *(ulong *)data = *(ulong *)read;
         }
         if ((type.FieldSerializeSize & sizeof(int)) != 0)
         {
             *(uint *)data = *(uint *)read;
         }
         stream.UnsafeAddLength(type.FieldSerializeSize + sizeof(int));
         stream.PrepLength();
     }
 }