CharacterSet.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // Scintilla source code edit control
  2. /** @file CharacterSet.cxx
  3. ** Simple case functions for ASCII.
  4. ** Lexer infrastructure.
  5. **/
  6. // Copyright 1998-2010 by Neil Hodgson <neilh@scintilla.org>
  7. // The License.txt file describes the conditions under which this software may be distributed.
  8. #include <stdlib.h>
  9. #include <string.h>
  10. #include <stdio.h>
  11. #include <assert.h>
  12. #include <ctype.h>
  13. #include "CharacterSet.h"
  14. #ifdef SCI_NAMESPACE
  15. using namespace Scintilla;
  16. #endif
  17. #ifdef SCI_NAMESPACE
  18. namespace Scintilla {
  19. #endif
  20. int CompareCaseInsensitive(const char *a, const char *b) {
  21. while (*a && *b) {
  22. if (*a != *b) {
  23. char upperA = static_cast<char>(MakeUpperCase(*a));
  24. char upperB = static_cast<char>(MakeUpperCase(*b));
  25. if (upperA != upperB)
  26. return upperA - upperB;
  27. }
  28. a++;
  29. b++;
  30. }
  31. // Either *a or *b is nul
  32. return *a - *b;
  33. }
  34. int CompareNCaseInsensitive(const char *a, const char *b, size_t len) {
  35. while (*a && *b && len) {
  36. if (*a != *b) {
  37. char upperA = static_cast<char>(MakeUpperCase(*a));
  38. char upperB = static_cast<char>(MakeUpperCase(*b));
  39. if (upperA != upperB)
  40. return upperA - upperB;
  41. }
  42. a++;
  43. b++;
  44. len--;
  45. }
  46. if (len == 0)
  47. return 0;
  48. else
  49. // Either *a or *b is nul
  50. return *a - *b;
  51. }
  52. #ifdef SCI_NAMESPACE
  53. }
  54. #endif