示例#1
0
    //GET请求
    IEnumerator GET(string url)
    {
        WWW www = new WWW(url);

        yield return(www);

        if (www.error != null)
        {
            //GET请求失败
            Debug.Log("error is :" + www.error);
        }
        else
        {
            //GET请求成功
            Debug.Log("request ok : " + www.text);
            // 解析base64数据
            string decodeMessage = UnicodeConverter.base64decode(www.text);
            string utf8Message   = UnicodeConverter.utf8to16(decodeMessage);
            Debug.Log("data : " + utf8Message);
            // json 数据解析  -->   ws 转
            // 数据 websocket操作
            // 获取网关服务器地址,建立长链接!
            // 启动心跳测试
            // 主要测试消息流程等
        }
    }
示例#2
0
 private static int WriteUtf16CodePoint(
     char *begin, char *end,
     byte *dest)
 {
     return(UnicodeConverter.WriteUtf8CodePoint(
                UnicodeConverter.ReadUtf16CodePoint(ref begin, end),
                dest));
 }
示例#3
0
    private void showList()
    {
        StringBuilder navi_tmp = new StringBuilder("");

        if (tag != "")
        {
            tag_decode       = UnicodeConverter.ToGB2312(tag);
            ltlnewsnavi.Text = tag_decode;
        }
        else
        {
            Response.Redirect("news_sublist_0_1.html");
        }
    }
示例#4
0
        /// <summary>
        /// Creates a string from the given null-terminated string
        /// of UTF-8 encoded characters.
        /// </summary>
        /// <param name="buffer">The buffer that contains the string.</param>
        /// <returns>A string.</returns>
        internal static unsafe string FromCString(byte *buffer)
        {
            int utf8Length  = (int)CStringHelpers.StringLength(buffer);
            var utf16Buffer = new char[utf8Length];

            var bufEnd      = buffer + utf8Length;
            int utf16Length = 0;

            while (buffer != bufEnd)
            {
                utf16Length += UnicodeConverter.WriteUtf16CodePoint(
                    UnicodeConverter.ReadUtf8CodePoint(ref buffer, bufEnd),
                    &utf16Buffer[utf16Length]);
            }

            return(new String(utf16Buffer, 0, utf16Length));
        }
示例#5
0
        /// <summary>
        /// Allocates an unmanaged buffer and fills it with this string's contents,
        /// re-encoded as UTF-8. The resulting buffer is terminated by the null
        /// terminator character. The caller is responsible for freeing the buffer
        /// when it's done using it.
        /// </summary>
        /// <param name="str">The string to convert to a C-style string.</param>
        /// <returns>A C-style string for which the caller is responsible.</returns>
        internal static unsafe byte *ToCString(string str)
        {
            char *beginPtr   = str.DataPointer;
            char *endPtr     = beginPtr + str.Length;
            var   utf8Length = UnicodeConverter.GetUtf16ToUtf8BufferLength(beginPtr, endPtr);

            byte *cStr   = (byte *)Marshal.AllocHGlobal(utf8Length + 1);
            int   offset = 0;

            while (beginPtr != endPtr)
            {
                offset += UnicodeConverter.WriteUtf8CodePoint(
                    UnicodeConverter.ReadUtf16CodePoint(ref beginPtr, endPtr),
                    &cStr[offset]);
            }
            cStr[offset] = (byte)'\0';
            return(cStr);
        }
