1/* 2Open Tracker License 3 4Terms and Conditions 5 6Copyright (c) 1991-2000, Be Incorporated. All rights reserved. 7 8Permission is hereby granted, free of charge, to any person obtaining a copy of 9this software and associated documentation files (the "Software"), to deal in 10the Software without restriction, including without limitation the rights to 11use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 12of the Software, and to permit persons to whom the Software is furnished to do 13so, subject to the following conditions: 14 15The above copyright notice and this permission notice applies to all licensees 16and shall be included in all copies or substantial portions of the Software. 17 18THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF TITLE, MERCHANTABILITY, 20FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 21BE INCORPORATED BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 22AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION 23WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 25Except as contained in this notice, the name of Be Incorporated shall not be 26used in advertising or otherwise to promote the sale, use or other dealings in 27this Software without prior written authorization from Be Incorporated. 28 29Tracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or registered trademarks 30of Be Incorporated in the United States and other countries. Other brand product 31names are registered trademarks or trademarks of their respective holders. 32All rights reserved. 33*/ 34#ifndef _TRACKER_STRING_H 35#define _TRACKER_STRING_H 36 37 38#include <ctype.h> 39 40#include <OS.h> 41#include <String.h> 42 43#include "RegExp.h" 44 45 46namespace BPrivate { 47 48enum TrackerStringExpressionType { 49 kNone = B_ERROR, 50 kStartsWith = 0, 51 kEndsWith, 52 kContains, 53 kGlobMatch, 54 kRegexpMatch 55}; 56 57 58class TrackerString : public BString 59{ 60public: 61 TrackerString(); 62 TrackerString(const char*); 63 TrackerString(const TrackerString&); 64 TrackerString(const char*, int32 maxLength); 65 ~TrackerString(); 66 67 bool Matches(const char*, bool caseSensitivity = false, 68 TrackerStringExpressionType expressionType = kGlobMatch) const; 69 70 bool MatchesRegExp(const char*, bool caseSensitivity = true) const; 71 bool MatchesRegExp(const RegExp&) const; 72 bool MatchesRegExp(const RegExp*) const; 73 74 bool MatchesGlob(const char*, bool caseSensitivity = false) const; 75 bool EndsWith(const char*, bool caseSensitivity = false) const; 76 bool StartsWith(const char*, bool caseSensitivity = false) const; 77 bool Contains(const char*, bool caseSensitivity = false) const; 78 79private: 80 bool IsGlyph(char) const; 81 bool IsInsideGlyph(char) const; 82 // Not counting start! 83 bool IsStartOfGlyph(char) const; 84 const char* MoveToEndOfGlyph(const char*) const; 85 86 // Functions for Glob matching: 87 bool MatchesBracketExpression(const char* string, const char* pattern, 88 bool caseSensitivity) const; 89 bool StringMatchesPattern(const char* string, const char* pattern, 90 bool caseSensitivity) const; 91 92 char ConditionalToLower(char c, bool toLower) const; 93 bool CharsAreEqual(char char1, char char2, bool toLower) const; 94 bool UTF8CharsAreEqual(const char* string1, const char* string2) const; 95}; 96 97 98inline bool 99TrackerString::MatchesRegExp(const RegExp* expression) const 100{ 101 if (expression == NULL || expression->InitCheck() != B_OK) 102 return false; 103 104 return expression->Matches(*this); 105} 106 107 108inline bool 109TrackerString::MatchesRegExp(const RegExp &expression) const 110{ 111 if (expression.InitCheck() != B_OK) 112 return false; 113 114 return expression.Matches(*this); 115} 116 117 118inline char 119TrackerString::ConditionalToLower(char c, bool caseSensitivity) const 120{ 121 return caseSensitivity ? c : (char)tolower(c); 122} 123 124 125inline bool 126TrackerString::CharsAreEqual(char char1, char char2, 127 bool caseSensitivity) const 128{ 129 return ConditionalToLower(char1, caseSensitivity) 130 == ConditionalToLower(char2, caseSensitivity); 131} 132 133} // namespace BPrivate 134 135using namespace BPrivate; 136 137 138#endif // _TRACKER_STRING_H 139