public string Format(string input, RantFormat formatStyle, OutputFormatterOptions options = OutputFormatterOptions.None) { if (String.IsNullOrEmpty(input)) { return(input); } // Check for special symbols switch (input.ToLowerInvariant()) { case SymbolCodes.EnDash: return(Symbols.EnDash); case SymbolCodes.EmDash: return(Symbols.EmDash); case SymbolCodes.Copyright: return(Symbols.Copyright); case SymbolCodes.RegisteredTM: return(Symbols.RegisteredTM); case SymbolCodes.Trademark: return(Symbols.Trademark); case SymbolCodes.Bullet: return(Symbols.Bullet); case SymbolCodes.Eszett: return(Symbols.Eszett); } switch (Case) { case Case.Lower: input = input.ToLower(); break; case Case.Upper: input = input.ToUpper(); break; case Case.First: input = RegCapsFirst.Replace(input, m => m.Value.ToUpper()); Case = Case.None; break; case Case.Title: if (((options & OutputFormatterOptions.IsArticle) == OutputFormatterOptions.IsArticle || formatStyle.Excludes(input)) && Char.IsWhiteSpace(_lastChar)) { break; } input = RegCapsTitleWord.Replace(input, m => ( _lastChar == '\0' || Char.IsSeparator(_lastChar) || Char.IsWhiteSpace(_lastChar)) || Char.IsPunctuation(_lastChar) ? m.Value.ToUpper() : m.Value); break; case Case.Sentence: if (_sentence) { input = Regex.Replace(input, @"^.*?\w", m => { if ((options & OutputFormatterOptions.NoUpdate) != OutputFormatterOptions.NoUpdate) { _sentence = false; } return(m.Value.ToUpper()); }); } input = RegCapsSentenceA.Replace(input, m => m.Value.ToUpper()); break; case Case.Word: input = RegCapsTitleWord.Replace(input, m => m.Value.ToUpper()); break; } if (RegCapsSentenceB.IsMatch(input) && (options & OutputFormatterOptions.NoUpdate) != OutputFormatterOptions.NoUpdate) { _sentence = true; } if ((options & OutputFormatterOptions.NoUpdate) != OutputFormatterOptions.NoUpdate) { _lastChar = input[input.Length - 1]; } return(input); }
public string Format(string input, RantFormat formatStyle, OutputFormatterOptions options = OutputFormatterOptions.None) { if (String.IsNullOrEmpty(input)) return input; // Check for special symbols // TODO: Move symbols to a dictionary switch (input.ToLowerInvariant()) { case SymbolCodes.EnDash: return Symbols.EnDash; case SymbolCodes.EmDash: return Symbols.EmDash; case SymbolCodes.Copyright: return Symbols.Copyright; case SymbolCodes.RegisteredTM: return Symbols.RegisteredTM; case SymbolCodes.Trademark: return Symbols.Trademark; case SymbolCodes.Bullet: return Symbols.Bullet; case SymbolCodes.Eszett: return Symbols.Eszett; } switch (Case) { case Case.Lower: input = input.ToLower(); break; case Case.Upper: input = input.ToUpper(); break; case Case.First: input = RegCapsFirst.Replace(input, m => m.Value.ToUpper()); if ((options & OutputFormatterOptions.NoUpdate) != OutputFormatterOptions.NoUpdate) Case = Case.None; break; case Case.Title: if (((options & OutputFormatterOptions.IsArticle) == OutputFormatterOptions.IsArticle || formatStyle.Excludes(input)) && Char.IsWhiteSpace(_lastChar)) break; input = RegCapsTitleWord.Replace(input, m => ( _lastChar == '\0' || Char.IsSeparator(_lastChar) || Char.IsWhiteSpace(_lastChar)) || Char.IsPunctuation(_lastChar) ? m.Value.ToUpper() : m.Value); break; case Case.Sentence: if (_sentence) input = Regex.Replace(input, @"^.*?\w", m => { if ((options & OutputFormatterOptions.NoUpdate) != OutputFormatterOptions.NoUpdate) _sentence = false; return m.Value.ToUpper(); }); input = RegCapsSentenceA.Replace(input, m => m.Value.ToUpper()); break; case Case.Word: input = RegCapsTitleWord.Replace(input, m => m.Value.ToUpper()); break; } if (RegCapsSentenceB.IsMatch(input) && (options & OutputFormatterOptions.NoUpdate) != OutputFormatterOptions.NoUpdate) _sentence = true; if ((options & OutputFormatterOptions.NoUpdate) != OutputFormatterOptions.NoUpdate) _lastChar = input[input.Length - 1]; return input; }