Assorted whitespace cleanup and typo fixes.
[haiku.git] / src / kits / tracker / TrackerString.h
blob0706ac90205264ac1341c38dccafb42e97015f1d
1 /*
2 Open Tracker License
4 Terms and Conditions
6 Copyright (c) 1991-2000, Be Incorporated. All rights reserved.
8 Permission is hereby granted, free of charge, to any person obtaining a copy of
9 this software and associated documentation files (the "Software"), to deal in
10 the Software without restriction, including without limitation the rights to
11 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
12 of the Software, and to permit persons to whom the Software is furnished to do
13 so, subject to the following conditions:
15 The above copyright notice and this permission notice applies to all licensees
16 and shall be included in all copies or substantial portions of the Software.
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF TITLE, MERCHANTABILITY,
20 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 BE INCORPORATED BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION
23 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 Except as contained in this notice, the name of Be Incorporated shall not be
26 used in advertising or otherwise to promote the sale, use or other dealings in
27 this Software without prior written authorization from Be Incorporated.
29 Tracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or registered trademarks
30 of Be Incorporated in the United States and other countries. Other brand product
31 names are registered trademarks or trademarks of their respective holders.
32 All rights reserved.
34 #ifndef _TRACKER_STRING_H
35 #define _TRACKER_STRING_H
38 #include <ctype.h>
40 #include <OS.h>
41 #include <String.h>
43 #include "RegExp.h"
46 namespace BPrivate {
48 enum TrackerStringExpressionType {
49 kNone = B_ERROR,
50 kStartsWith = 0,
51 kEndsWith,
52 kContains,
53 kGlobMatch,
54 kRegexpMatch
58 class TrackerString : public BString
60 public:
61 TrackerString();
62 TrackerString(const char*);
63 TrackerString(const TrackerString&);
64 TrackerString(const char*, int32 maxLength);
65 ~TrackerString();
67 bool Matches(const char*, bool caseSensitivity = false,
68 TrackerStringExpressionType expressionType = kGlobMatch) const;
70 bool MatchesRegExp(const char*, bool caseSensitivity = true) const;
71 bool MatchesRegExp(const RegExp&) const;
72 bool MatchesRegExp(const RegExp*) const;
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;
79 private:
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;
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;
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;
98 inline bool
99 TrackerString::MatchesRegExp(const RegExp* expression) const
101 if (expression == NULL || expression->InitCheck() != B_OK)
102 return false;
104 return expression->Matches(*this);
108 inline bool
109 TrackerString::MatchesRegExp(const RegExp &expression) const
111 if (expression.InitCheck() != B_OK)
112 return false;
114 return expression.Matches(*this);
118 inline char
119 TrackerString::ConditionalToLower(char c, bool caseSensitivity) const
121 return caseSensitivity ? c : (char)tolower(c);
125 inline bool
126 TrackerString::CharsAreEqual(char char1, char char2,
127 bool caseSensitivity) const
129 return ConditionalToLower(char1, caseSensitivity)
130 == ConditionalToLower(char2, caseSensitivity);
133 } // namespace BPrivate
135 using namespace BPrivate;
138 #endif // _TRACKER_STRING_H