FilenameField.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. #include "FilenameField.h"
  2. #include "../nde.h"
  3. //---------------------------------------------------------------------------
  4. FilenameField::FilenameField(const wchar_t *Str, int strkind) : StringField(Str, strkind)
  5. {
  6. Type = FIELD_FILENAME;
  7. }
  8. //---------------------------------------------------------------------------
  9. FilenameField::FilenameField()
  10. {
  11. Type = FIELD_FILENAME;
  12. }
  13. //---------------------------------------------------------------------------
  14. int FilenameField::Compare(Field *Entry)
  15. {
  16. if (!Entry) return -1;
  17. if (!CompatibleFields(Entry->GetType(), GetType()))
  18. return 0;
  19. return mywcsicmp_fn(GetStringW(), ((FilenameField*)Entry)->GetStringW());
  20. }
  21. //---------------------------------------------------------------------------
  22. int FilenameField::Starts(Field *Entry)
  23. {
  24. if (!Entry) return -1;
  25. if (!CompatibleFields(Entry->GetType(), GetType()))
  26. return 0;
  27. const wchar_t *p = ((StringField*)Entry)->GetStringW();
  28. const wchar_t *d = GetStringW();
  29. if (!d || !p) return 0;
  30. return nde_fnbegins(d, p);
  31. }
  32. //---------------------------------------------------------------------------
  33. int FilenameField::Contains(Field *Entry)
  34. {
  35. if (!Entry) return -1;
  36. if (!CompatibleFields(Entry->GetType(), GetType()))
  37. return 0;
  38. const wchar_t *p = ((StringField*)Entry)->GetStringW();
  39. const wchar_t *d = GetStringW();
  40. if (!d || !p) return 0;
  41. return nde_fncontains(GetStringW(), ((StringField*)Entry)->GetStringW());
  42. }
  43. Field *FilenameField::Clone(Table *pTable)
  44. {
  45. FilenameField *clone = new FilenameField(StringW, STRING_IS_NDESTRING);
  46. clone->Pos = FIELD_CLONE;
  47. clone->ID = ID;
  48. clone->MaxSizeOnDisk = (uint32_t)GetDataSize();
  49. return clone;
  50. }
  51. // TODO: make file system string comparison functions
  52. //---------------------------------------------------------------------------
  53. bool FilenameField::ApplyFilter(Field *Data, int op)
  54. {
  55. // TODO: maybe do this?
  56. if (op == FILTER_ISEMPTY || op == FILTER_ISNOTEMPTY)
  57. {
  58. bool r = (op == FILTER_ISEMPTY);
  59. if (!StringW)
  60. return r;
  61. if (StringW && StringW[0] == 0)
  62. return r;
  63. return !r;
  64. }
  65. //
  66. bool r;
  67. wchar_t *p=0;
  68. if (Data->GetType() == FIELD_STRING)
  69. p = ((StringField *)Data)->GetStringW();
  70. else
  71. p = ((FilenameField *)Data)->GetStringW();
  72. wchar_t *d = GetStringW();
  73. if (!p)
  74. p = L"";
  75. if (!d)
  76. d = L"";
  77. switch (op)
  78. {
  79. case FILTER_EQUALS:
  80. r = !nde_wcsicmp_fn(d, p);
  81. break;
  82. case FILTER_NOTEQUALS:
  83. r = !!nde_wcsicmp_fn(d, p);
  84. break;
  85. case FILTER_CONTAINS:
  86. r = nde_fncontains(d, p);
  87. break;
  88. case FILTER_NOTCONTAINS:
  89. r = !nde_fncontains(d, p);
  90. break;
  91. case FILTER_ABOVE:
  92. r = (bool)(nde_wcsicmp_fn(d, p) > 0);
  93. break;
  94. case FILTER_ABOVEOREQUAL:
  95. r = (bool)(nde_wcsicmp_fn(d, p) >= 0);
  96. break;
  97. case FILTER_BELOW:
  98. r = (bool)(nde_wcsicmp_fn(d, p) < 0);
  99. break;
  100. case FILTER_BELOWOREQUAL:
  101. r = (bool)(nde_wcsicmp_fn(d, p) <= 0);
  102. break;
  103. case FILTER_BEGINS:
  104. r = nde_fnbegins(d, p);
  105. break;
  106. case FILTER_ENDS:
  107. r = nde_fnends(d, p);
  108. break;
  109. case FILTER_LIKE:
  110. r = (bool)(nde_wcsicmp_fn(d, p) == 0);
  111. break;
  112. default:
  113. r = true;
  114. break;
  115. }
  116. return r;
  117. }