NCBI C++ ToolKit
regexp_loc.cpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: regexp_loc.cpp 67434 2015-05-18 14:37:25Z kornbluh $
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 * Author: Clifford Clausen
27 *
28 * File Description: Functions for creating CSeq_locs from CRegexps
29 *
30 * ===========================================================================*/
31 
32 #include <ncbi_pch.hpp>
34 
37 
39  : m_regexp(new CRegexp(pat, flags))
40 {
41 }
42 
44 {
45 }
46 
47 void CRegexp_loc::Set(const string &pat, CRegexp::TCompile flags)
48 {
49  m_regexp->Set(pat, flags);
50 }
51 
53 (const char *seq,
54  CSeq_loc *loc,
57 {
58  // Reset loc to type CPacked_seqint
59  CSeq_loc::TPacked_int &packed = loc->SetPacked_int();
60 
61  // Get list of CSeq_interval
62  CPacked_seqint::Tdata &lst = packed.Set();
63  lst.clear();
64 
65  // Match the regular expression to the sequence
66  m_regexp->GetMatch(seq, offset, 0, flags, true);
67 
68  // Create a CSeq_interval for whole pattern match
69  // and each sub-pattern match and push into list
70  for (int i = 0; i < m_regexp->NumFound(); i++) {
72  si->SetFrom(m_regexp->GetResults(i)[0]);
73  si->SetTo(m_regexp->GetResults(i)[1] - 1);
74  lst.push_back(si);
75  }
76  if (m_regexp->NumFound() > 0) {
77  return m_regexp->GetResults(0)[0];
78  } else {
79  return kInvalidSeqPos;
80  }
81 }
82 
void Set(const string &pat, CRegexp::TCompile flags=0)
Sets PCRE pattern.
Definition: regexp_loc.cpp:47
CRegexp_loc(const string &pat, CRegexp::TCompile flags=0)
Constructor for CRegexp_loc.
Definition: regexp_loc.cpp:38
unique_ptr< CRegexp > m_regexp
PCRE used to match against char* sequence passed as argument to GetLoc.
Definition: regexp_loc.hpp:93
TSeqPos GetLoc(const char *seq, CSeq_loc *loc, TSeqPos offset=0, CRegexp::TMatch flags=0)
Gets a CSeq_loc for PCRE match to char* sequence.
Definition: regexp_loc.cpp:53
virtual ~CRegexp_loc()
Definition: regexp_loc.cpp:43
CRegexp –.
Definition: regexp.hpp:74
static uch flags
static const char si[8][64]
Definition: des.c:146
int offset
Definition: replacements.h:160
unsigned int TSeqPos
Type for sequence locations and lengths.
Definition: ncbimisc.hpp:875
const TSeqPos kInvalidSeqPos
Define special value for invalid sequence position.
Definition: ncbimisc.hpp:878
void SetPacked_int(TPacked_int &v)
Definition: Seq_loc.hpp:984
unsigned int TMatch
Match options.
Definition: regexp.hpp:85
unsigned int TCompile
Type definitions used for code clarity.
Definition: regexp.hpp: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
list< CRef< CSeq_interval > > Tdata
Tdata & Set(void)
Assign a value to data member.
int i
USING_SCOPE(objects)
header file for creating CSeq_locs from CRegexps.
Modified on Fri Sep 20 14:57:34 2024 by modify_doxy.py rev. 669887