StyleContext.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // Scintilla source code edit control
  2. /** @file StyleContext.cxx
  3. ** Lexer infrastructure.
  4. **/
  5. // Copyright 1998-2004 by Neil Hodgson <neilh@scintilla.org>
  6. // This file is in the public domain.
  7. #include <stdlib.h>
  8. #include <string.h>
  9. #include <stdio.h>
  10. #include <assert.h>
  11. #include <ctype.h>
  12. #include "ILexer.h"
  13. #include "LexAccessor.h"
  14. #include "Accessor.h"
  15. #include "StyleContext.h"
  16. #include "CharacterSet.h"
  17. #ifdef SCI_NAMESPACE
  18. using namespace Scintilla;
  19. #endif
  20. bool StyleContext::MatchIgnoreCase(const char *s) {
  21. if (MakeLowerCase(ch) != static_cast<unsigned char>(*s))
  22. return false;
  23. s++;
  24. if (MakeLowerCase(chNext) != static_cast<unsigned char>(*s))
  25. return false;
  26. s++;
  27. for (int n = 2; *s; n++) {
  28. if (static_cast<unsigned char>(*s) !=
  29. MakeLowerCase(static_cast<unsigned char>(styler.SafeGetCharAt(currentPos + n, 0))))
  30. return false;
  31. s++;
  32. }
  33. return true;
  34. }
  35. static void getRange(Sci_PositionU start,
  36. Sci_PositionU end,
  37. LexAccessor &styler,
  38. char *s,
  39. Sci_PositionU len) {
  40. Sci_PositionU i = 0;
  41. while ((i < end - start + 1) && (i < len-1)) {
  42. s[i] = styler[start + i];
  43. i++;
  44. }
  45. s[i] = '\0';
  46. }
  47. void StyleContext::GetCurrent(char *s, Sci_PositionU len) {
  48. getRange(styler.GetStartSegment(), currentPos - 1, styler, s, len);
  49. }
  50. static void getRangeLowered(Sci_PositionU start,
  51. Sci_PositionU end,
  52. LexAccessor &styler,
  53. char *s,
  54. Sci_PositionU len) {
  55. Sci_PositionU i = 0;
  56. while ((i < end - start + 1) && (i < len-1)) {
  57. s[i] = static_cast<char>(tolower(styler[start + i]));
  58. i++;
  59. }
  60. s[i] = '\0';
  61. }
  62. void StyleContext::GetCurrentLowered(char *s, Sci_PositionU len) {
  63. getRangeLowered(styler.GetStartSegment(), currentPos - 1, styler, s, len);
  64. }