From a56ea189f1976d9a77ee3bb9f345520ae705e0b7 Mon Sep 17 00:00:00 2001 From: Olek Date: Wed, 16 Sep 2015 17:00:59 +0200 Subject: [PATCH] [Fix] Issue#1 Parser finds errors that aren't errors --- .../Infrastructure/JsParserService.cs | 3 +- .../Parsers/JSParserExtensions.cs | 98 ++++++++++--------- 2 files changed, 56 insertions(+), 45 deletions(-) diff --git a/source/JsParser.Core/Infrastructure/JsParserService.cs b/source/JsParser.Core/Infrastructure/JsParserService.cs index 8ba776e..49ac6df 100644 --- a/source/JsParser.Core/Infrastructure/JsParserService.cs +++ b/source/JsParser.Core/Infrastructure/JsParserService.cs @@ -71,9 +71,10 @@ private bool CheckExt(string fileName) { if (_settings.Extensions.Count > 0) { + var currentExt = Path.GetExtension(fileName).SafeTrimStart('.'); foreach (var ext in _settings.Extensions) { - if (fileName.ToLower().EndsWith(ext, StringComparison.InvariantCultureIgnoreCase)) + if (string.Compare(currentExt, ext, StringComparison.InvariantCultureIgnoreCase) == 0) { return true; } diff --git a/source/JsParser.Core/Parsers/JSParserExtensions.cs b/source/JsParser.Core/Parsers/JSParserExtensions.cs index 7861d2e..98a5542 100644 --- a/source/JsParser.Core/Parsers/JSParserExtensions.cs +++ b/source/JsParser.Core/Parsers/JSParserExtensions.cs @@ -5,48 +5,58 @@ namespace JsParser.Core.Parsers { - public static class JSParserExtensions - { - public static string Shortenize(this String s, int targetLength) - { - if (targetLength <= 0) - { - return string.Empty; - } - - if (s.Length > targetLength) - { - var si = (int)2 * (targetLength / 3); - s = s.Substring(0, si) + '\x2026' + s.Substring(s.Length + 1 - targetLength + si); - } - - return s; - } - - /// - /// Transform input string by adding spaces where words should be separeated. - /// Example: "ThisStringShouldBeSeparated" => "This String Shoud Be Separated" - /// - /// - /// - public static string SplitWordsByCamelCase(this String s) - { - if (string.IsNullOrEmpty(s)) - { - return s; - } - - var chars = s.ToList(); - for (int charIndex = 0; charIndex < chars.Count; charIndex++) - { - if (char.IsUpper(chars[charIndex])) - { - chars.Insert(charIndex, ' '); - charIndex++; - } - } - - return new string(chars.ToArray()).Trim(); - } - } + public static class JsParserExtensions + { + public static string SafeTrimStart(this string s, char symbol) + { + if (string.IsNullOrEmpty(s)) + { + return string.Empty; + } + + return s.TrimStart(symbol); + } + + public static string Shortenize(this String s, int targetLength) + { + if (targetLength <= 0) + { + return string.Empty; + } + + if (s.Length > targetLength) + { + var si = (int) 2*(targetLength/3); + s = s.Substring(0, si) + '\x2026' + s.Substring(s.Length + 1 - targetLength + si); + } + + return s; + } + + /// + /// Transform input string by adding spaces where words should be separeated. + /// Example: "ThisStringShouldBeSeparated" => "This String Shoud Be Separated" + /// + /// + /// + public static string SplitWordsByCamelCase(this String s) + { + if (string.IsNullOrEmpty(s)) + { + return s; + } + + var chars = s.ToList(); + for (int charIndex = 0; charIndex < chars.Count; charIndex++) + { + if (char.IsUpper(chars[charIndex])) + { + chars.Insert(charIndex, ' '); + charIndex++; + } + } + + return new string(chars.ToArray()).Trim(); + } + } }