NCBI C++ ToolKit
String_constraint.hpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: String_constraint.hpp 100215 2023-07-09 00:39:58Z gotvyans $
2  * ===========================================================================
3  *
4  * PUBLIC DOMAIN NOTICE
5  * National Center for Biotechnology Information
6  *
7  * This software/database is a "United States Government Work" under the
8  * terms of the United States Copyright Act. It was written as part of
9  * the author's official duties as a United States Government employee and
10  * thus cannot be copyrighted. This software/database is freely available
11  * to the public for use. The National Library of Medicine and the U.S.
12  * Government have not placed any restriction on its use or reproduction.
13  *
14  * Although all reasonable efforts have been taken to ensure the accuracy
15  * and reliability of the software and data, the NLM and the U.S.
16  * Government do not and cannot warrant the performance or results that
17  * may be obtained by using this software or data. The NLM and the U.S.
18  * Government disclaim all warranties, express or implied, including
19  * warranties of performance, merchantability or fitness for any particular
20  * purpose.
21  *
22  * Please cite the author in any work or product based on this material.
23  *
24  * ===========================================================================
25  *
26  */
27 
28 /// @file String_constraint.hpp
29 /// User-defined methods of the data storage class.
30 ///
31 /// This file was originally generated by application DATATOOL
32 /// using the following specifications:
33 /// 'macro.asn'.
34 ///
35 /// New methods or data members can be added to it if needed.
36 /// See also: String_constraint_.hpp
37 
38 
39 #ifndef OBJECTS_MACRO_STRING_CONSTRAINT_HPP
40 #define OBJECTS_MACRO_STRING_CONSTRAINT_HPP
41 
43 #include <serial/iterator.hpp>
45 
47 BEGIN_objects_SCOPE // namespace ncbi::objects::
48 
50 {
51 public:
53 
54  CAutoLowerCase(const string& v) :
55  m_original(v)
56  {
57  }
59  m_original(std::move(v.m_original)),
60  m_lowercase(std::move(v.m_lowercase)),
61  m_uppercase(std::move(v.m_uppercase))
62  {
63  }
65  {
66  m_original = std::move(v.m_original);
67  m_lowercase = std::move(v.m_lowercase);
68  m_uppercase = std::move(v.m_uppercase);
69  return *this;
70  }
72  {
73  m_original = std::move(v);
74  m_lowercase.clear();
75  m_uppercase.clear();
76  return *this;
77  }
78  CAutoLowerCase& operator=(const string& v)
79  {
80  m_original = v;
81  m_lowercase.clear();
82  m_uppercase.clear();
83  return *this;
84  }
85 
86  const string& lowercase() const
87  {
88  if (m_lowercase.empty() && !m_original.empty())
89  {
92  }
93  return m_lowercase;
94  }
95  const string& uppercase() const
96  {
97  if (m_uppercase.empty() && !m_original.empty())
98  {
101  }
102  return m_uppercase;
103  }
104  operator const string&() const
105  {
106  return m_original;
107  }
108  const string& original() const
109  {
110  return m_original;
111  }
112 
113 private:
116 
117  string m_original;
118  mutable string m_lowercase;
119  mutable string m_uppercase;
120 };
121 
123 {
124 public:
126 
128  {
129  }
131  {
132  }
133  const CAutoLowerCase& original() const
134  {
135  return m_original;
136  }
137  CMatchString& operator=(const string&s)
138  {
139  m_original = s;
141  m_weaselmask = 0;
142  return *this;
143  };
144 
145  operator const string&() const
146  {
147  return m_original;
148  }
149 
151 
153  {
154  PopWeasel();
156  }
158  {
159  PopWeasel();
161  }
163  {
164  PopWeasel();
166  }
167 
168  unsigned GetWeaselMask() const { PopWeasel(); return m_weaselmask; }
169 
170 private:
171  void x_PopWeasel() const;
174  mutable unsigned m_weaselmask;
175 };
176 
177 /////////////////////////////////////////////////////////////////////////////
179 {
181 public:
183  virtual ~CString_constraint();
184 
185  // get all string type data from object
186  template <class T>
187  void GetStringsFromObject(const T& obj, vector <string>& strs) const
188  {
191  for (it = ConstBegin(obj); it; ++it) {
192  strs.push_back(*static_cast<const string*>(it.GetFoundPtr()));
193  }
194  }
195 
196  bool Match(const CMatchString& str) const;
197  bool Empty() const;
198  bool ReplaceStringConstraintPortionInString(string& result, const CMatchString& str, const string& replace) const;
200  {
201  m_match = kEmptyStr;
203  }
205  {
206  m_match = kEmptyStr;
208  }
209 
210  static const vector<string> s_WeaselWords;
211 
212 private:
213  // Prohibit copy constructor and assignment operator
216 
217  typedef enum
218  {
223  } ECase;
224 
226  CTempString x_GetCompareString(const CMatchString& s, ECase e_case = e_automatic) const;
227 
229  bool x_IsAllCaps(const CMatchString& str) const;
230  bool x_IsAllLowerCase(const CMatchString& str) const;
231  bool x_IsAllPunctuation(const CMatchString& str) const;
232  bool x_IsSkippable(const char ch) const;
233  bool x_IsAllSkippable(const CTempString& str) const;
234  // Checks whether the first letter of the first word is capitalized
235  bool x_IsFirstCap(const CMatchString& str) const;
236  // Checks whether the first letter of each word is capitalized
237  bool x_IsFirstEachCap(const CMatchString& str) const;
238 
239  bool x_PartialCompare(const string& str, const string& pattern, char prev_char, size_t & match_len) const;
240  bool x_AdvancedStringCompare(const string& str,
241  const string& str_match,
242  const char prev_char,
243  size_t * ini_target_match_len = 0) const;
244  bool x_AdvancedStringMatch(const string& str,const string& tmp_match) const;
245  bool x_IsWholeWordMatch(const CTempString& start,
246  size_t found,
247  size_t match_len,
248  bool disallow_slash = false) const;
249  bool x_MatchFound(CTempString& search, CTempString& pattern) const;
250 
251  bool x_ReplaceContains(string& val, const string& replace) const;
252 
254 };
255 
256 
257 END_objects_SCOPE // namespace ncbi::objects::
259 
260 #endif // OBJECTS_MACRO_STRING_CONSTRAINT_HPP
Data storage class.
const string & uppercase() const
CAutoLowerCase(const CAutoLowerCase &)
CAutoLowerCase(const string &v)
const string & original() const
CAutoLowerCase(CAutoLowerCase &&v)
const string & lowercase() const
CAutoLowerCase & operator=(const CAutoLowerCase &)
CAutoLowerCase & operator=(string &&v)
CAutoLowerCase & operator=(const string &v)
CAutoLowerCase & operator=(CAutoLowerCase &&v)
CTempString GetNoweaselLC() const
CTempString GetNoweasel() const
void PopWeasel() const
CTempString GetNoweaselUC() const
CMatchString(const string &v)
CTempString::size_type m_noweasel_start
CAutoLowerCase m_original
CMatchString(const char *v)
CMatchString & operator=(const string &s)
void x_PopWeasel() const
unsigned GetWeaselMask() const
const CAutoLowerCase & original() const
CString_constraint_Base –.
CTempString x_GetCompareString(const CMatchString &s, ECase e_case=e_automatic) const
bool x_IsAllSkippable(const CTempString &str) const
bool x_IsWholeWordMatch(const CTempString &start, size_t found, size_t match_len, bool disallow_slash=false) const
TMatch_text & SetMatch_text(void)
CTempString x_GetConstraintString(ECase e_case=e_automatic) const
bool x_MatchFound(CTempString &search, CTempString &pattern) const
bool x_IsFirstCap(const CMatchString &str) const
bool ReplaceStringConstraintPortionInString(string &result, const CMatchString &str, const string &replace) const
bool x_IsAllLowerCase(const CMatchString &str) const
bool x_IsAllPunctuation(const CMatchString &str) const
void GetStringsFromObject(const T &obj, vector< string > &strs) const
bool x_ReplaceContains(string &val, const string &replace) const
bool Match(const CMatchString &str) const
bool x_DoesSingleStringMatchConstraint(const CMatchString &str) const
bool x_IsAllCaps(const CMatchString &str) const
CString_constraint & operator=(const CString_constraint &value)=delete
bool x_IsFirstEachCap(const CMatchString &str) const
bool x_AdvancedStringCompare(const string &str, const string &str_match, const char prev_char, size_t *ini_target_match_len=0) const
CString_constraint_Base Tparent
void SetMatch_text(const TMatch_text &value)
bool x_IsSkippable(const char ch) const
static const vector< string > s_WeaselWords
bool x_AdvancedStringMatch(const string &str, const string &tmp_match) const
CString_constraint(const CString_constraint &value)=delete
bool x_PartialCompare(const string &str, const string &pattern, char prev_char, size_t &match_len) const
CTempString implements a light-weight string on top of a storage buffer whose lifetime management is ...
Definition: tempstr.hpp:65
Template base class for CTypesIterator and CTypesConstIterator Do not use it directly.
Definition: iterator.hpp:565
#define T(s)
Definition: common.h:230
static const char * str(char *buf, int n)
Definition: stats.c:84
CParent::TObjectInfo::TObjectPtrType GetFoundPtr(void) const
Definition: iterator.hpp:616
CConstBeginInfo ConstBegin(const C &obj)
Get starting point of non-modifiable object hierarchy.
Definition: iterator.hpp:1012
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define kEmptyStr
Definition: ncbistr.hpp:123
size_t size_type
Definition: tempstr.hpp:70
static string & ToUpper(string &str)
Convert string to upper case – string& version.
Definition: ncbistr.cpp:424
static string & ToLower(string &str)
Convert string to lower case – string& version.
Definition: ncbistr.cpp:405
static const size_type npos
Definition: tempstr.hpp:72
TMatch_text & SetMatch_text(void)
Assign a value to Match_text data member.
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1227
else result
Definition: token2.c:20
Modified on Tue Apr 23 07:39:59 2024 by modify_doxy.py rev. 669887