URIBeaconConfig::encodeURI: move const declarations to the top.
This commit is contained in:
parent
6f0d2168e6
commit
5a5834ce2d
1 changed files with 23 additions and 22 deletions
|
@ -376,16 +376,6 @@ class URIBeaconConfigService {
|
|||
* Encode a human-readable URI into the binary format defined by URIBeacon spec (https://github.com/google/uribeacon/tree/master/specification).
|
||||
*/
|
||||
static void encodeURI(const char *uriDataIn, UriData_t uriDataOut, size_t &sizeofURIDataOut) {
|
||||
sizeofURIDataOut = 0;
|
||||
memset(uriDataOut, 0, sizeof(UriData_t));
|
||||
|
||||
if ((uriDataIn == NULL) || (strlen(uriDataIn) == 0)) {
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* handle prefix
|
||||
*/
|
||||
const char *prefixes[] = {
|
||||
"http://www.",
|
||||
"https://www.",
|
||||
|
@ -394,18 +384,6 @@ class URIBeaconConfigService {
|
|||
"urn:uuid:"
|
||||
};
|
||||
const size_t NUM_PREFIXES = sizeof(prefixes) / sizeof(char *);
|
||||
for (unsigned i = 0; i < NUM_PREFIXES; i++) {
|
||||
size_t prefixLen = strlen(prefixes[i]);
|
||||
if (strncmp(uriDataIn, prefixes[i], prefixLen) == 0) {
|
||||
uriDataOut[sizeofURIDataOut++] = i;
|
||||
uriDataIn += prefixLen;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* handle suffixes
|
||||
*/
|
||||
const char *suffixes[] = {
|
||||
".com/",
|
||||
".org/",
|
||||
|
@ -423,6 +401,29 @@ class URIBeaconConfigService {
|
|||
".gov"
|
||||
};
|
||||
const size_t NUM_SUFFIXES = sizeof(suffixes) / sizeof(char *);
|
||||
|
||||
sizeofURIDataOut = 0;
|
||||
memset(uriDataOut, 0, sizeof(UriData_t));
|
||||
|
||||
if ((uriDataIn == NULL) || (strlen(uriDataIn) == 0)) {
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* handle prefix
|
||||
*/
|
||||
for (unsigned i = 0; i < NUM_PREFIXES; i++) {
|
||||
size_t prefixLen = strlen(prefixes[i]);
|
||||
if (strncmp(uriDataIn, prefixes[i], prefixLen) == 0) {
|
||||
uriDataOut[sizeofURIDataOut++] = i;
|
||||
uriDataIn += prefixLen;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* handle suffixes
|
||||
*/
|
||||
while (*uriDataIn && (sizeofURIDataOut < URI_DATA_MAX)) {
|
||||
/* check for suffix match */
|
||||
unsigned i;
|
||||
|
|
Loading…
Reference in a new issue