Skip to content

Instantly share code, notes, and snippets.

@klondi
Created January 10, 2015 16:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save klondi/7b5aa6a6f47ed2c9a36b to your computer and use it in GitHub Desktop.
Save klondi/7b5aa6a6f47ed2c9a36b to your computer and use it in GitHub Desktop.
This is code I wrote for an I2PD http parser which will never see the light, consider it public domain
inline bool isValidHeaderChar(uint8_t c) { return (c > 0x20 && c != 0x7f); }
inline bool isValidHeaderNameChar(uint8_t c) {
//This is a bool vector containing the valid characters
//!#$%&'*+-.^_`|~0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
static const uint8_t *valid = {0, 0, 0, 0, 250, 108, 255, 3, 254, 255, 255, 199,
255, 255, 255, 87, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
return valid[(x / 8) & 31] & (1 << (x & 7));
}
@klondi
Copy link
Author

klondi commented Jan 10, 2015

Keep in mind that you can use compres the vector if you remove values below 0x20 and over 0x7f

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment