internal static bool IsStartRegion( string line, [NotNullWhen(true)] out string?key) { if (!line.StartsWith("#region ", StringComparison.Ordinal)) { key = ""; return(false); } var substring = line.Substring(8); var split = substring.SplitBySpace(); if (split.Length == 0) { key = ""; return(false); } key = split[0].ToLowerInvariant(); if (split.Length != 1) { return(false); } if (KeyValidator.IsInValidKey(key)) { return(false); } return(true); }
internal static bool IsBeginSnippet( string line, string path, [NotNullWhen(true)] out string?key) { var beginSnippetIndex = IndexOf(line, "begin-snippet: "); if (beginSnippetIndex == -1) { key = null; return(false); } var startIndex = beginSnippetIndex + 15; var substring = line .TrimBackCommentChars(startIndex); var split = substring.SplitBySpace(); if (split.Length == 0) { throw new SnippetReadingException($@"No Key could be derived. Path: {path} Line: '{line}'"); } key = split[0].ToLowerInvariant(); if (split.Length != 1) { throw new SnippetReadingException($@"Too many parts. Path: {path} Line: '{line}'"); } if (KeyValidator.IsInValidKey(key)) { throw new SnippetReadingException($@"Key cannot contain whitespace or start/end with symbols. Key: {key} Path: {path} Line: {line}"); } return(true); }