Skip to content

Instantly share code, notes, and snippets.

@jbenner-radham
Last active August 29, 2015 13:58
Show Gist options
  • Save jbenner-radham/10219982 to your computer and use it in GitHub Desktop.
Save jbenner-radham/10219982 to your computer and use it in GitHub Desktop.
Prototyping an HTTP content negotiation function for super magic fun time!
#include <assert.h>
#include <stdio.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <string.h>
/**
* @link https://developer.mozilla.org/en-US/docs/HTTP/Content_negotiation
*/
int main()
{
const char *accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
/**
* @see https://tools.ietf.org/html/rfc2616#section-14.1
*/
struct accept_vector {
char *str;
ptrdiff_t pdiff;
float qvalue;
};
// Unsigned char 0 - 255 (256 size)
//printf("%.1f\n", x);
struct accept_vector vect;
vect.str = (char*)accept;
//char *buffer = {0};
//buffer = vect.str;
char *buffer;
//buffer = vect.str;
// ---
for (buffer = vect.str; *(vect.str++); buffer = vect.str) {
puts(buffer);
}
// ---
//do {
// puts(vect.str);
//} while (*vect.str++);
//puts(buffer);
for (unsigned int i = 0, length = strlen(accept); i <= length; ++i) {
//char *sub_accept = (char*)accept;
if (accept[i] == ';') {
//vect.end = i - 1;
/**
* Returns the first match after the semicolon is found (via the `+ (i + 1)` method)
* e.g. the pointer index incremented plus one
*/
// Example from our `accept` string.
// Found: q=0.9,*/*;q=0.8
//printf("Found: %s\n", (const char*)accept + (i + 1));
//printf("Direction vector: %d - %d\nString: ", vect.start, vect.end);
//for (unsigned int x = vect.start; x <= vect.end; ++x) {
//printf("%c!!!\n", sub_accept[x]);
//}
//printf("\n");
//sub_accept[vect.end + 1] = '\0';
//printf("%s\n", sub_accept);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment