private void UpdateAllCharsRefinerSettingsUI()
        {
            FilteringCharacterCategory cats = m_allCharactersRefinerSettings.NotIgnoredCategories;

            cbRefineDigits.Checked        = ((FilteringCharacterCategory.ArabicDigit & cats) == FilteringCharacterCategory.ArabicDigit);
            cbRefineErab.Checked          = ((FilteringCharacterCategory.Erab & cats) == FilteringCharacterCategory.Erab);
            cbRefineHalfSpaceChar.Checked = ((FilteringCharacterCategory.HalfSpace & cats) == FilteringCharacterCategory.HalfSpace);
            cbRefineKaaf.Checked          = ((FilteringCharacterCategory.Kaaf & cats) == FilteringCharacterCategory.Kaaf);
            cbRefineYaa.Checked           = ((FilteringCharacterCategory.Yaa & cats) == FilteringCharacterCategory.Yaa);

            cbRemoveHalfSpaces.Checked = m_allCharactersRefinerSettings.RefineHalfSpacePositioning;

            cbRefineAndNormalizeHeYe.Checked = m_allCharactersRefinerSettings.NormalizeHeYe;
            cbConvertLongHeYeToShort.Checked = m_allCharactersRefinerSettings.ConvertLongHeYeToShort;
            cbConvertShortHeYeToLong.Checked = m_allCharactersRefinerSettings.ConvertShortHeYeToLong;

            tetLetterToIgnore.Text = "";
            listViewIgnoreList.Items.Clear();

            if (listViewIgnoreList.Items.Count <= 0) // if the form has been ewnewed with an empty list only
            {
                foreach (char c in m_allCharactersRefinerSettings.GetIgnoreListAsString())
                {
                    AddLetterToIgnoreList(c, true);
                }
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Adds a sequence of character codes to a filtering category
 /// </summary>
 /// <param name="category">The filtering category.</param>
 /// <param name="codes">The codes.</param>
 private void AddCodesToCategory(FilteringCharacterCategory category, params int[] codes)
 {
     foreach (int code in codes)
     {
         m_dicCharCategories.Add(code, category);
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// Filters the char and returns the string for its filtered (i.e. standardized) equivalant.
        /// The string may contain 0, 1, or more characters.
        /// If the length of the string is 0, then the character should have been left out.
        /// If the length of the string is 1, then the character might be left intact or replaced with another character.
        /// If the length of the string is more than 1, then there have been no 1-character replacement for this character.
        /// It is replaced with 2 or more characters. e.g. some fonts have encoded Tashdid, and Tanvin in one character.
        /// To make it standard this character is replaced with 2 characters, one for Tashdid, and the other for Tanvin.
        /// </summary>
        /// <param name="ch">The character to filter.</param>
        /// <param name="ignoreList">The characters to be ignored.</param>
        /// <param name="ignoreCats">The filtering categories to be ignored.</param>
        /// <returns></returns>
        public string FilterChar(char ch, HashSet <char> ignoreList, FilteringCharacterCategory ignoreCats)
        {
            if (ignoreList.Contains(ch))
            {
                return(ch.ToString());
            }

            return(FilterChar(ch, ignoreCats));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Filters every character of the string and returns the filtered string. To see how each character is
        /// filtered see: <see cref="FilterChar(char)"/>
        /// </summary>
        /// <param name="str">The string to be filtered.</param>
        /// <param name="ignoreList">The characters to be ignored.</param>
        /// <param name="ignoreCats">The filtering categories to be ignored.</param>
        /// <returns></returns>
        public string FilterString(string str, HashSet <char> ignoreList, FilteringCharacterCategory ignoreCats)
        {
            var sb = new StringBuilder();

            foreach (char c in str)
            {
                sb.Append(FilterChar(c, ignoreList, ignoreCats));
            }
            return(sb.ToString());
        }
Exemplo n.º 5
0
        public CharacterRefinementVerifier(AllCharactersRefinerSettings settings)
            : base(0, 1)
        {
            m_settings = settings;

            ResetStats();
            ResetCurStepStats();

            m_filteringCategory = settings.GetIgnoredCategories();
            m_ignoreList        = settings.GetIgnoreList();
        }
Exemplo n.º 6
0
        /// <summary>
        /// Filters the char and returns the string for its filtered (i.e. standardized) equivalant.
        /// The string may contain 0, 1, or more characters.
        /// If the length of the string is 0, then the character should have been left out.
        /// If the length of the string is 1, then the character might be left intact or replaced with another character.
        /// If the length of the string is more than 1, then there have been no 1-character replacement for this character.
        /// It is replaced with 2 or more characters. e.g. some fonts have encoded Tashdid, and Tanvin in one character.
        /// To make it standard this character is replaced with 2 characters, one for Tashdid, and the other for Tanvin.
        /// </summary>
        /// <param name="ch">The character to filter.</param>
        /// <param name="ignoreCats">The filtering categories to be ignored.</param>
        /// <returns></returns>
        public string FilterChar(char ch, FilteringCharacterCategory ignoreCats)
        {
            int nCh = Convert.ToInt32(ch);
            FilteringCharacterCategory cat;

            if (m_dicCharCategories.TryGetValue(nCh, out cat))
            {
                return((cat & ignoreCats) == cat?ch.ToString() : FilterChar(ch));
            }

            return(FilterChar(ch));
        }
Exemplo n.º 7
0
 public void SetOffFilteringCategory(FilteringCharacterCategory cat)
 {
     NotIgnoredCategories = (NotIgnoredCategories & (~cat));
 }
Exemplo n.º 8
0
 public void SetFilteringCategory(FilteringCharacterCategory cat)
 {
     NotIgnoredCategories = (NotIgnoredCategories | cat);
 }
Exemplo n.º 9
0
        /// <summary>
        /// Filters the given string with the given options while returning the filtered string as well as filtering statistics.
        /// </summary>
        /// <param name="str">The string to filter.</param>
        /// <param name="ignoreList">list of characters to ignore.</param>
        /// <param name="ignoreCats">The character-categories to ignore.</param>
        /// <returns></returns>
        public FilterResultsWithStats FilterStringWithStats(string str, HashSet <char> ignoreList, FilteringCharacterCategory ignoreCats)
        {
            var sbResult = new StringBuilder(str.Length);

            int numLetters    = 0;
            int numErabs      = 0;
            int numDigits     = 0;
            int numHlafSpaces = 0;

            foreach (var ch in str)
            {
                if (ignoreList != null && ignoreList.Contains(ch))
                {
                    sbResult.Append(ch);
                }

                int    nCh = Convert.ToInt32(ch);
                string filterResult;
                // if there's something to filter
                if (m_dicCharFilterings.TryGetValue(nCh, out filterResult))
                {
                    // try to find the filtering category
                    FilteringCharacterCategory cat;
                    if (m_dicCharCategories.TryGetValue(nCh, out cat))
                    {
                        if ((cat & ignoreCats) == cat)
                        {
                            sbResult.Append(ch);
                        }
                        else
                        {
                            sbResult.Append(filterResult);

                            switch (cat)
                            {
                            case FilteringCharacterCategory.ArabicDigit:
                                numDigits++;
                                break;

                            case FilteringCharacterCategory.Erab:
                                numErabs++;
                                break;

                            case FilteringCharacterCategory.HalfSpace:
                                numHlafSpaces++;
                                break;

                            case FilteringCharacterCategory.Kaaf:
                                numLetters++;
                                break;

                            case FilteringCharacterCategory.Yaa:
                                numLetters++;
                                break;
                            }
                        }
                    }
                    else // if there's no filtering category specified for the given character
                    {
                        numLetters++;
                    }
                }
                else // there's no need to filter the given character
                {
                    sbResult.Append(ch);
                }
            } // end of foreach char in str

            return(new FilterResultsWithStats(sbResult.ToString(), numLetters, numDigits, numErabs, numHlafSpaces));
        }