10.10.2015, 08:01
(
Последний раз редактировалось RoboN1X; 10.10.2015 в 15:43.
)
To censor/hide partially/all email address username (not the domain) but still giving the same email address length. The way how it works is explained on the code comments.
Params:
will give output:
will give output:
will give output:
Well if you want to censor all, then set visible_chars to 0.
will give output:
Hope it will be useful :D, it's just a simple function though, it has no valid email address checking.
Код:
stock CensorEmailAddress(const addr[], addr_len, addr_censored[], replace_char = '*', visible_chars = 1) { new at_idx, idx = 0; // Get the last @ symbol position while(idx < addr_len) { if(addr[idx] == '@') { at_idx = idx; } else if(addr[idx] == '\0') { break; // It's end of string, go out } idx++; } if(at_idx > 0 && visible_chars >= 0) // @ symbol is found or not the first character and make sure visible_chars is not negative { while(idx >= at_idx) // Copy the characters after @ symbol { addr_censored[idx] = addr[idx]; idx--; } idx = at_idx-1; while(idx >= visible_chars) // Only censor until visible characters from start { addr_censored[idx] = replace_char; idx--; } while(idx >= 0) // Now copy the visible first characters { addr_censored[idx] = addr[idx]; idx--; } return 1; } return 0; }
- addr[] : the input string for email address
- addr_len : the email address length
- addr_censored[] : the output string for censored email address (any array to be stored/passed by reference)
- replace_char : the character used to censor, default: '*'
- visible_chars : the number of characters to be made visible (not censored/hidden) from start of the address, default: 1
- 0: The at (@) symbol is not found or it's only in the first character, no output given.
- 1: The function is executed successfully, output of censored email address is given.
Код:
new censored_email[128]; CensorEmailAddress("foobar@example.com", sizeof(email), censored_email); printf("Email: %s", censored_email);
Quote:
Email: f*****@example.com |
Код:
new censored_email[128]; CensorEmailAddress("foobar@example.com", sizeof(email), censored_email, '?'); printf("Email: %s", censored_email);
Quote:
Email: f?????@example.com |
Код:
new censored_email[128]; CensorEmailAddress("foobar@example.com", sizeof(email), censored_email, .visible_chars = 3); printf("Email: %s", censored_email);
Quote:
Email: foo***@example.com |
Код:
new censored_email[128]; CensorEmailAddress("foobar@example.com", sizeof(email), censored_email, .visible_chars = 0); printf("Email: %s", censored_email);
Quote:
Email: ******@example.com |