Exemplo n.º 1
0
    static bool TryExtractParts(
        string substring,
        string line,
        bool throwForTooManyParts,
        string path,
        [NotNullWhen(true)] out string?key)
    {
        var split = substring.SplitBySpace();

        if (split.Length == 0)
        {
            throw new SnippetReadingException($@"No Key could be derived.
Path: {path}
Line: '{line}'");
        }

        key = split[0].ToLowerInvariant();
        KeyValidator.ValidateKeyDoesNotStartOrEndWithSymbol(key, path, line);
        if (split.Length == 1)
        {
            return(true);
        }

        if (!throwForTooManyParts)
        {
            return(false);
        }

        throw new SnippetReadingException($@"Too many parts.
Path: {path}
Line: '{line}'");
    }
Exemplo n.º 2
0
    static bool TryExtractParts(out string key, out string version, string substring, string line, bool throwForTooManyParts)
    {
        var split = substring.SplitBySpace();

        if (split.Length == 0)
        {
            throw new SnippetReadingException($"No Key could be derived. Line: '{line}'.");
        }
        key = split[0];
        KeyValidator.ValidateKeyDoesNotStartOrEndWithSymbol(key);
        if (split.Length == 1)
        {
            version = null;
            return(true);
        }
        version = split[1];
        if (split.Length == 2)
        {
            return(true);
        }

        if (!throwForTooManyParts)
        {
            return(false);
        }
        throw new SnippetReadingException($"Too many parts. Line: '{line}'.");
    }
Exemplo n.º 3
0
    public static bool IsStart(string line, out string key)
    {
        if (!line.StartsWith("<!-- snippet: ", StringComparison.Ordinal))
        {
            key = null;
            return(false);
        }

        var substring = line.Substring(13);

        if (!substring.EndsWith(" -->"))
        {
            throw new Exception($"Expected line to end with ' -->'. Line: '{line}'.");
        }

        key = substring.Substring(0, substring.Length - 3).Trim();
        if (key.Length == 0)
        {
            throw new Exception($"No Key could be derived. Line: '{line}'.");
        }

        KeyValidator.ValidateKeyDoesNotStartOrEndWithSymbol(key);
        return(true);
    }