Hubbub
string.c
Go to the documentation of this file.
1 /*
2  * This file is part of Hubbub.
3  * Licensed under the MIT License,
4  * http://www.opensource.org/licenses/mit-license.php
5  * Copyright 2008 Andrew Sidwell
6  */
7 
8 #include <stddef.h>
9 #include <inttypes.h>
10 #include <stdbool.h>
11 #include <string.h>
12 #include "utils/string.h"
13 
14 
23 bool hubbub_string_match(const uint8_t *a, size_t a_len,
24  const uint8_t *b, size_t b_len)
25 {
26  if (a_len != b_len)
27  return false;
28 
29  return memcmp((const char *) a, (const char *) b, b_len) == 0;
30 }
31 
40 bool hubbub_string_match_ci(const uint8_t *a, size_t a_len,
41  const uint8_t *b, size_t b_len)
42 {
43  if (a_len != b_len)
44  return false;
45 
46  while (b_len-- > 0) {
47  uint8_t aa = *(a++);
48  uint8_t bb = *(b++);
49 
50  aa = ('a' <= aa && aa <= 'z') ? (aa - 0x20) : aa;
51  bb = ('a' <= bb && bb <= 'z') ? (bb - 0x20) : bb;
52 
53  if (aa != bb)
54  return false;
55  }
56 
57  return true;
58 }
bool hubbub_string_match_ci(const uint8_t *a, size_t a_len, const uint8_t *b, size_t b_len)
Check that one string is case-insensitively equal to another.
Definition: string.c:40
bool hubbub_string_match(const uint8_t *a, size_t a_len, const uint8_t *b, size_t b_len)
Check that one string is exactly equal to another.
Definition: string.c:23