public string Format(string transformedString, ISlugityConfig config) { string stripHtml = StripHtml(transformedString.Trim()); string cleanSpaces = NormaliseSpaces(stripHtml); string result = RemoveInvalidChars(cleanSpaces); return(result); }
public string Format(string transformedString, ISlugityConfig config) { if (!config.StripStopWords) { return(transformedString); } string[] inputArray = transformedString.Split(config.StringSeparator); string result = string.Join(config.StringSeparator.ToString(), inputArray.Except(config.StopWords.StopWordsStore)); return(result); }
public string Format(string transformedString, ISlugityConfig config) { if (config.ReplacementCharacters == null) { throw new ArgumentNullException(nameof(config.ReplacementCharacters)); } foreach (KeyValuePair <string, string> characters in config.ReplacementCharacters.ReplacementCharacters) { transformedString = transformedString.Replace(characters.Key, characters.Value); } return(transformedString); }
public string Format(string transformedString, ISlugityConfig config) { _configuration = config; switch (config.TextCase) { case TextCase.LowerCase: return(transformedString.ToLower()); case TextCase.CamalCase: return(ToCamalCaseRevisted(transformedString)); case TextCase.UpperCase: return(transformedString.ToUpper()); default: return(transformedString); } }
public string Format(string transformedString, ISlugityConfig config) { // If slug is shorter than MaxLength if (config.MaxLength == null || transformedString.Length <= config.MaxLength) { return(transformedString); } // If MaxLength ends on separator, remove separator int charPos = config.MaxLength.Value - 1; char charAtPos = transformedString[charPos]; if (charAtPos == config.StringSeparator) { return(transformedString.Substring(0, charPos)); } // If MaxLength ends on word, ensure it doesn't get truncated int length = transformedString.Length; int realMaxLength = config.MaxLength.Value; for (int i = 0; i < length; i++) { char c = transformedString[i]; if (i <= realMaxLength || c != config.StringSeparator) { continue; } realMaxLength = i; break; } string result = transformedString.Substring(0, realMaxLength); return(result); }
public string Format(string transformedString, ISlugityConfig config) { if (string.IsNullOrEmpty(transformedString)) { throw new ArgumentNullException(nameof(transformedString)); } bool lastCharIsSeperator = false; var result = new StringBuilder(); bool isWhiteSpace; foreach (char currentChar in transformedString) { isWhiteSpace = char.IsWhiteSpace(currentChar); if (isWhiteSpace && transformedString.IndexOf(currentChar) == transformedString.Length - 1) { break; } if (char.IsWhiteSpace(currentChar) || currentChar == config.StringSeparator) { if (!lastCharIsSeperator) { result.Append(config.StringSeparator); } lastCharIsSeperator = true; continue; } lastCharIsSeperator = false; result.Append(currentChar); } return(result.ToString()); }
public Slugity(ISlugityConfig slugityConfig) { this.slugityConfig = slugityConfig; }
public Slugity() { slugityConfig = new SlugityConfig(); }