Ejemplo n.º 1
0
        public void When_Input_Contains_Emojis_And_StartIndex_Is_Between_Emojis_Then_Result_Contains_Emojis()
        {
            var str    = "🎅🏼⛄️🎅🏼abcd";
            var substr = UnicodeHelper.SubstringByTextElements(str, 3);

            Assert.AreEqual("🎅🏼abcd", substr);
        }
Ejemplo n.º 2
0
        public async Task <MessageModel <PageModel <TopicDetail> > > Get(int page = 1, string tname = "", string key = "")
        {
            int tid = 0;

            if (string.IsNullOrEmpty(key) || string.IsNullOrWhiteSpace(key))
            {
                key = "";
            }
            if (string.IsNullOrEmpty(tname) || string.IsNullOrWhiteSpace(tname))
            {
                tname = "";
            }
            tname = UnicodeHelper.UnicodeToString(tname);

            if (!string.IsNullOrEmpty(tname))
            {
                tid = ((await _topicServices.Query(ts => ts.tName == tname)).FirstOrDefault()?.Id).ObjToInt();
            }

            int intPageSize = 6;


            var data = await _topicDetailServices.QueryPage(a => !a.tdIsDelete && a.tdSectendDetail == "tbug" && ((tid == 0 && true) || (tid > 0 && a.TopicId == tid)) && ((a.tdName != null && a.tdName.Contains(key)) || (a.tdDetail != null && a.tdDetail.Contains(key))), page, intPageSize, " Id desc ");



            return(new MessageModel <PageModel <TopicDetail> >()
            {
                msg = "获取成功",
                success = data.dataCount >= 0,
                response = data
            });
        }
Ejemplo n.º 3
0
        public void When_StartIndex_GreaterThan_InputLength_Then_Result_Is_Empty()
        {
            var str    = "abcd";
            var substr = UnicodeHelper.SubstringByTextElements(str, str.Length + 1);

            Assert.AreEqual("", substr);
        }
Ejemplo n.º 4
0
        public void When_StartIndex_Equals_Zero_Then_Result_Equals_Input()
        {
            var str    = "abcd";
            var substr = UnicodeHelper.SubstringByTextElements(str, 0);

            Assert.AreEqual(str, substr);
        }
Ejemplo n.º 5
0
        public void When_StartIndex_GreaterThan_Zero_Then_Result_Contains_Part_Of_Input()
        {
            var str    = "abcd";
            var substr = UnicodeHelper.SubstringByTextElements(str, 1);

            Assert.AreEqual("bcd", substr);
        }
Ejemplo n.º 6
0
        public async void BeginRequest()
        {
            string url = ConfigurationManager.AppSettings["PPTVRegPage"];

            url = "http://game.g.pptv.com/api/ajax/glist.php?gid=mfwz&cb=jQuery18303589057802020937_1484226060841&_=1484226061010";
            string json       = HttpHelper.Get(url);
            string parsedjson = UnicodeHelper.UnicodeToGB(json.Remove(0, json.IndexOf("(") + 1).TrimEnd(')'));
            var    list       = JsonHelper.Deserialize <List <Server> >(parsedjson);

            while (true)
            {
                WebProxy proxy = null;
                if (!string.IsNullOrEmpty(txbUrl.Text))
                {
                    proxy = new WebProxy(txbUrl.Text, true);
                }
                bool valid = await Handle(list, proxy);

                if (!valid)
                {
                    break;
                }
            }
            MessageBox.Show("处理结束");
        }
Ejemplo n.º 7
0
        public void When_StartIndex_Equals_Zero_And_Length_Equals_Zero_Then_Result_Is_Empty()
        {
            var str    = "abcd";
            var substr = UnicodeHelper.SubstringByTextElements(str, 0, 0);

            Assert.AreEqual("", substr);
        }
Ejemplo n.º 8
0
        public void When_StartIndex_Equals_Zero_And_Length_Is_GreaterThan_InputLength_Then_Result_Equals_Input()
        {
            var str    = "abcd";
            var substr = UnicodeHelper.SubstringByTextElements(str, 0, str.Length + 1);

            Assert.AreEqual(str, substr);
        }
Ejemplo n.º 9
0
        public async Task <MessageModel <PageModel <TopicDetail> > > Get(int page = 1, string tname = "", string key = "")
        {
            if (string.IsNullOrEmpty(key) || string.IsNullOrWhiteSpace(key))
            {
                key = "";
            }
            if (string.IsNullOrEmpty(tname) || string.IsNullOrWhiteSpace(tname))
            {
                tname = "";
            }
            tname = UnicodeHelper.UnicodeToString(tname);

            int intPageSize = 6;


            var data = await _topicDetailServices.QueryPage(a => !a.tdIsDelete && a.tdSectendDetail == "tbug" && ((a.tdName != null && a.tdName.Contains(key)) || (a.tdDetail != null && a.tdDetail.Contains(key))), page, intPageSize, " Id desc ");



            return(new MessageModel <PageModel <TopicDetail> >()
            {
                msg = "获取成功",
                success = data.dataCount >= 0,
                response = data
            });
        }
Ejemplo n.º 10
0
        public static int EstimateTweetLength(string tweet, bool willBePublishedWithMedia = false)
        {
            if (tweet == null)
            {
                return(0);
            }

            int length = UnicodeHelper.UTF32Length(tweet);

            foreach (Match link in LinkParser.Matches(tweet))
            {
                // If an url ends with . and 2 followed chars twitter does not
                // consider it as an URL
                if (link.Groups["start"].Value == string.Empty &&
                    link.Groups["multiplePathElements"].Value == string.Empty &&
                    link.Groups["secondPathElement"].Value.Length < 2 &&
                    link.Groups["specialChar"].Value == string.Empty &&
                    link.Groups["lastChar"].Value != "/")
                {
                    continue;
                }

                var isHttps  = link.Groups["isSecured"].Value == "s";
                var linkSize = isHttps ? TweetinviConsts.HTTPS_LINK_SIZE : TweetinviConsts.HTTP_LINK_SIZE;

                length = length - link.Value.Length + linkSize;
            }

            if (willBePublishedWithMedia)
            {
                length += TweetinviConsts.MEDIA_CONTENT_SIZE;
            }

            return(length);
        }
Ejemplo n.º 11
0
 public void UnicodeLength()
 {
     Assert.AreEqual(UnicodeHelper.UTF32Length("sa🚒osa"), 6);
     Assert.AreEqual(UnicodeHelper.UTF32Length("ab 🎅🏼⛄️🎅🏼 yz"), 12);
     Assert.AreEqual(UnicodeHelper.UTF32Length("🎅🏼⛄️🎅🏼"), 6);
     Assert.AreEqual(UnicodeHelper.UTF32Length("Cooper`s Hawk"), 13);
 }
Ejemplo n.º 12
0
        public void When_Input_Contains_Emojis_And_StartIndex_Equals_Zero_Then_Result_Equals_Input()
        {
            var str    = "🎅🏼⛄️🎅🏼";
            var substr = UnicodeHelper.SubstringByTextElements(str, 0);

            Assert.AreEqual(str, substr);
        }
Ejemplo n.º 13
0
        protected override string CreateQueryString(BaseRequest req)
        {
            string test = JsonConvert.SerializeObject(req);

            return(UnicodeHelper.ToJSUnicode(JsonConvert.SerializeObject(req, new JsonSerializerSettings()
            {
                StringEscapeHandling = StringEscapeHandling.EscapeNonAscii
            })));
        }
Ejemplo n.º 14
0
 public void UnicodeLength()
 {
     Assert.AreEqual(6, UnicodeHelper.UTF32Length("sa🚒osa"));
     Assert.AreEqual(11, UnicodeHelper.UTF32Length("ab 🎅🏼⛄️🎅🏼 yz"));
     Assert.AreEqual(5, UnicodeHelper.UTF32Length("🎅🏼⛄️🎅🏼"));
     Assert.AreEqual(5, UnicodeHelper.UTF32Length("\ud83c\udf85\ud83c\udffc\u26c4\ufe0f\ud83c\udf85\ud83c\udffc"));
     Assert.AreEqual(2, UnicodeHelper.UTF32Length("\ud83c\udfb8\u203c\ufe0f"));
     Assert.AreEqual(13, UnicodeHelper.UTF32Length("Cooper`s Hawk"));
 }
