Skip to content

Commit

Permalink
Add function to check if something is a value utf8 string
Browse files Browse the repository at this point in the history
  • Loading branch information
arr2036 committed May 17, 2015
1 parent 52d51a4 commit 4f2f33d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/include/libradius.h
Expand Up @@ -725,6 +725,7 @@ size_t fr_bin2hex(char *hex, uint8_t const *bin, size_t inlen);
size_t fr_hex2bin(uint8_t *bin, size_t outlen, char const *hex, size_t inlen);
uint32_t fr_strtoul(char const *value, char **end);
bool is_whitespace(char const *value);
bool is_printable(void const *value, size_t len);
bool is_integer(char const *value);
bool is_zero(char const *value);

Expand Down
24 changes: 24 additions & 0 deletions src/lib/misc.c
Expand Up @@ -1139,6 +1139,30 @@ bool is_whitespace(char const *value)
return true;
}

/** Check whether the string is made up of printable UTF8 chars
*
* @param value to check.
* @param len of value.
*
* @return
* - true if the string is printable.
* - false if the string contains non printable chars
*/
bool is_printable(void const *value, size_t len)
{
uint8_t const *p = value;
int clen;
size_t i;

for (i = 0; i < len; i++) {
clen = fr_utf8_char(p);
if (clen == 0) return false;
i += (size_t)clen;
p += clen;
}
return true;
}

/** Check whether the string is all numbers
*
* @return
Expand Down

0 comments on commit 4f2f33d

Please sign in to comment.