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

Go to the SVN repository for this file.

1 #ifndef GUI_OBJUTILS___STRING_MATCHING__HPP
2 #define GUI_OBJUTILS___STRING_MATCHING__HPP
3 
4 /* $Id: string_matching.hpp 45982 2021-01-20 17:01:19Z grichenk $
5  * ===========================================================================
6  *
7  * PUBLIC DOMAIN NOTICE
8  * National Center for Biotechnology Information
9  *
10  * This software/database is a "United States Government Work" under the
11  * terms of the United States Copyright Act. It was written as part of
12  * the author's official duties as a United States Government employee and
13  * thus cannot be copyrighted. This software/database is freely available
14  * to the public for use. The National Library of Medicine and the U.S.
15  * Government have not placed any restriction on its use or reproduction.
16  *
17  * Although all reasonable efforts have been taken to ensure the accuracy
18  * and reliability of the software and data, the NLM and the U.S.
19  * Government do not and cannot warrant the performance or results that
20  * may be obtained by using this software or data. The NLM and the U.S.
21  * Government disclaim all warranties, express or implied, including
22  * warranties of performance, merchantability or fitness for any particular
23  * purpose.
24  *
25  * Please cite the author in any work or product based on this material.
26  *
27  * ===========================================================================
28  *
29  * Author: Vladislav Evgeniev
30  *
31  * File Description:
32  * Provides a class that supports several text matching algorithms - plain text search,
33  * wildcard matching, regexp and Metaphone search.
34  *
35  */
36 
37 #include <memory>
38 #include <vector>
39 #include <string>
40 #include <corelib/ncbistr.hpp>
41 #include <util/xregexp/regexp.hpp>
42 #include <gui/gui_export.h>
43 
45 
46 class CQueryExec;
47 
48 ////////////////////////////////////////////////////////////////////////////////
49 /// class CTextSearch
50 ///
51 /// Matches string by using different algorithms - plain text search,
52 /// wildcard matching, regexp and Metaphone search.
53 ///
55 {
56 public:
57  /// String matching algorithms
59  ePlainSearch, ///< Plain search
60  eWildcardMatch, ///< Wildcard pattern matching
61  eRegex, ///< Regular expression matching
62  eMetaphone ///< Metaphone mathcing
63  };
64 
65 public:
66  /// Constructs text search object with specific pattern and algorithm
67  /// @param[in] pattern
68  /// Reference to a pattern to search for.
69  /// @param[in] string_matching
70  /// String matching algorithm to use, default is plain text search.
71  /// @param[in] use_case
72  /// Whether to do a case sensitive comparison (default), or not.
73  CStringMatching(const CTempString &pattern, EStringMatching string_matching = ePlainSearch, NStr::ECase use_case = NStr::eCase);
74 
75  /// Matches a string to a pattern, using the specified string matching algorithm
76  /// @param[in] str
77  /// Reference to the string to be searched.
78  /// @return
79  /// Return true if "str" matches the pattern, and false otherwise.
80  bool MatchString(const CTempString &str);
81 
82 protected:
83  typedef vector<string> TStringVector;
84 
85 protected:
86  /// Default constructor - declared, but not defined
88 
89  /// Copy constructor - declared but not defined
91 
92  /// Assignment operator - declared but not defined
94 
95 private:
96  /// The pattern to search for.
98  /// String matching algorithm to use.
100  /// Whether to do a case sensitive comparison or not.
102  /// Metaphone pattern(s)
103  unique_ptr<TStringVector> m_MetaphonePattern;
104  /// Regular expression
105  unique_ptr<CRegexp> m_Regex;
106 };
107 
109 
110 #endif // GUI_OBJUTILS___STRING_MATCHING__HPP
Query execution environment holds the function registry and the execution context.
Definition: query_exec.hpp:144
class CTextSearch
CStringMatching()
Default constructor - declared, but not defined.
unique_ptr< TStringVector > m_MetaphonePattern
Metaphone pattern(s)
unique_ptr< CRegexp > m_Regex
Regular expression.
NStr::ECase m_UseCase
Whether to do a case sensitive comparison or not.
EStringMatching m_MatchingAlgorithm
String matching algorithm to use.
CTempString m_Pattern
The pattern to search for.
EStringMatching
String matching algorithms.
@ eWildcardMatch
Wildcard pattern matching.
@ eRegex
Regular expression matching.
@ ePlainSearch
Plain search.
vector< string > TStringVector
CStringMatching & operator=(const CStringMatching &src)
Assignment operator - declared but not defined.
CStringMatching(const CStringMatching &src)
Copy constructor - declared but not defined.
CTempString implements a light-weight string on top of a storage buffer whose lifetime management is ...
Definition: tempstr.hpp:65
The NCBI C++ standard methods for dealing with std::string.
static const char * str(char *buf, int n)
Definition: stats.c:84
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
ECase
Which type of string comparison.
Definition: ncbistr.hpp:1204
@ eCase
Case sensitive compare.
Definition: ncbistr.hpp:1205
#define NCBI_GUIOBJUTILS_EXPORT
Definition: gui_export.h:512
Defines to provide correct exporting from DLLs in Windows.
C++ wrappers for the Perl-compatible regular expression (PCRE) library.
Modified on Fri Sep 20 14:58:14 2024 by modify_doxy.py rev. 669887