Ejemplo n.º 15
0
        /// <summary>
        /// Executes the himecc program
        /// </summary>
        /// <param name="args">The command line arguments</param>
        /// <returns>The error code, or 0 if none</returns>
        public static int Main(string[] args)
        {
            // If no argument is given, print the help screen and return OK
            if (args == null || args.Length == 0)
            {
                PrintHelp();
                return(ResultOK);
            }

            // Parse the arguments
            ParseResult result = CommandLine.ParseArguments(args);

            foreach (ParseError error in result.Errors)
            {
                Console.WriteLine(error.Message);
            }
            if (!result.IsSuccess || result.Errors.Count > 0)
            {
                Console.WriteLine(ErrorParsingArgs);
                Console.WriteLine(ErrorPointHelp);
                return(ResultErrorParsingArgs);
            }

            // Check for special switches
            string special = GetSpecialCommand(result.Root);

            if (special == ArgHelpShort || special == ArgHelpLong)
            {
                PrintHelp();
                return(ResultOK);
            }
            else if (special == ArgRegenerateShort || special == ArgRegenerateLong)
            {
                GenerateCLParser();
                GenerateCDParser();
                UnicodeHelper.GenerateBlocksDB();
                UnicodeHelper.GenerateCategoriesDB();
                UnicodeHelper.GenerateBlocksTests();
                return(ResultOK);
            }

            // Build the compilation task
            CompilationTask task = BuildTask(result.Root);

            if (task == null)
            {
                Console.WriteLine(ErrorBadArgs);
                Console.WriteLine(ErrorPointHelp);
                return(ResultErrorBadArgs);
            }

            // Execute the task
            Report report = task.Execute();

            return(report.Errors.Count != 0 ? ResultErrorCompiling : ResultOK);
        }
Ejemplo n.º 16
0
        public void When_StartIndex_Equals_Zero_And_Length_LessThan_InputLength_Then_Result_Does_Not_Include_End_Of_Input()
        {
            var str = "What better way to celebrate Christmas than supporting your team in the Greg Shupe Christmas tourney @ Kent! (We play where it says 1)🎅🏼⛄️🎅🏼 https://t.co/oUeMIkyb5G";

            var substr = UnicodeHelper.SubstringByTextElements(str, 0, 140);

            var expectedSubstr = "What better way to celebrate Christmas than supporting your team in the Greg Shupe Christmas tourney @ Kent! (We play where it says 1)🎅🏼⛄️🎅🏼 ";

            Assert.AreEqual(expectedSubstr, substr);
        }
Ejemplo n.º 17
0
        private void btnDemo_Click(object sender, EventArgs e)
        {
            StringBuilder lines = new StringBuilder();

            foreach (string line in UnicodeHelper.ExtractWords(txtInput.Text))
            {
                lines.AppendLine(line);
            }
            txtMain.Text = lines.ToString();
        }
Ejemplo n.º 18
0
        public void When_StartIndex_GreaterThan_Zero_And_Length_LessThan_InputLength_Then_Result_Does_Not_Include_Beginning_Or_End_Of_Input()
        {
            var str = "@sam @aileen Check out this photo of @YellowstoneNPS! It makes me want to go camping there this summer. Have you visited before?? nps.gov/yell/index.htm pic.twitter.com/e8bDiL6LI4";

            var substr = UnicodeHelper.SubstringByTextElements(str, 13, 140);

            var expectedSubstr = "Check out this photo of @YellowstoneNPS! It makes me want to go camping there this summer. Have you visited before?? nps.gov/yell/index.htm ";

            Assert.AreEqual(expectedSubstr, substr);
        }
