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

Go to the SVN repository for this file.

1 #ifndef _PARSE_TEXT_OPTIONS_HPP_
2 #define _PARSE_TEXT_OPTIONS_HPP_
3 /* $Id: parse_text_options.hpp 93572 2021-04-30 13:48:31Z stakhovv $
4 * ===========================================================================
5 *
6 * PUBLIC DOMAIN NOTICE
7 * National Center for Biotechnology Information
8 *
9 * This software/database is a "United States Government Work" under the
10 * terms of the United States Copyright Act. It was written as part of
11 * the author's official duties as a United States Government employee and
12 * thus cannot be copyrighted. This software/database is freely available
13 * to the public for use. The National Library of Medicine and the U.S.
14 * Government have not placed any restriction on its use or reproduction.
15 *
16 * Although all reasonable efforts have been taken to ensure the accuracy
17 * and reliability of the software and data, the NLM and the U.S.
18 * Government do not and cannot warrant the performance or results that
19 * may be obtained by using this software or data. The NLM and the U.S.
20 * Government disclaim all warranties, express or implied, including
21 * warranties of performance, merchantability or fitness for any particular
22 * purpose.
23 *
24 * Please cite the author in any work or product based on this material.
25 *
26 * ===========================================================================
27 *
28 * Authors: Colleen Bollin, Andrea Asztalos
29 *
30 * File Description:
31 * Classes that implement string parsing.
32 */
33 
34 #include <corelib/ncbistd.hpp>
35 #include <corelib/ncbiobj.hpp>
36 
37 
41 
42 NCBI_XOBJEDIT_EXPORT SIZE_TYPE FindWithOptions(const string& str, const string& pattern,
43  SIZE_TYPE start_search, bool case_insensitive, bool whole_word);
44 
46 {
47 public:
48  enum EMarkerType {
49  eMarkerType_None = 0,
52  eMarkerType_Letters
53  };
54 
56  : m_MarkerType(eMarkerType_None),
57  m_Text(kEmptyStr) {}
59 
60  void SetText(const string& val);
61  void SetDigits() { m_MarkerType = eMarkerType_Digits; }
62  void SetLetters() { m_MarkerType = eMarkerType_Letters; }
63  bool FindInText(const string& val, size_t& pos, size_t& len, size_t start_search, bool case_insensitive, bool whole_word) const;
64  void Reset();
65 
66  static void s_GetDigitsPosition(const string& str, size_t& pos, size_t& len, size_t start_search);
67  static void s_GetLettersPosition(const string& str, size_t& pos, size_t& len, size_t start_search);
68 
69 private:
71  string m_Text;
72 };
73 
74 
76 {
77 public:
79  : m_IncludeStartMarker(false),
80  m_IncludeStopMarker(false),
81  m_RemoveFromParsed(false),
82  m_RemoveBeforePattern(false),
83  m_RemoveAfterPattern(false),
84  m_CaseInsensitive(false),
85  m_WholeWord(false) {}
87 
88  void SetStartText(const string& val) { m_StartMarker.SetText(val); }
89  void SetStopText(const string& val) { m_StopMarker.SetText(val); }
90  void SetStartDigits() { m_StartMarker.SetDigits(); }
91  void SetStopDigits() { m_StopMarker.SetDigits(); }
92  void SetStartLetters() { m_StartMarker.SetLetters(); }
93  void SetStopLetters() { m_StopMarker.SetLetters(); }
94 
95  void SetIncludeStart(bool val) { m_IncludeStartMarker = val; }
96  void SetIncludeStop(bool val) { m_IncludeStopMarker = val; }
97  /// if true, removes the parsed text from the parsed text
98  void SetShouldRemove(bool val) { m_RemoveFromParsed = val; }
99  /// if true, removes the lhs delimiter from the parsed text
100  void SetShouldRmvBeforePattern(bool val) { m_RemoveBeforePattern = val; }
101  /// if true, removes the rhs delimiter from the parsed text
102  void SetShouldRmvAfterPattern(bool val) { m_RemoveAfterPattern = val; }
103 
104  void SetCaseInsensitive(bool val) { m_CaseInsensitive = val; }
105  void SetWholeWord(bool val) { m_WholeWord = val; }
106  void Reset();
107 
108  string GetSelectedText(const string& input) const;
109  void RemoveSelectedText(string& input, bool remove_first_only = true) const;
110  bool ShouldRemoveFromParsed() const { return m_RemoveFromParsed; }
111 
112 private:
122 };
123 
127 
128 #endif // _PARSE_TEXT_OPTIONS_HPP_
CObject –.
Definition: ncbiobj.hpp:180
void SetShouldRmvAfterPattern(bool val)
if true, removes the rhs delimiter from the parsed text
CParseTextMarker m_StartMarker
void SetIncludeStop(bool val)
void SetShouldRmvBeforePattern(bool val)
if true, removes the lhs delimiter from the parsed text
CParseTextMarker m_StopMarker
void SetIncludeStart(bool val)
void SetStopText(const string &val)
void SetCaseInsensitive(bool val)
bool ShouldRemoveFromParsed() const
void SetWholeWord(bool val)
void SetStartText(const string &val)
void SetShouldRemove(bool val)
if true, removes the parsed text from the parsed text
Include a standard set of the NCBI C++ Toolkit most basic headers.
#define false
Definition: bool.h:36
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 END_SCOPE(ns)
End the previously defined scope.
Definition: ncbistl.hpp:75
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define BEGIN_SCOPE(ns)
Define a new scope.
Definition: ncbistl.hpp:72
NCBI_NS_STD::string::size_type SIZE_TYPE
Definition: ncbistr.hpp:132
#define kEmptyStr
Definition: ncbistr.hpp:123
#define NCBI_XOBJEDIT_EXPORT
Definition: ncbi_export.h:1291
static int input()
int len
Definition: fix_pub.hpp:45
Portable reference counted smart and weak pointers using CWeakRef, CRef, CObject and CObjectEx.
SIZE_TYPE FindWithOptions(const string &str, const string &pattern, SIZE_TYPE start_search, bool case_insensitive, bool whole_word)
Modified on Fri Sep 20 14:57:06 2024 by modify_doxy.py rev. 669887