From: Bowon Ryu Date: Thu, 9 Dec 2021 09:30:30 +0000 (+0900) Subject: [NUI] remove duplicate code from TextMapHelper X-Git-Tag: accepted/tizen/unified/20231205.024657~1250 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=38c3a782a20f1c1485f434b2f661b8e981aa20b2;p=platform%2Fcore%2Fcsapi%2Ftizenfx.git [NUI] remove duplicate code from TextMapHelper remove duplicate code through function extraction. Signed-off-by: Bowon Ryu --- diff --git a/src/Tizen.NUI/src/public/BaseComponents/TextMapHelper.cs b/src/Tizen.NUI/src/public/BaseComponents/TextMapHelper.cs index 4a1986d..75ff2c7 100644 --- a/src/Tizen.NUI/src/public/BaseComponents/TextMapHelper.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/TextMapHelper.cs @@ -27,6 +27,18 @@ namespace Tizen.NUI.BaseComponents [EditorBrowsable(EditorBrowsableState.Never)] public static class TextMapHelper { + private static string GetCamelCase(string pascalCase) + { + if (!string.IsNullOrEmpty(pascalCase)) + { + char[] charArray = pascalCase.ToCharArray(); + charArray[0] = Char.ToLower(charArray[0]); + pascalCase = new string(charArray); + } + + return pascalCase; + } + /// /// It returns a string value according to FontWidthType. /// The returned value can be used for FontStyle PropertyMap. @@ -36,19 +48,8 @@ namespace Tizen.NUI.BaseComponents [EditorBrowsable(EditorBrowsableState.Never)] public static string GetFontWidthString(FontWidthType fontWidthType) { - string value = fontWidthType.ToString(); - if (!string.IsNullOrEmpty(value)) - { - char[] charArray = value.ToCharArray(); - charArray[0] = Char.ToLower(charArray[0]); - value = new string(charArray); - } - else - { - value = "none"; // The default value. - } - - return value; + string value = GetCamelCase(fontWidthType.ToString()); + return string.IsNullOrEmpty(value) ? "none" : value; } /// @@ -60,19 +61,8 @@ namespace Tizen.NUI.BaseComponents [EditorBrowsable(EditorBrowsableState.Never)] public static string GetFontWeightString(FontWeightType fontWeightType) { - string value = fontWeightType.ToString(); - if (!string.IsNullOrEmpty(value)) - { - char[] charArray = value.ToCharArray(); - charArray[0] = Char.ToLower(charArray[0]); - value = new string(charArray); - } - else - { - value = "none"; // The default value. - } - - return value; + string value = GetCamelCase(fontWeightType.ToString()); + return string.IsNullOrEmpty(value) ? "none" : value; } /// @@ -84,19 +74,21 @@ namespace Tizen.NUI.BaseComponents [EditorBrowsable(EditorBrowsableState.Never)] public static string GetFontSlantString(FontSlantType fontSlantType) { - string value = fontSlantType.ToString(); - if (!string.IsNullOrEmpty(value)) - { - char[] charArray = value.ToCharArray(); - charArray[0] = Char.ToLower(charArray[0]); - value = new string(charArray); - } - else - { - value = "none"; // The default value. - } + string value = GetCamelCase(fontSlantType.ToString()); + return string.IsNullOrEmpty(value) ? "none" : value; + } - return value; + /// + /// It returns a string value according to FontSizeType. + /// The returned value can be used for TextFit PropertyMap. + /// The FontSizeType enum value. + /// A string value for TextFit.FontSizeType property. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public static string GetFontSizeString(FontSizeType fontSizeType) + { + string value = GetCamelCase(fontSizeType.ToString()); + return string.IsNullOrEmpty(value) ? "pointSize" : value; } /// @@ -372,30 +364,6 @@ namespace Tizen.NUI.BaseComponents } /// - /// It returns a string value according to FontSizeType. - /// The returned value can be used for TextFit PropertyMap. - /// The FontSizeType enum value. - /// A string value for TextFit.FontSizeType property. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public static string GetFontSizeString(FontSizeType fontSizeType) - { - string value = fontSizeType.ToString(); - if (!string.IsNullOrEmpty(value)) - { - char[] charArray = value.ToCharArray(); - charArray[0] = Char.ToLower(charArray[0]); - value = new string(charArray); - } - else - { - value = "pointSize"; // The default value. - } - - return value; - } - - /// /// It returns a FontSizeType value according to fontSizeString. /// The returned value can be used for FontStyle PropertyMap. /// The FontSizeType string value.