/// <summary> /// Converts the specified <paramref name="str"/> to a new string formatted using the specified <paramref name="casing"/>. /// </summary> /// <param name="str">The string to be converted.</param> /// <param name="casing">The casing of the output string.</param> /// <returns>The output string, matching the specified <paramref name="casing"/>.</returns> public static string ToCasing(string str, TextCasing casing) { if (String.IsNullOrWhiteSpace(str)) { return(String.Empty); } switch (casing) { case TextCasing.LowerCase: return(str.ToLower()); case TextCasing.UpperCase: return(str.ToUpper()); case TextCasing.CamelCase: return(ToCamelCase(str)); case TextCasing.PascalCase: return(ToPascalCase(str)); case TextCasing.KebabCase: return(ToKebabCase(str)); case TextCasing.TrainCase: return(ToTrainCase(str)); case TextCasing.Underscore: return(ToUnderscore(str)); default: throw new ArgumentException("Unknown casing " + casing, nameof(casing)); } }
private static void SetText(TextBlock textBlock, TextCasing textCasing) { switch (textCasing) { case TextCasing.UpperCase: textBlock.Text = textBlock.Text.ToUpper(); break; case TextCasing.LowerCase: textBlock.Text = textBlock.Text.ToLower(); break; } }
public void Test_TransformToLowerCase() { var lowerCasingService = new TextCasing() { Type = CasingType.Lower }; Assert.Equal("listdetail", lowerCasingService.Transform("ListDetail")); Assert.Equal("listdetail", lowerCasingService.Transform("List_Detail")); Assert.Equal("listdetail", lowerCasingService.Transform("List Detail")); Assert.Equal("listdetail", lowerCasingService.Transform(" List Detail ")); Assert.Equal("listdetail1", lowerCasingService.Transform("list detail 1")); Assert.Equal("listui", lowerCasingService.Transform("ListUI")); Assert.Equal("listui", lowerCasingService.Transform("list UI")); Assert.Equal("listui", lowerCasingService.Transform("List_UI")); }
public void Test_TransformToCamelCase() { var camelCasingService = new TextCasing() { Type = CasingType.Camel }; Assert.Equal("listDetail", camelCasingService.Transform("ListDetail")); Assert.Equal("listDetail", camelCasingService.Transform("List_Detail")); Assert.Equal("listDetail", camelCasingService.Transform("List Detail")); Assert.Equal("listDetail", camelCasingService.Transform(" List Detail ")); Assert.Equal("listDetail1", camelCasingService.Transform("list detail 1")); Assert.Equal("listUI", camelCasingService.Transform("ListUI")); Assert.Equal("listUI", camelCasingService.Transform("list UI")); Assert.Equal("listUI", camelCasingService.Transform("List_UI")); }
public void Test_TransformToCamelCase() { var camelCasingService = new TextCasing() { Type = CasingType.Camel }; Assert.Equal("masterDetail", camelCasingService.Transform("MasterDetail")); Assert.Equal("masterDetail", camelCasingService.Transform("Master_Detail")); Assert.Equal("masterDetail", camelCasingService.Transform("Master Detail")); Assert.Equal("masterDetail", camelCasingService.Transform(" Master Detail ")); Assert.Equal("masterDetail1", camelCasingService.Transform("master detail 1")); Assert.Equal("masterUI", camelCasingService.Transform("MasterUI")); Assert.Equal("masterUI", camelCasingService.Transform("master UI")); Assert.Equal("masterUI", camelCasingService.Transform("Master_UI")); }
public void Test_TransformToLowerCase() { var lowerCasingService = new TextCasing() { Type = CasingType.Lower }; Assert.Equal("masterdetail", lowerCasingService.Transform("MasterDetail")); Assert.Equal("masterdetail", lowerCasingService.Transform("Master_Detail")); Assert.Equal("masterdetail", lowerCasingService.Transform("Master Detail")); Assert.Equal("masterdetail", lowerCasingService.Transform(" Master Detail ")); Assert.Equal("masterdetail1", lowerCasingService.Transform("master detail 1")); Assert.Equal("masterui", lowerCasingService.Transform("MasterUI")); Assert.Equal("masterui", lowerCasingService.Transform("master UI")); Assert.Equal("masterui", lowerCasingService.Transform("Master_UI")); }
private SpellingFix GetFix(string value) { TextCasing textCasing = TextUtility.GetTextCasing(value); if (textCasing != TextCasing.Undefined && Data.Fixes.TryGetValue(value, out ImmutableHashSet <SpellingFix>?fixes)) { SpellingFix fix = fixes.SingleOrDefault( f => TextUtility.GetTextCasing(f.Value) != TextCasing.Undefined, shouldThrow: false); if (!fix.IsDefault) { return(fix.WithValue(TextUtility.SetTextCasing(fix.Value, textCasing))); } } return(default);
public void Test_TransformToSnake() { var snakeCasingService = new TextCasing() { Type = CasingType.Snake }; Assert.Equal("list_detail", snakeCasingService.Transform("ListDetail")); Assert.Equal("list_detail", snakeCasingService.Transform("List_Detail")); Assert.Equal("list_detail", snakeCasingService.Transform("List Detail")); Assert.Equal("list_detail", snakeCasingService.Transform(" List Detail ")); Assert.Equal("list_detail", snakeCasingService.Transform("list detail")); Assert.Equal("list_detail_123_abc", snakeCasingService.Transform("list - detail 123 abc")); Assert.Equal("list_detail_1", snakeCasingService.Transform("ListDetail1")); Assert.Equal("list_ui", snakeCasingService.Transform("ListUI")); Assert.Equal("list_ui", snakeCasingService.Transform("List UI")); Assert.Equal("list_ui", snakeCasingService.Transform("List_UI")); }
public void Test_TransformToKebab() { var kebabCasingService = new TextCasing() { Type = CasingType.Kebab }; Assert.Equal("list-detail", kebabCasingService.Transform("ListDetail")); Assert.Equal("list-detail", kebabCasingService.Transform("List_Detail")); Assert.Equal("list-detail", kebabCasingService.Transform("List Detail")); Assert.Equal("list-detail", kebabCasingService.Transform(" List Detail ")); Assert.Equal("list-detail", kebabCasingService.Transform("list detail")); Assert.Equal("list-detail-123-abc", kebabCasingService.Transform("list - detail 123 abc")); Assert.Equal("list-detail-1", kebabCasingService.Transform("ListDetail1")); Assert.Equal("list-ui", kebabCasingService.Transform("ListUI")); Assert.Equal("list-ui", kebabCasingService.Transform("List UI")); Assert.Equal("list-ui", kebabCasingService.Transform("List_UI")); }
public void Test_TransformToSnake() { var snakeCasingService = new TextCasing() { Type = CasingType.Snake }; Assert.Equal("master_detail", snakeCasingService.Transform("MasterDetail")); Assert.Equal("master_detail", snakeCasingService.Transform("Master_Detail")); Assert.Equal("master_detail", snakeCasingService.Transform("Master Detail")); Assert.Equal("master_detail", snakeCasingService.Transform(" Master Detail ")); Assert.Equal("master_detail", snakeCasingService.Transform("master detail")); Assert.Equal("master_detail_123_abc", snakeCasingService.Transform("master - detail 123 abc")); Assert.Equal("master_detail_1", snakeCasingService.Transform("MasterDetail1")); Assert.Equal("master_ui", snakeCasingService.Transform("MasterUI")); Assert.Equal("master_ui", snakeCasingService.Transform("Master UI")); Assert.Equal("master_ui", snakeCasingService.Transform("Master_UI")); }
public void Test_TransformToKebab() { var kebabCasingService = new TextCasing() { Type = CasingType.Kebab }; Assert.Equal("master-detail", kebabCasingService.Transform("MasterDetail")); Assert.Equal("master-detail", kebabCasingService.Transform("Master_Detail")); Assert.Equal("master-detail", kebabCasingService.Transform("Master Detail")); Assert.Equal("master-detail", kebabCasingService.Transform(" Master Detail ")); Assert.Equal("master-detail", kebabCasingService.Transform("master detail")); Assert.Equal("master-detail-123-abc", kebabCasingService.Transform("master - detail 123 abc")); Assert.Equal("master-detail-1", kebabCasingService.Transform("MasterDetail1")); Assert.Equal("master-ui", kebabCasingService.Transform("MasterUI")); Assert.Equal("master-ui", kebabCasingService.Transform("Master UI")); Assert.Equal("master-ui", kebabCasingService.Transform("Master_UI")); }
public static string SetTextCasing(string s, TextCasing textCasing) { TextCasing textCasing2 = GetTextCasing(s); if (textCasing == textCasing2) { return(s); } switch (textCasing) { case TextCasing.Lower: return(s.ToLowerInvariant()); case TextCasing.Upper: return(s.ToUpperInvariant()); case TextCasing.FirstUpper: return(s.Substring(0, 1).ToUpperInvariant() + s.Substring(1).ToLowerInvariant()); default: throw new InvalidOperationException($"Invalid enum value '{textCasing}'"); } }
public static string ToFormattedString(this StringBuilder source, TextCasing casing = TextCasing.Default) { if (source == null) { throw new ArgumentNullException(nameof(source)); } if (casing == TextCasing.Uppercase) { return(source.ToString().ToUpper()); } if (casing == TextCasing.Lowercase) { return(source.ToString().ToLower()); } if (casing == TextCasing.TitleCase) { var culture = CultureInfo.CurrentCulture; var textInfo = culture.TextInfo; var trimmedSource = source.ToString().Trim(); return(textInfo.ToTitleCase(trimmedSource)); } return(source.ToString().Trim()); }
public EnumStringConverter(TextCasing casing) { _casing = casing; }
public EnumStringConverter() { _casing = TextCasing.PascalCase; }
/// <summary> /// Converts the specified <paramref name="str"/> to a new string formatted using the specified <paramref name="casing"/>. /// </summary> /// <param name="str">The string to be converted.</param> /// <param name="casing">The casing of the output string.</param> /// <returns>The output string, matching the specified <paramref name="casing"/>.</returns> public static string ToCasing(this string str, TextCasing casing) { return(StringUtils.ToCasing(str, casing)); }
/// <summary> /// Converts the specified enum <paramref name="value"/> to a string with the enum name is formatted using the specified <paramref name="casing"/>. /// </summary> /// <param name="value">The enum value to be converted.</param> /// <param name="casing">The casing of the output string.</param> /// <returns>The output string, matching the specified <paramref name="casing"/>.</returns> public static string ToCasing(this Enum value, TextCasing casing) { return(StringUtils.ToCasing(value, casing)); }
public static void SetTextCasing(DependencyObject obj, TextCasing value) { obj.SetValue(TextCasingProperty, value); }
/// <summary> /// Initializes a new instance of the <see cref="Chalker"/> class. /// </summary> /// <param name="casing">The casing method used for the prefix.</param> public Chalker(TextCasing casing) : this() { Casing = casing; }
/// <summary> /// Converts the specified enum <paramref name="values"/> to a string where the enum names are formatted using the specified <paramref name="casing"/>. /// </summary> /// <typeparam name="TEnum">The type of the enum.</typeparam> /// <param name="values">The enum values to be converted.</param> /// <param name="casing">The casing of the output string.</param> /// <returns>The output string, matching the specified <paramref name="casing"/>.</returns> public static string ToCasing <TEnum>(this IEnumerable <TEnum> values, TextCasing casing) where TEnum : Enum { return(StringUtils.ToCasing(values, casing)); }
static void Main() { TextCasing service = new TextCasing(); Console.WriteLine(service.InvertStringCase("mahmoud")); }
/// <summary> /// Converts the specified enum <paramref name="value"/> to a string with the enum name is formatted using the specified <paramref name="casing"/>. /// </summary> /// <param name="value">The enum value to be converted.</param> /// <param name="casing">The casing of the output string.</param> /// <returns>The output string, matching the specified <paramref name="casing"/>.</returns> public static string ToCasing(Enum value, TextCasing casing) { return(ToCasing(value.ToString(), casing)); }
/// <summary> /// Initializes a new instance of the <see cref="Chalker"/> class. /// </summary> /// <param name="paddingRight">The padding that will be used on the right side of the prefix. Negative values are not allowed.</param> /// <param name="casing">The casing method used for the prefix.</param> public Chalker(int paddingRight, TextCasing casing) : this(paddingRight) { Casing = casing; }
/// <summary> /// Converts the specified enum <paramref name="values"/> to a string where the enum names are formatted using the specified <paramref name="casing"/>. /// </summary> /// <typeparam name="TEnum">The type of the enum.</typeparam> /// <param name="values">The enum values to be converted.</param> /// <param name="casing">The casing of the output string.</param> /// <returns>The output string, matching the specified <paramref name="casing"/>.</returns> public static string ToCasing <TEnum>(IEnumerable <TEnum> values, TextCasing casing) where TEnum : Enum { return(string.Join(",", from e in values select ToCasing(e, casing))); }