Ejemplo n.º 1
0
        public static string Process(string toProcess, IProgress <string> progress)
        {
            if (string.IsNullOrWhiteSpace(toProcess))
            {
                return(string.Empty);
            }

            progress?.Report("Searching for Line Codes...");

            var resultList = BracketCodeCommon.ContentBracketCodeMatches(toProcess, BracketCodeToken);

            if (!resultList.Any())
            {
                return(toProcess);
            }

            var context = Db.Context().Result;

            foreach (var loopMatch in resultList)
            {
                var dbContent = context.LineContents.FirstOrDefault(x => x.ContentId == loopMatch.contentGuid);
                if (dbContent == null)
                {
                    continue;
                }

                progress?.Report($"Adding Line {dbContent.Title} from Code");

                toProcess = toProcess.Replace(loopMatch.bracketCodeText, LineParts.LineDivAndScript(dbContent));
            }

            return(toProcess);
        }
Ejemplo n.º 2
0
 public void Remove()
 {
     if (SupportPoints.Any())
     {
         SupportPoints.RemoveAt(SupportPoints.Count - 1);
     }
     if (LineParts.Any())
     {
         LineParts.RemoveAt(LineParts.Count - 1);
     }
 }
Ejemplo n.º 3
0
        public bool Add(IFillerVertex supportPoint)
        {
            if (supportPoint.Equals(First))
            {
                LineParts.Add(GetFillerLine(Last, First));
                return(true);
            }
            else
            {
                SupportPoints.Add(supportPoint);
                if (VertexCount >= 2)
                {
                    LineParts.Add(GetFillerLine(Prev, Last));
                }

                return(false);
            }
        }
Ejemplo n.º 4
0
        private KeyValuePair <string, string>?ParseLine(int lineNo, string line)
        {
            // allow, but ignore, 'export ' line prefix
            // to support files that can be loaded via source command in the shell
            if (line.StartsWith("export "))
            {
                line = line.Substring(7).TrimStart();
            }

            LineParts parts = SplitLine(line);

            if (parts.SeparatorIndex < 0)
            {
                if (_skipParseErrors)
                {
                    return(null);
                }
                throw new ParseException(parts.SeparatorIndex, lineNo, "key/value separator (= or :) was not found");
            }

            if (parts.Key.Length == 0)
            {
                if (_skipParseErrors)
                {
                    return(null);
                }
                throw new ParseException(0, lineNo, "key name was not specified");
            }

            if (parts.IsQuoted() && parts.EndQuoteIndex <= parts.StartQuoteIndex)
            {
                if (_skipParseErrors)
                {
                    return(null);
                }
                throw new ParseException(parts.SeparatorIndex + 1, lineNo, $"value for key '{parts.Key}' is missing a closing quote");
            }

            if (parts.IsDoubleQuoted())
            {
                parts.Value = Regex.Unescape(parts.Value);
            }
            return(new KeyValuePair <string, string>(parts.Key, parts.Value));
        }
Ejemplo n.º 5
0
        private LineParts SplitLine(string line)
        {
            var parts = new LineParts();

            // split key value pairs on '=' or ':'
            parts.SeparatorIndex = line.IndexOfAny(new [] { '=', ':' });
            if (parts.SeparatorIndex >= 0)
            {
                parts.SeparatorChar = line.Substring(parts.SeparatorIndex, 1)[0];

                parts.Key   = line.Substring(0, parts.SeparatorIndex).Trim();
                parts.Value = line.Substring(parts.SeparatorIndex + 1).Trim();

                if (parts.Value.Length > 0)
                {
                    char startChar = parts.Value[0];
                    if ('"' == startChar || '\'' == startChar)
                    {
                        parts.StartQuoteIndex = 0;
                        parts.QuoteChar       = startChar;
                        parts.EndQuoteIndex   = parts.Value.IndexOfAny(new [] { '"', '\'' }, 1);
                        if (parts.EndQuoteIndex > 0)
                        {
                            parts.Value = parts.Value.Substring(1, parts.EndQuoteIndex - 1);
                        }
                    }
                    else
                    {
                        // strip trailing comment, if any, from value
                        int commentIndex = parts.Value.IndexOf('#');
                        if (commentIndex >= 0)
                        {
                            parts.Value = parts.Value.Substring(0, commentIndex).Trim();
                        }
                    }
                }
            }
            return(parts);
        }