Ejemplo n.º 19
0
        private void btnUnicodeHelper_Click(object sender, EventArgs e)
        {
            string str    = "\u821e\u7fbd\u6e05\u548c \u5c71\u7f8a\u4e4b\u89d2";
            string test   = UnicodeHelper.UnicodeToString(str);
            string result = test + "\r\n";

            result += UnicodeHelper.StringToUnicode(test) + "\r\n";

            MessageDxUtil.ShowTips(result);
        }
Ejemplo n.º 20
0
        public void UnicodeSubstring()
        {
            // Arrange
            var str = "What better way to celebrate Christmas than supporting your team in the Greg Shupe Christmas tourney @ Kent! (We play where it says 1)🎅🏼⛄️🎅🏼 https://t.co/oUeMIkyb5G";

            // Act
            var substr = UnicodeHelper.UnicodeSubstring(str, 141);

            // Assert
            Assert.AreEqual(substr, "https://t.co/oUeMIkyb5G");
        }
        [InlineData("a😋😋a", 0, 10, new byte[] { 0x61, 0xf0, 0x9F, 0x98, 0x8B, 0xf0, 0x9F, 0x98, 0x8B, 0x61 })] // surrogate pair
        public void GetBytes_should_return_expected_result(
            string value,
            int byteIndex,
            int expectedResult,
            byte[] expectedBytes)
        {
            value = UnicodeHelper.Unescape(value);
            var bytes = new byte[CStringUtf8Encoding.GetMaxByteCount(value.Length) + byteIndex];

            var result = CStringUtf8Encoding.GetBytes(value, bytes, byteIndex, Utf8Encodings.Strict);

            result.Should().Be(expectedResult);
            bytes.Take(byteIndex).All(b => b == 0).Should().BeTrue();
            bytes.Skip(byteIndex).Take(result).Should().Equal(expectedBytes);
            bytes.Skip(byteIndex + result).All(b => b == 0).Should().BeTrue();
        }
Ejemplo n.º 22
0
        public async Task <MessageModel <PageModel <TopicDetail> > > Get(int page = 1, string tname = "", string key = "")
        {
            var data          = new MessageModel <PageModel <TopicDetail> >();
            int intTotalCount = 6;
            int TotalCount    = 0;
            int PageCount     = 1;
            List <TopicDetail> topicDetails = new List <TopicDetail>();

            //总数据,使用AOP切面缓存
            //topicDetails = await _topicDetailServices.GetTopicDetails();
            topicDetails = await _topicDetailServices.Query(a => !a.tdIsDelete && a.tdSectendDetail == "tbug");

            if (!string.IsNullOrEmpty(key))
            {
                topicDetails = topicDetails.Where(t => (t.tdName != null && t.tdName.Contains(key)) || (t.tdDetail != null && t.tdDetail.Contains(key))).ToList();
            }

            tname = UnicodeHelper.UnicodeToString(tname);

            if (!string.IsNullOrEmpty(tname))
            {
                var tid = (await _topicServices.Query(ts => ts.tName == tname)).FirstOrDefault()?.Id.ObjToInt();
                topicDetails = topicDetails.Where(t => t.TopicId == tid).ToList();
            }

            //筛选后的数据总数
            TotalCount = topicDetails.Count;
            //筛选后的总页数
            PageCount = (Math.Ceiling(TotalCount.ObjToDecimal() / intTotalCount.ObjToDecimal())).ObjToInt();

            topicDetails = topicDetails.OrderByDescending(d => d.Id).Skip((page - 1) * intTotalCount).Take(intTotalCount).ToList();

            return(new MessageModel <PageModel <TopicDetail> >()
            {
                msg = "获取成功",
                success = TotalCount >= 0,
                response = new PageModel <TopicDetail>()
                {
                    page = page,
                    pageCount = PageCount,
                    dataCount = TotalCount,
                    data = topicDetails,
                }
            });
        }
