예제 #1
0
            internal static bool IsValidValue(Type type, string value)
            {
                if (type == typeof(string))
                {
                    if (value.StartsWith("--")) // can't be long option
                    {
                        return(false);
                    }
                    if (value.StartsWith("-"))                 // can't be short option
                    {
                        return(CStringUtils.IsNumeric(value)); // but can be a negative number
                    }
                    if (value.Equals("&&") || value.Equals("||"))
                    {
                        return(false);
                    }

                    return(value.Length > 0); // can't be empty
                }

                if (type == typeof(int))
                {
                    return(CStringUtils.IsInteger(value));
                }

                if (type == typeof(float))
                {
                    return(CStringUtils.IsNumeric(value));
                }

                return(false);
            }
예제 #2
0
        private void CheckValue(Option opt, object value)
        {
            if (opt.Values != null)
            {
                foreach (object v in opt.Values)
                {
                    if (v.Equals(value))
                    {
                        return;
                    }
                }

                string optionDesc = opt.ShortName != null?
                                    CStringUtils.TryFormat("--{0}(-{1})", opt.Name, opt.ShortName) :
                                        CStringUtils.TryFormat("--{0}", opt.Name);

                StringBuilder buffer = new StringBuilder();
                buffer.AppendFormat("Invalid value '{0}' for option {1}\n", value, optionDesc);
                buffer.Append("Valid values:");
                foreach (object v in opt.Values)
                {
                    buffer.Append("\n• ");
                    buffer.Append(v);
                }

                throw new CCommandException(buffer.ToString());
            }
        }
        private static string GetNewLine(string line, string[] suggestions)
        {
            if (suggestions.Length == 0)
            {
                return(null);
            }

            string token = GetToken(line);

            if (token == null)
            {
                return(null);
            }

            if (suggestions.Length == 1)
            {
                return(ReplaceToken(line, token, CStringUtils.RemoveRichTextTags(suggestions[0])) + " ");
            }

            string suggestion = CStringUtils.GetSuggestedText(token, suggestions, true);

            if (suggestion == null || suggestion.Equals(token))
            {
                return(null);
            }

            return(ReplaceToken(line, token, suggestion));
        }
예제 #4
0
 public static void w <A0, A1, A2>(bool condition, CTag tag, string format, A0 arg0, A1 arg1, A2 arg2)
 {
     if (condition && ShouldLogLevel(CLogLevel.Warn) && ShouldLogTag(tag))
     {
         LogMessage(tag, CLogLevel.Warn, CStringUtils.TryFormat(format, arg0, arg1, arg2));
     }
 }
예제 #5
0
        public override Widget build(BuildContext context)
        {
            var fontSize = (int)Math.Ceiling(this.size * 0.5f);
            var name     = CStringUtils.genAvatarName(name: this.title);

            if (name.IsLetterOrNumber())
            {
                fontSize = (int)Math.Ceiling(this.size * 0.4f);
            }
            return(new Container(
                       width: this.size,
                       height: this.size,
                       alignment: Alignment.center,
                       color: CColorUtils.GetSpecificColorFromId(id: this.id),
                       child: new Container(
                           alignment: Alignment.center,
                           child: new Text(
                               CStringUtils.genAvatarName(name: this.title),
                               textAlign: TextAlign.center,
                               style: new TextStyle(
                                   color: CColors.White,
                                   height: 1.15f,
                                   fontFamily: "Roboto-Medium",
                                   fontSize: fontSize
                                   )
                               )
                           )
                       ));
        }
예제 #6
0
 public static void e(string format, params object[] args)
 {
     if (ShouldLogLevel(CLogLevel.Error))
     {
         LogMessage(null, CLogLevel.Error, CStringUtils.TryFormat(format, args));
     }
 }
예제 #7
0
 public static void e <A0>(CTag tag, string format, A0 arg0)
 {
     if (ShouldLogLevel(CLogLevel.Error) && ShouldLogTag(tag))
     {
         LogMessage(tag, CLogLevel.Error, CStringUtils.TryFormat(format, arg0));
     }
 }
예제 #8
0
 public static void w(bool condition, CTag tag, string format, params object[] args)
 {
     if (condition && ShouldLogLevel(CLogLevel.Warn) && ShouldLogTag(tag))
     {
         LogMessage(tag, CLogLevel.Warn, CStringUtils.TryFormat(format, args));
     }
 }
예제 #9
0
 public static void d <A0, A1, A2>(CTag tag, string format, A0 arg0, A1 arg1, A2 arg2)
 {
     if (ShouldLogLevel(CLogLevel.Debug) && ShouldLogTag(tag))
     {
         LogMessage(tag, CLogLevel.Debug, CStringUtils.TryFormat(format, arg0, arg1, arg2));
     }
 }