示例#6
0
    private void showDetail()
    {
        if (!IsPostBack)
        {
            SqlDataReader reader = SqlHelper.ExecuteReader("select * from news where id=" + news_id);
            while (reader.Read())
            {
                StringBuilder sb_head    = new StringBuilder("");
                StringBuilder sb_subhead = new StringBuilder("");
                StringBuilder sb_content = new StringBuilder("");
                StringBuilder sb_tags    = new StringBuilder("");
                sb_head.Append(reader["title"].ToString().Trim());
                sb_subhead.Append("文章来源:" + reader["source"].ToString().Trim() + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;发布时间:" + Convert.ToDateTime(reader["date"].ToString().Trim()).ToString("yyyy年MM月dd日") + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;点击数:" + reader["hittime"].ToString().Trim() + "次");
                sb_content.Append(reader["detail"].ToString().Trim());

                string        content         = sb_content.ToString();
                SqlDataReader reader_keywords = SqlHelper.ExecuteReader("select * from keywords");
                while (reader_keywords.Read())
                {
                    Regex r = new Regex(reader_keywords["name"].ToString().Trim());
                    content = r.Replace(content, "<a href=\"" + reader_keywords["url"].ToString().Trim() + "\">" + reader_keywords["name"].ToString().Trim() + "</a>", 1);
                }
                reader_keywords.Close();

                StringBuilder sb_taglink = new StringBuilder("");
                sb_tags.Append(reader["tags"].ToString().Trim());
                string[] tag = sb_tags.ToString().Split(new char[] { ';' });
                for (int i = 0; i < tag.Length; i++)
                {
                    sb_taglink.Append("&nbsp;&nbsp;<a href=\"news_tags_" + UnicodeConverter.ToUnicode(tag[i]) + "_page1.html\">" + tag[i] + "</a>");// UnicodeConverter.ToUnicode(tag[i])
                }
                ltlhead.Text    = sb_head.ToString();
                ltlsubhead.Text = sb_subhead.ToString();
                ltlcontent.Text = content;
                ltltags.Text    = sb_taglink.ToString();
                Page.Title      = reader["title"] + "——华樱出国_新闻资讯";

                //面包屑导航栏
                class_id = int.Parse(reader["type"].ToString().Trim());
                StringBuilder navi_tmp = new StringBuilder("");
                switch (class_id)
                {
                case 0:
                    break;

                case 1:
                    navi_tmp.Append("<a href=\"news_sublist.aspx?type=1\">雅思快讯</a>");
                    break;

                case 2:
                    navi_tmp.Append("<a href=\"news_sublist.aspx?type=2\">托福快讯</a>");
                    break;

                case 3:
                    navi_tmp.Append("<a href=\"news_sublist.aspx?type=3\">SAT考试</a>");
                    break;

                case 4:
                    navi_tmp.Append("<a href=\"news_sublist.aspx?type=4\">留学咨询</a>");
                    break;
                }
                ltlnewsnavi.Text = navi_tmp.ToString();
            }
            reader.Close();
        }
    }
示例#7
0
        private int GetCharsImpl(
            byte[] bytes, int byteIndex, int byteCount,
            char[] chars, int charIndex)
        {
            // TODO: the logic in this algorithm is non-trivial. We should
            // test UTF8Decoder extensively.

            // TODO: check that we're not overflowing any of these buffers here.

            int   numCharsParsed        = 0;
            byte *curPtr                = &bytes[byteIndex];
            byte *endPtr                = &bytes[byteIndex + byteCount];
            byte *undecodedByteStartPtr = &undecodedBytes[0];
            byte *undecodedBytePtr;
            bool  eofReached;

            if (HasUndecodedBytes)
            {
                // Try to parse undecoded bytes by appending decoded bytes.

                int newUndecodedByteCount = Math.Min(undecodedByteCount + byteCount, undecodedBytes.Length);
                for (int i = undecodedByteCount; i < newUndecodedByteCount; i++)
                {
                    undecodedBytes[i] = curPtr[i - undecodedByteCount];
                }

                undecodedBytePtr = undecodedByteStartPtr;
                byte *undecodedByteEndPtr = undecodedBytePtr + newUndecodedByteCount;
                uint  codePoint           = UnicodeConverter.ReadUtf8CodePoint(
                    ref undecodedBytePtr, undecodedByteEndPtr, out eofReached);

                if (eofReached)
                {
                    // We don't have enough new bytes to decode a code point.
                    undecodedByteCount = newUndecodedByteCount;
                    return(0);
                }

                // We can compute the total number of *new* bytes we've decoded by first
                // computing the total number of bytes decoded `undecodedByteEndPtr - undecodedBytePtr`
                // and the subtracting the number of undecoded bytes.
                long numNewBytesDecoded = (long)undecodedByteEndPtr - (long)undecodedBytePtr - undecodedByteCount;
                curPtr            += numNewBytesDecoded;
                numCharsParsed    += WriteToCharBuffer(codePoint, chars, charIndex + numCharsParsed);
                undecodedByteCount = 0;
            }

            while (curPtr != endPtr)
            {
                byte *oldCurPtr = curPtr;
                uint  codePoint = UnicodeConverter.ReadUtf8CodePoint(
                    ref curPtr, endPtr, out eofReached);

                if (eofReached)
                {
                    // Stop trying to parse code points; move the rest of the data into
                    // the undecoded bytes buffer.
                    curPtr = oldCurPtr;
                    break;
                }

                numCharsParsed += WriteToCharBuffer(codePoint, chars, charIndex + numCharsParsed);
            }

            // Copy undecoded bytes to the undecoded byte buffer.
            undecodedBytePtr   = undecodedByteStartPtr;
            undecodedByteCount = 0;
            while (curPtr != endPtr)
            {
                *undecodedBytePtr = *curPtr;
                undecodedBytePtr++;
                curPtr++;
                undecodedByteCount++;
            }

            return(numCharsParsed);
        }
示例#8
0
 private static int WriteToCharBuffer(uint codePoint, char[] buffer, int offset)
 {
     return(UnicodeConverter.WriteUtf16CodePoint(codePoint, buffer == null ? null : &buffer[offset]));
 }