Пример #1
0
        public override string Mask(char[] raw, IMaskerOption option = null)
        {
            bool withGender = false;

            if (option is RegNoMaskerOption regNoOption)
            {
                withGender = regNoOption.WithGender;
            }

            bool mask = false;

            for (int i = 0; i < raw.Length; i++)
            {
                if (mask)
                {
                    raw[i] = '*';
                }
                else if (withGender && i == 7)
                {
                    mask = true;
                }
                else if (!withGender && i == 6)
                {
                    mask = true;
                }
            }

            return(new string(raw));
        }
Пример #2
0
 public override string Mask(char[] raw, IMaskerOption option = null)
 {
     if (raw.Length == 2)
     {
         return(new string(new char[] { raw[0], '*' }));
     }
     if (raw.Length == 3)
     {
         return(new string(new char[] { raw[0], '*', raw[2] }));
     }
     return(raw[0] + new string('*', raw.Length - 2) + raw[raw.Length - 1]);
 }
Пример #3
0
        public override string Mask(char[] raw, IMaskerOption option = null)
        {
            for (int i = 0; i < raw.Length; i++)
            {
                if (i >= 4 && i <= 7)
                {
                    raw[i] = '*';
                }
            }

            return(new string(raw));
        }
Пример #4
0
        public override string Mask(char[] raw, IMaskerOption option = null)
        {
            for (int i = 0; i < raw.Length; i++)
            {
                if (i < 1)
                {
                    continue;
                }

                raw[i] = '*';
            }

            return(new string(raw));
        }
Пример #5
0
        public override string Mask(char[] raw, IMaskerOption option = null)
        {
            var rule = EmailMaskerRule.All;

            if (option is EmailMaskerOption emailOption)
            {
                rule = emailOption.Rule;
            }

            bool mask = true;

            if (rule == EmailMaskerRule.All)
            {
                for (int i = 0; i < raw.Length; i++)
                {
                    if (raw[i] == '@')
                    {
                        continue;
                    }
                    else if (raw[i] == '.')
                    {
                        mask = false;
                    }
                    else if (mask)
                    {
                        raw[i] = '*';
                    }
                }

                return(new string(raw));
            }
            else
            {
                for (int i = 0; i < raw.Length; i++)
                {
                    if (raw[i] == '@')
                    {
                        int start = i / 4, length = i / 2;
                        for (int j = start; j < start + length; j++)
                        {
                            raw[j] = '*';
                        }
                        break;
                    }
                }

                return(new string(raw));
            }
        }
Пример #6
0
        public override string Mask(char[] raw, IMaskerOption option = null)
        {
            string s = raw.ToString();

            if (option is RegexMaskerOption regexOption)
            {
                var sb = new StringBuilder(s);

                var regex = new Regex(regexOption.Pattern);

                foreach (Match m in regex.Matches(s))
                {
                    sb.Remove(m.Index, m.Length);
                    sb.Insert(m.Index, new string('*', m.Length));
                }

                return(sb.ToString());
            }
            else
            {
                return(s);
            }
        }
Пример #7
0
 public string Mask(StringBuilder raw, IMaskerOption option = null) => Mask(raw.ToString(), option);
Пример #8
0
 public abstract string Mask(char[] raw, IMaskerOption option = null);
Пример #9
0
 public string Mask(string raw, IMaskerOption option = null) => Mask(raw.ToCharArray(), option);