예제 #10
0
 public static void w <A0, A1, A2, A3, A4>(CTag tag, string format, A0 arg0, A1 arg1, A2 arg2, A3 arg3, A4 arg4)
 {
     if (ShouldLogLevel(CLogLevel.Warn) && ShouldLogTag(tag))
     {
         LogMessage(tag, CLogLevel.Warn, CStringUtils.TryFormat(format, arg0, arg1, arg2, arg3, arg4));
     }
 }
예제 #11
0
        private static string[] getSuggestedArgs(IList <string> values, string token)
        {
            // we need to keep suggested values in a sorted order
            List <string> sortedValues = new List <string>(values.Count);

            for (int i = 0; i < values.Count; ++i)
            {
                if (token.Length == 0 || CStringUtils.StartsWithIgnoreCase(CStringUtils.RemoveRichTextTags(values[i]), token))
                {
                    sortedValues.Add(CStringUtils.RemoveRichTextTags(values[i]));
                }
            }

            if (sortedValues.Count == 0)
            {
                return(EMPTY_SUGGESTIONS);
            }

            if (sortedValues.Count > 1)
            {
                sortedValues.Sort();
                return(sortedValues.ToArray());
            }

            return(singleSuggestion(sortedValues[0]));
        }
예제 #12
0
 public static void w <A0, A1>(string format, A0 arg0, A1 arg1)
 {
     if (ShouldLogLevel(CLogLevel.Warn))
     {
         LogMessage(null, CLogLevel.Warn, CStringUtils.TryFormat(format, arg0, arg1));
     }
 }
예제 #13
0
 public void LogTerminal(string[] table)
 {
     if (IsTrackTerminalLog)
     {
         AddResult(CStringUtils.Join(table));
     }
 }
예제 #14
0
 public static void i(CTag tag, string format, params object[] args)
 {
     if (ShouldLogLevel(CLogLevel.Info) && ShouldLogTag(tag))
     {
         LogMessage(tag, CLogLevel.Info, CStringUtils.TryFormat(format, args));
     }
 }
예제 #15
0
 public static void i <A0, A1>(bool condition, CTag tag, string format, A0 arg0, A1 arg1)
 {
     if (condition && ShouldLogLevel(CLogLevel.Info) && ShouldLogTag(tag))
     {
         LogMessage(tag, CLogLevel.Info, CStringUtils.TryFormat(format, arg0, arg1));
     }
 }
예제 #16
0
 public static void i <A0, A1, A2, A3>(CTag tag, string format, A0 arg0, A1 arg1, A2 arg2, A3 arg3)
 {
     if (ShouldLogLevel(CLogLevel.Info) && ShouldLogTag(tag))
     {
         LogMessage(tag, CLogLevel.Info, CStringUtils.TryFormat(format, arg0, arg1, arg2, arg3));
     }
 }
예제 #17
0
 public static void i <A0>(string format, A0 arg0)
 {
     if (ShouldLogLevel(CLogLevel.Info))
     {
         LogMessage(null, CLogLevel.Info, CStringUtils.TryFormat(format, arg0));
     }
 }
예제 #18
0
 public static void d <A0>(bool condition, CTag tag, string format, A0 arg0)
 {
     if (condition && ShouldLogLevel(CLogLevel.Debug) && ShouldLogTag(tag))
     {
         LogMessage(tag, CLogLevel.Debug, CStringUtils.TryFormat(format, arg0));
     }
 }
예제 #19
0
        private string FormatLine(string line, CLogLevel level, CTag tag, string stackTrace)
        {
            StringBuilder lineBuffer = new StringBuilder();

            string coloredLine = CEditorSkin.SetColors(line);

            string filename = CEditorStackTrace.ExtractFileName(stackTrace);

            if (level != null)
            {
                lineBuffer.Append("[");
                lineBuffer.Append(level.ShortName);
                lineBuffer.Append("]: ");
            }

            if (filename != null)
            {
                lineBuffer.Append(CStringUtils.C("[" + filename + "]: ", CEditorSkin.GetColor(CColorCode.Plain)));
            }

            if (tag != null)
            {
                lineBuffer.Append("[");
                lineBuffer.Append(tag.Name);
                lineBuffer.Append("]: ");
            }

            lineBuffer.Append(coloredLine);

            return(lineBuffer.ToString());
        }
예제 #20
0
 public static void w <A0, A1>(CTag tag, string format, A0 arg0, A1 arg1)
 {
     if (ShouldLogLevel(CLogLevel.Warn) && ShouldLogTag(tag))
     {
         LogMessage(tag, CLogLevel.Warn, CStringUtils.TryFormat(format, arg0, arg1));
     }
 }
