case.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*!
  2. \file lib/db/dbmi_base/case.c
  3. \brief DBMI Library (base) - case string conversion
  4. (C) 1999-2009, 2011 by the GRASS Development Team
  5. This program is free software under the GNU General Public License
  6. (>=v2). Read the file COPYING that comes with GRASS for details.
  7. \author Joel Jones (CERL/UIUC), Radim Blazek
  8. \author Doxygenized by Martin Landa <landa.martin gmail.com> (2011)
  9. */
  10. #include <grass/dbmi.h>
  11. /*!
  12. \brief Convert character to lowercase
  13. \param s character to be modified
  14. */
  15. void db_char_to_lowercase(char *s)
  16. {
  17. if (*s >= 'A' && *s <= 'Z')
  18. *s -= 'A' - 'a';
  19. }
  20. /*!
  21. \brief Convert character to uppercase
  22. \param s character to be modified
  23. */
  24. void db_char_to_uppercase(char *s)
  25. {
  26. if (*s >= 'a' && *s <= 'z')
  27. *s += 'A' - 'a';
  28. }
  29. /*!
  30. \brief Convert string to lowercase
  31. \param s string buffer to be modified
  32. */
  33. void db_Cstring_to_lowercase(char *s)
  34. {
  35. while (*s)
  36. db_char_to_lowercase(s++);
  37. }
  38. /*!
  39. \brief Convert string to lowercase
  40. \param s string buffer to be modified
  41. */
  42. void db_Cstring_to_uppercase(char *s)
  43. {
  44. while (*s)
  45. db_char_to_uppercase(s++);
  46. }
  47. /*!
  48. \brief Compare strings case-insensitive
  49. \param a,b string buffers to be compared
  50. \return 0 strings equal
  51. \return 1 otherwise
  52. */
  53. int db_nocase_compare(const char *a, const char *b)
  54. {
  55. char s, t;
  56. while (*a && *b) {
  57. s = *a++;
  58. t = *b++;
  59. db_char_to_uppercase(&s);
  60. db_char_to_uppercase(&t);
  61. if (s != t)
  62. return 0;
  63. }
  64. return (*a == 0 && *b == 0);
  65. }