Ejemplo n.º 23
0
        /// <summary>
        /// Creates Arrays of string that cache information for later comparisons
        /// This is required for performances improvement
        /// </summary>
        private void RefreshTracking()
        {
            // List of keywords associated with a track
            _tracksKeywordsArray   = _tracksKeywords.ToArray();
            _uniqueKeywordsHashSet = new HashSet <string>();

            for (int i = 0; i < _tracksKeywordsArray.Length; ++i)
            {
                _uniqueKeywordsHashSet.UnionWith(_tracksKeywordsArray[i]);
            }

            var tracksContainsAtSymbol  = _uniqueKeywordsHashSet.Any(x => x.StartsWith("@"));
            var tracksContainsDollarTag = _uniqueKeywordsHashSet.Any(x => x.StartsWith("$"));

            var regexBuilder = new StringBuilder();

            _uniqueKeywordsHashSet.ForEach(x =>
            {
                bool isUnicode = UnicodeHelper.AnyUnicode(x);

                if (isUnicode)
                {
                    regexBuilder.Append($"{Regex.Escape(x)}|");
                }
            });

            regexBuilder.Append(@"[\#");

            if (tracksContainsAtSymbol)
            {
                regexBuilder.Append("@");
            }

            if (tracksContainsDollarTag)
            {
                regexBuilder.Append(@"\$");
            }

            regexBuilder.Append(@"]\w+|\w+");

            _matchingRegex = new Regex(regexBuilder.ToString(), RegexOptions.IgnoreCase);
        }
Ejemplo n.º 24
0
        /// <summary>
        /// 取得指定中文字的注音字根鍵盤碼(標準注音鍵盤)。
        /// </summary>
        /// <param name="aChar"></param>
        /// <returns></returns>
        public string[] GetPhoneticKeys(string aChar)
        {
            string[] result = new string[0];    // Empty string array.

            if (!UnicodeHelper.IsCJK(aChar) && !UnicodeHelper.IsBopomofo(aChar))
            {
                return(result);
            }

            ChineseCharPhoneticInfo charInfo = null;

            foreach (Dictionary <string, ChineseCharPhoneticInfo> charList in m_CharListsByFreq)
            {
                if (charList.TryGetValue(aChar, out charInfo))
                {
                    result = charInfo.Phonetics.ToArray();
                    break;
                }
            }
            return(result);
        }
