Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  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. typedef signed char int8_t;
  13. typedef signed short int16_t;
  14. typedef signed int int32_t;
  15.  
  16. typedef unsigned char uint8_t;
  17. typedef unsigned short uint16_t;
  18. typedef unsigned int uint32_t;
  19. #include "utils/string.h"
  20.  
  21.  
  22.  
  23.  
  24.  
  25. /**
  26.  * Check that one string is exactly equal to another
  27.  *
  28.  * \param a     String to compare
  29.  * \param a_len Length of first string
  30.  * \param b     String to compare
  31.  * \param b_len Length of second string
  32.  */
  33. bool hubbub_string_match(const uint8_t *a, size_t a_len,
  34.                 const uint8_t *b, size_t b_len)
  35. {
  36.         if (a_len != b_len)
  37.                 return false;
  38.  
  39.         return memcmp((const char *) a, (const char *) b, b_len) == 0;
  40. }
  41.  
  42. /**
  43.  * Check that one string is case-insensitively equal to another
  44.  *
  45.  * \param a     String to compare
  46.  * \param a_len Length of first string
  47.  * \param b     String to compare
  48.  * \param b_len Length of second string
  49.  */
  50. bool hubbub_string_match_ci(const uint8_t *a, size_t a_len,
  51.                 const uint8_t *b, size_t b_len)
  52. {
  53.         if (a_len != b_len)
  54.                 return false;
  55.  
  56.         while (b_len-- > 0) {
  57.                 uint8_t aa = *(a++);
  58.                 uint8_t bb = *(b++);
  59.  
  60.                 aa = ('a' <= aa && aa <= 'z') ? (aa - 0x20) : aa;
  61.                 bb = ('a' <= bb && bb <= 'z') ? (bb - 0x20) : bb;
  62.  
  63.                 if (aa != bb)
  64.                         return false;
  65.         }
  66.  
  67.         return true;
  68. }
  69.