コード例 #1
0
        public static YmlError ValidateYml(string content)
        {
            YmlError result = null;

            string[] lines = content.Split('\n');
            int      index1 = -1, index2 = -1, lineIndex = 1, index = 0;
            string   startStr = null;

            foreach (string line in lines)
            {
                if (!line.TrimStart().StartsWith("#"))
                {
                    if (line.IndexOf("	") != -1 && line.Substring(0, line.IndexOf("	")).IndexOf("#") == -1)
                    {
                        result       = new YmlError();
                        result.line  = lineIndex;
                        result.index = content.IndexOf("	", index);
                        result.msg   = string.Format("第{0}行,位置{1}包含Tab符", lineIndex, line.IndexOf("	"));
                        break;
                    }
                    else if (!string.IsNullOrWhiteSpace(line))
                    {
                        index2 = line.IndexOf("#");
                        if (index2 > 0)
                        {
                            startStr = line.Substring(0, index2);
                            index1   = startStr.IndexOf(":");
                            if (index1 <= 0)
                            {
                                result       = new YmlError();
                                result.line  = lineIndex;
                                result.index = index;
                                result.msg   = string.Format("第{0}行,格式不正确,缺少冒号", lineIndex);
                                break;
                            }
                        }
                        else
                        {
                            index1 = line.IndexOf(":");
                            if (index1 <= 0)
                            {
                                result       = new YmlError();
                                result.line  = lineIndex;
                                result.index = index;
                                result.msg   = string.Format("第{0}行,格式不正确,缺少冒号", lineIndex);
                                break;
                            }
                        }
                    }
                }

                lineIndex++;
                index += line.Length;
            }
            return(result);
        }
コード例 #2
0
        private bool Validate(ListViewItem item, string content)
        {
            bool     result = true;
            YmlFile  file   = (YmlFile)item.Tag;
            YmlError error  = YmlFormatUtil.ValidateYml(content);

            if (error != null)
            {
                try
                {
                    if (tabControl1.SelectedIndex == 1)
                    {
                        ymlEditor.SelectionStart = error.index - 1;
                        ymlEditor.ScrollToCaret();
                        ymlEditor.Select(error.index, 0);
                        ymlEditor.Focus();
                    }
                }
                catch { }

                MessageBox.Show(this, error.msg);
                file.correct    = false;
                item.ImageIndex = 3;

                result = false;
            }
            else
            {
                if (file.status == YmlFileState.NoModif)
                {
                    item.ImageIndex = 1;
                }
                else if (file.status == YmlFileState.Modif)
                {
                    item.ImageIndex = 2;
                }
                else if (file.status == YmlFileState.NoAsync)
                {
                    item.ImageIndex = 0;
                }
            }
            return(result);
        }