/// <summary> /// Checks if a number follows the specified <code>token</code> /// </summary> /// <param name="category">the category to set if a number follows the <code>token</code></param> /// <param name="token">the token</param> /// <returns>true if a number follows the token; false otherwise</returns> private bool NumberComesAfterPrefix(Element.ElementCategory category, Token token) { var numberBegin = ParserHelper.IndexOfFirstDigit(token.Content); var prefix = StringHelper.SubstringWithCheck(token.Content, 0, numberBegin).ToUpperInvariant(); if (!KeywordManager.Contains(category, prefix)) { return(false); } var number = StringHelper.SubstringWithCheck(token.Content, numberBegin, token.Content.Length - numberBegin); switch (category) { case Element.ElementCategory.ElementEpisodePrefix: if (!MatchEpisodePatterns(number, token)) { SetEpisodeNumber(number, token, false); } return(true); case Element.ElementCategory.ElementVolumePrefix: if (!MatchVolumePatterns(number, token)) { SetVolumeNumber(number, token, false); } return(true); default: return(false); } }
/// <summary> /// Removes the extension from the <see cref="filename"/> /// </summary> /// <param name="filename">the ref that will be updated with the new filename</param> /// <param name="extension">the ref that will be updated with the file extension</param> /// <returns>if the extension was successfully separated from the filename</returns> private static bool RemoveExtensionFromFilename(ref string filename, ref string extension) { int position; if (string.IsNullOrEmpty(filename) || (position = filename.LastIndexOf('.')) == -1) { return(false); } /** remove file extension */ extension = filename.Substring(position + 1); if (extension.Length > 4 || !extension.All(char.IsLetterOrDigit)) { return(false); } /** check if valid anime extension */ var keyword = KeywordManager.Normalize(extension); if (!KeywordManager.Contains(Element.ElementCategory.ElementFileExtension, keyword)) { return(false); } filename = filename.Substring(0, position); return(true); }