예제 #21
0
        void _onShare(Article article)
        {
            var linkUrl = CStringUtils.JointProjectShareLink(projectId: article.id);

            ShareManager.showArticleShareView(
                true,
                isLoggedIn: this.widget.viewModel.isLoggedIn,
                () => {
                Clipboard.setData(new ClipboardData(text: linkUrl));
                CustomDialogUtils.showToast("复制链接成功", iconData: Icons.check_circle_outline);
            },
                () => this.widget.actionModel.pushToLogin(),
                () => this.widget.actionModel.pushToBlock(obj: article.id),
                () => this.widget.actionModel.pushToReport(arg1: article.id, arg2: ReportType.article),
                type => {
                CustomDialogUtils.showCustomDialog(
                    child: new CustomLoadingDialog()
                    );
                string imageUrl = CImageUtils.SizeTo200ImageUrl(article.thumbnail.url);
                this.widget.actionModel.shareToWechat(arg1: type, arg2: article.title,
                                                      arg3: article.subTitle, arg4: linkUrl, arg5: imageUrl)
                .Then(onResolved: CustomDialogUtils.hiddenCustomDialog)
                .Catch(_ => CustomDialogUtils.hiddenCustomDialog());
            }
                );
        }
예제 #22
0
 public static void e <A0, A1, A2>(string format, A0 arg0, A1 arg1, A2 arg2)
 {
     if (ShouldLogLevel(CLogLevel.Error))
     {
         LogMessage(null, CLogLevel.Error, CStringUtils.TryFormat(format, arg0, arg1, arg2));
     }
 }
예제 #23
0
        bool Execute(int index, string rgb)
        {
            uint value;

            try
            {
                value = Convert.ToUInt32(rgb, 16);
            }
            catch (Exception)
            {
                PrintError("Wrong color value");
                return(false);
            }

            CColorCode[] values = (CColorCode[])Enum.GetValues(typeof(CColorCode));
            if (index >= 0 && index < values.Length)
            {
                Color color = CColorUtils.FromRGB(value);
                CEditorSkin.SetColor(values[index], color);

                Print("{0}: {1}", index, CStringUtils.C(values[index].ToString(), values[index]));
            }
            else
            {
                PrintError("Wrong index");
                Execute();
            }

            return(true);
        }
 void _showShareView(IEvent eventObj)
 {
     ActionSheetUtils.showModalActionSheet(
         new ShareView(
             projectType: ProjectType.iEvent,
             onPressed: type => {
         AnalyticsManager.ClickShare(shareType: type, "Event", "Event_" + eventObj.id,
                                     title: eventObj.title);
         var linkUrl = $"{Config.unity_cn_url}/events/{eventObj.id}";
         var path    = CStringUtils.CreateMiniPath(id: eventObj.id, title: eventObj.title);
         if (type == ShareType.clipBoard)
         {
             this.widget.actionModel.copyText(obj: linkUrl);
             CustomDialogUtils.showToast("复制链接成功", iconData: Icons.check_circle_outline);
         }
         else
         {
             var imageUrl = CImageUtils.SizeTo200ImageUrl(imageUrl: eventObj.avatar);
             CustomDialogUtils.showCustomDialog(
                 child: new CustomLoadingDialog()
                 );
             this.widget.actionModel.shareToWechat(
                 arg1: type,
                 arg2: eventObj.title,
                 arg3: eventObj.shortDescription,
                 arg4: linkUrl,
                 arg5: imageUrl,
                 arg6: path)
             .Then(onResolved: CustomDialogUtils.hiddenCustomDialog)
             .Catch(_ => CustomDialogUtils.hiddenCustomDialog());
         }
     }
             )
         );
 }
예제 #25
0
        public void TestCountLineBreaksTwoLines()
        {
            string line = "line1\n" +
                          "line2";

            Assert.AreEqual(1, CStringUtils.LinesBreaksCount(line));
        }
예제 #26
0
        public void TestInsertColorsWrongLookup()
        {
            Color[] lookup =
            {
                Color.red,
                Color.green,
                Color.blue
            };

            string formatted = string.Format("{0} {1} {2}",
                                             CStringUtils.C("red", (CColorCode)0),
                                             CStringUtils.C("green", (CColorCode)1),
                                             CStringUtils.C("blue", (CColorCode)2),
                                             CStringUtils.C("yellow", (CColorCode)3)
                                             );

            string expected = string.Format("{0} {1} {2}",
                                            CStringUtils.C("red", lookup[0]),
                                            CStringUtils.C("green", lookup[1]),
                                            CStringUtils.C("blue", lookup[2]),
                                            CStringUtils.C("yellow", (CColorCode)3)
                                            );

            string actual = CStringUtils.SetColors(formatted, lookup);

            Assert.AreEqual(expected, actual);
        }
예제 #27
0
        public void TestRemoveColorTag()
        {
            string expected  = "text";
            string formatted = CStringUtils.C(expected, CColorCode.Clear);

            Assert.AreEqual(expected, CStringUtils.RemoveRichTextTags(formatted));
        }
예제 #28
0
        public void TestRemoveItalicStyleTag()
        {
            string expected  = "text";
            string formatted = CStringUtils.I(expected);

            Assert.AreEqual(expected, CStringUtils.RemoveRichTextTags(formatted));
        }
예제 #29
0
        public static CStackTraceLine[] ParseStackTrace(string stackTrace)
        {
            if (stackTrace != null)
            {
                List <CStackTraceLine> list = new List <CStackTraceLine>();

                int lineStart = 0;
                int lineEnd;

                while (lineStart < stackTrace.Length)
                {
                    // extract next line
                    lineEnd = CStringUtils.EndOfLineIndex(stackTrace, lineStart);
                    string line = stackTrace.Substring(lineStart, lineEnd - lineStart);
                    lineStart = lineEnd + 1;

                    // extract data
                    Match m;
                    if ((m = PatternUnityStackTrace.Match(line)).Success)
                    {
                        GroupCollection groups        = m.Groups;
                        string          sourcePath    = groups[2].Value;
                        string          lineNumberStr = groups[3].Value;
                        int             lineNumber    = CStringUtils.ParseInt(lineNumberStr, -1);

                        list.Add(new CStackTraceLine(line, string.IsNullOrEmpty(sourcePath) ? null : sourcePath, lineNumber, lineNumberStr.Length));
                    }
                    else if ((m = PatternSystemStackTrace.Match(line)).Success)
                    {
                        GroupCollection groups = m.Groups;

                        string method        = groups[1].Value;
                        string args          = OptimizeArgs(groups[2].Value);
                        string path          = OptimizePath(groups[4].Value);
                        string lineNumberStr = groups[5].Value;
                        int    lineNumber    = CStringUtils.ParseInt(lineNumberStr, -1);

                        if (!string.IsNullOrEmpty(path) && lineNumber != -1)
                        {
                            line = CStringUtils.TryFormat("{0}({1}) (at {2}:{3})", method, args, path, lineNumberStr);
                        }
                        else
                        {
                            line = CStringUtils.TryFormat("{0}({1})", method, args);
                        }

                        list.Add(new CStackTraceLine(line, path, lineNumber, lineNumberStr.Length));
                    }
                    else
                    {
                        list.Add(new CStackTraceLine(line));
                    }
                }

                return(list.ToArray());
            }

            return(CStackTraceLine.kEmptyLinesArray);
        }
        Widget _buildArticleCard(BuildContext context, int index)
        {
            var article = this.viewModel.articleHistory[index : index];
            var linkUrl = CStringUtils.JointProjectShareLink(projectId: article.id);

            return(CustomDismissible.builder(
                       Key.key(value: article.id),
                       new ArticleCard(
                           article: article,
                           () => this.actionModel.pushToArticleDetail(obj: article.id),
                           () => ShareManager.showArticleShareView(
                               true,
                               isLoggedIn: this.viewModel.isLoggedIn,
                               () => {
                Clipboard.setData(new ClipboardData(text: linkUrl));
                CustomDialogUtils.showToast("复制链接成功", Icons.check_circle_outline);
            },
                               () => this.actionModel.pushToLogin(),
                               () => this.actionModel.pushToBlock(article.id),
                               () => this.actionModel.pushToReport(article.id, ReportType.article),
                               type => {
                CustomDialogUtils.showCustomDialog(
                    child: new CustomLoadingDialog()
                    );
                string imageUrl = CImageUtils.SizeTo200ImageUrl(article.thumbnail.url);
                this.actionModel.shareToWechat(arg1: type, arg2: article.title,
                                               arg3: article.subTitle, arg4: linkUrl, arg5: imageUrl)
                .Then(onResolved: CustomDialogUtils.hiddenCustomDialog)
                .Catch(_ => CustomDialogUtils.hiddenCustomDialog());
            }
                               ),
                           fullName: article.fullName,
                           index == 0,
                           new ObjectKey(value: article.id)
                           ),
                       new CustomDismissibleDrawerDelegate(),
                       secondaryActions: new List <Widget> {
                new GestureDetector(
                    onTap: () => this.actionModel.deleteArticleHistory(obj: article.id),
                    child: new Container(
                        color: CColors.Separator2,
                        width: 80,
                        alignment: Alignment.center,
                        child: new Container(
                            width: 44,
                            height: 44,
                            alignment: Alignment.center,
                            decoration: new BoxDecoration(
                                CColors.White,
                                borderRadius: BorderRadius.circular(22)
                                ),
                            child: new Icon(Icons.delete_outline, size: 28, color: CColors.Error)
                            )
                        )
                    )
            },
                       controller: this._controller
                       ));
        }