2021-02-07 22:31:04 +03:00
|
|
|
### URI Parser
|
2021-02-03 08:09:50 +03:00
|
|
|
|
2021-02-07 22:31:04 +03:00
|
|
|
### Overview
|
2021-02-03 08:09:50 +03:00
|
|
|
|
2023-06-06 20:26:34 +03:00
|
|
|
- URI parser but not a full-featured one. It just splits parts of a url.
|
2021-02-03 08:09:50 +03:00
|
|
|
- Internally, it does a single allocation but each part is represented as null
|
2023-06-06 20:26:34 +03:00
|
|
|
terminated string, so it plays nicely with C string functions.
|
2021-02-03 08:09:50 +03:00
|
|
|
|
2021-02-07 22:31:04 +03:00
|
|
|
### Usage
|
2021-02-03 08:09:50 +03:00
|
|
|
|
|
|
|
```c
|
|
|
|
#include "sc_uri.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
2023-06-06 20:26:34 +03:00
|
|
|
struct sc_uri *uri;
|
2021-02-03 08:09:50 +03:00
|
|
|
uri = sc_uri_create("http://user:pass@any.com:8042/over/there?name=jane#doe");
|
|
|
|
printf("%s \n", uri->str); // prints "http://user:pass@any.com:8042/over/there?name=jane#doe"
|
|
|
|
printf("%s \n", uri->scheme); // prints "http"
|
|
|
|
printf("%s \n", uri->host); // prints "any.com"
|
|
|
|
printf("%s \n", uri->userinfo); // prints "user:pass"
|
|
|
|
printf("%s \n", uri->port); // prints "8042"
|
|
|
|
printf("%s \n", uri->path); // prints "/over/there"
|
|
|
|
printf("%s \n", uri->query); // prints "name=jane"
|
|
|
|
printf("%s \n", uri->fragment); // prints "doe"
|
|
|
|
|
2023-06-06 20:26:34 +03:00
|
|
|
sc_uri_destroy(uri);
|
2021-02-03 08:09:50 +03:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
```
|