Commits

Miguel Roman committed ba1ba10

Se implemento la funcionalidad de remover caracteres diacriticos.

  • Participants
  • Parent commits fe761ee

Comments (0)

Files changed (7)

File BinarioDataAnnotations/BinarioDataAnnotations.csproj

     <DefineConstants>TRACE</DefineConstants>
     <ErrorReport>prompt</ErrorReport>
     <WarningLevel>4</WarningLevel>
+    <DocumentationFile>bin\Release\BinarioDataAnnotations.XML</DocumentationFile>
   </PropertyGroup>
   <ItemGroup>
     <Reference Include="System" />

File BinarioDataAnnotations/CuiAttribute.cs

 
         private CuiValidator cuiValidator = new CuiValidator();
 
+        /// <summary>
+        ///     Determina si el valor indicado es un Nit Valido.
+        /// </summary>
+        /// <param name="value">
+        ///     El valor del objeto a validar.
+        /// </param>
+        /// <returns>
+        ///     true si el valor es valido o de lo contrario falso.
+        /// </returns>
         public override bool IsValid(object value)
         {
 

File BinarioDrawingTools/BinarioDrawingTools.csproj

     <DefineConstants>TRACE</DefineConstants>
     <ErrorReport>prompt</ErrorReport>
     <WarningLevel>4</WarningLevel>
+    <DocumentationFile>bin\Release\BinarioDrawingTools.XML</DocumentationFile>
   </PropertyGroup>
   <ItemGroup>
     <Reference Include="System.Drawing" />

File BinarioMvcTools/BinarioMvcTools.csproj

     <DefineConstants>TRACE</DefineConstants>
     <ErrorReport>prompt</ErrorReport>
     <WarningLevel>4</WarningLevel>
+    <DocumentationFile>bin\Release\BinarioMvcTools.XML</DocumentationFile>
   </PropertyGroup>
   <ItemGroup>
     <Compile Include="Properties\AssemblyInfo.cs" />

File BinarioTools/BinarioTools.csproj

     <DefineConstants>TRACE</DefineConstants>
     <ErrorReport>prompt</ErrorReport>
     <WarningLevel>4</WarningLevel>
+    <DocumentationFile>bin\Release\BinarioTools.XML</DocumentationFile>
   </PropertyGroup>
   <ItemGroup>
     <Reference Include="System" />

File BinarioTools/Extensions/StringExtensions.cs

 using System;
 using System.Collections.Generic;
+using System.Globalization;
 using System.Linq;
 using System.Text;
 
             return text;
         }
 
+        /// <summary>
+        ///     Elimina todos los caracteres diacriticos por su equivalente sin diacritico.
+        ///     <example>
+        ///         Console.WriteLine("ç".RemoveDiacritics()); // Imprime "c"
+        ///         Console.WriteLine("á".RemoveDiacritics()); // Imprime "a"
+        ///     </example>
+        /// </summary>
+        /// <param name="text">
+        ///     Texto al que se quiere remover los acentos.
+        /// </param>
+        /// <returns>
+        ///     Retorna la cadena introducida sin caracteres diacritcos.
+        /// </returns>
+        /// <remarks>
+        ///     Thanks to Michael S. Kaplan http://blogs.msdn.com/b/michkap/archive/2005/02/19/376617.aspx
+        /// </remarks>
+        public static string RemoveDiacritics(this string text)
+        {
+            string textInFormD = text.Normalize(NormalizationForm.FormD);
+            StringBuilder sb = new StringBuilder();
+
+            for (int ich = 0; ich < textInFormD.Length; ich++)
+            {
+                UnicodeCategory uc = CharUnicodeInfo.GetUnicodeCategory(textInFormD[ich]);
+                if (uc != UnicodeCategory.NonSpacingMark)
+                {
+                    sb.Append(textInFormD[ich]);
+                }
+            }
+
+            return (sb.ToString().Normalize(NormalizationForm.FormC));
+        }
+
     }
 }

File BinarioToolsTests/Extensions/StringExtensionsTests.cs

         [TestCase("Niño", "Nino")]
         [TestCase("CANCIÓN", "CANCION")]
         [TestCase("Binario", "Binario")]
+        [TestCase("Barça", "Barça")]
+        [TestCase("C:\\Path", "C:\\Path")]
+        [TestCase("2^2=4", "2^2=4")]
         public void RemoveOrthographicAccents_Test(string inputText, string expectedText)
         {
 
 
         }
 
+        [TestCase("á", "a")]
+        [TestCase("é", "e")]
+        [TestCase("í", "i")]
+        [TestCase("ó", "o")]
+        [TestCase("ú", "u")]
+        [TestCase("Á", "A")]
+        [TestCase("É", "E")]
+        [TestCase("Í", "I")]
+        [TestCase("Ó", "O")]
+        [TestCase("Ú", "U")]
+        [TestCase("ñ", "n")]
+        [TestCase("Ñ", "N")]
+        [TestCase("árbol", "arbol")]
+        [TestCase("Niño", "Nino")]
+        [TestCase("CANCIÓN", "CANCION")]
+        [TestCase("Binario", "Binario")]
+        [TestCase("Barça", "Barca")]
+        [TestCase("C:\\Path", "C:\\Path")]
+        [TestCase("2^2=4", "2^2=4")]
+        public void RemoveDiacritics_Test(string inputText, string expectedText)
+        {
+            //Act
+            var result = StringExtensions.RemoveDiacritics(inputText);
+
+            //Assert
+            Assert.AreEqual(expectedText, result);
+        }
+
     }
 }