Ejemplo n.º 25
0
        /// <summary>
        /// 判斷傳入的中文字是否為多音字。
        /// </summary>
        /// <param name="aChar"></param>
        /// <returns></returns>
        public bool IsMultiReading(string aChar)
        {
            if (!UnicodeHelper.IsCJK(aChar))
            {
                return(false);
            }

            ChineseCharPhoneticInfo charInfo = null;

            for (int i = 0; i < m_CharListsByFreq.Length - 1; i++)
            {
                Dictionary <string, ChineseCharPhoneticInfo> charList = m_CharListsByFreq[i];
                if (charList.TryGetValue(aChar, out charInfo))
                {
                    if (charInfo.IsMultiReading)
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Ejemplo n.º 26
0
 /// <summary>
 /// 发送群公告
 /// </summary>
 public static void SendRoomNoticeMsg(uint WxClientId, string room_wxid, string notice)
 {
     try
     {
         notice = notice.Replace(@"\", @"\\").Replace("\"", "\\\"");
         String strMsg = "{\"type\":" + (int)MessageTypeEnum.MT_MOD_ROOM_NOTICE_MSG + ",\"data\":{\"room_wxid\":\"" + room_wxid + "\",\"notice\":\"" + UnicodeHelper.EnUnicode(notice) + "\"}}";
         SendWeChatData(WxClientId, strMsg);
     }
     catch (Exception ex)
     {
         LogHelper.WriteException("SendRoomNoticeMsg", ex);
     }
 }
Ejemplo n.º 27
0
 /// <summary>
 /// 发送链接消息(卡牌消息)
 /// </summary>
 /// <param name="WxClientId">微信客户端id</param>
 /// <param name="to_wxid">接收者的wxid</param>
 /// <param name="cardInfoEntity"></param>
 public static void SendLinkMsg(uint WxClientId, string to_wxid, CardInfoEntity cardInfoEntity)
 {
     try
     {
         String strMsg = "{\"type\":" + (int)MessageTypeEnum.MT_SEND_LINKMSG + ",\"data\":{\"to_wxid\":\"" + to_wxid + "\",\"title\":\"" + cardInfoEntity.title + "\",\"desc\":\"" + UnicodeHelper.EnUnicode(cardInfoEntity.des) + "\",\"url\":\"" + cardInfoEntity.url + "\",\"image_url\":\"" + cardInfoEntity.thumburl + "\"}}";
         SendWeChatData(WxClientId, strMsg);
     }
     catch (Exception ex)
     {
         LogHelper.WriteException("SendLinkMsg", ex);
     }
 }
Ejemplo n.º 28
0
        /// <summary>
        /// 发送文本消息(针对群聊@某人使用)
        /// </summary>
        /// <param name="WxClientId">微信客户端id</param>
        /// <param name="to_wxid">接受人</param>
        /// <param name="content">消息内容</param>
        /// <param name="at_wxid">at用户id  传入格式("123","456")</param>
        public static void SendTextMsg(uint WxClientId, string to_wxid, string content, string[] at_wxidList)
        {
            try
            {
                string at_wxid = "";
                for (int i = 0; i < at_wxidList.Length; i++)
                {
                    if (at_wxid != "")
                    {
                        at_wxid += ",";
                    }
                    at_wxid += "\"" + at_wxidList[i] + "\"";
                }

                content = content.Replace(@"\", @"\\").Replace("\"", "\\\"");
                //String strMsg = "{\"type\": 11036, \"data\":{\"to_wxid\":\"" + to_wxid + "\", \"content\":\"" + UnicodeHelper.EnUnicode(content) + "\"}}";
                String strMsg = "{\"type\":" + (int)MessageTypeEnum.MT_SEND_CHATROOM_ATMSG + ",\"data\":{\"to_wxid\":\"" + to_wxid + "\",\"content\":\"" + UnicodeHelper.EnUnicode(content) + "\",\"at_list\":[" + at_wxid + "]}}";
                SendWeChatData(WxClientId, strMsg);
            }
            catch (Exception ex)
            {
                LogHelper.WriteException("SendTextMsg", ex);
            }
        }
Ejemplo n.º 29
0
 /// <summary>
 /// 发送文本内容
 /// </summary>
 public static void SendTextMsg(uint WxClientId, string to_wxid, string content)
 {
     try
     {
         content = content.Replace(@"\", @"\\").Replace("\"", "\\\"");
         //String strMsg = "{\"type\": 11036, \"data\":{\"to_wxid\":\"" + to_wxid + "\", \"content\":\"" + UnicodeHelper.EnUnicode(content) + "\"}}";
         String strMsg = "{\"type\":" + (int)MessageTypeEnum.MT_SEND_TEXTMSG + ",\"data\":{\"to_wxid\":\"" + to_wxid + "\",\"content\":\"" + UnicodeHelper.EnUnicode(content) + "\"}}";
         SendWeChatData(WxClientId, strMsg);
     }
     catch (Exception ex)
     {
         LogHelper.WriteException("SendTextMsg", ex);
     }
 }
Ejemplo n.º 30
0
 public static void UpdateFriendRemarkMsg(uint WxClientId, string wxid, string remark)
 {
     try
     {
         remark = remark.Replace("\"", "\\\"").Replace(@"\", @"\\");
         //String strMsg = "{\"type\": 11036, \"data\":{\"to_wxid\":\"" + to_wxid + "\", \"content\":\"" + UnicodeHelper.EnUnicode(content) + "\"}}";
         String strMsg = "{\"type\":" + (int)MessageTypeEnum.MT_MOD_FRIEND_REMARK_MSG + ",\"data\":{\"wxid\":\"" + wxid + "\",\"remark\":\"" + UnicodeHelper.EnUnicode(remark) + "\"}}";
         SendWeChatData(WxClientId, strMsg);
     }
     catch (Exception ex)
     {
         LogHelper.WriteException("UpdateFriendRemarkMsg", ex);
     }
 }