Dynamixel  2.9.5
RoadNarrows Robotics Dynamixel Package
dynashell_regex.cxx
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // Package: Dynamixel
4 //
5 // Program: dynashell
6 //
7 // File: dynashell_regex.cxx
8 //
9 /*! \file
10  *
11  * $LastChangedDate: 2015-01-12 10:56:06 -0700 (Mon, 12 Jan 2015) $
12  * $Rev: 3845 $
13  *
14  * \brief The Dynamixel Shell Regular Expression Class.
15  *
16  * \author Robin Knight (robin.knight@roadnarrows.com)
17  *
18  * \copyright
19  * \h_copy 2012-2017. RoadNarrows LLC.\n
20  * http://www.roadnarrows.com\n
21  * All Rights Reserved
22  */
23 /*
24  * @EulaBegin@
25  *
26  * Unless otherwise stated explicitly, all materials contained are copyrighted
27  * and may not be used without RoadNarrows LLC's written consent,
28  * except as provided in these terms and conditions or in the copyright
29  * notice (documents and software) or other proprietary notice provided with
30  * the relevant materials.
31  *
32  * IN NO EVENT SHALL THE AUTHOR, ROADNARROWS LLC, OR ANY
33  * MEMBERS/EMPLOYEES/CONTRACTORS OF ROADNARROWS OR DISTRIBUTORS OF THIS SOFTWARE
34  * BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR
35  * CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS
36  * DOCUMENTATION, EVEN IF THE AUTHORS OR ANY OF THE ABOVE PARTIES HAVE BEEN
37  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38  *
39  * THE AUTHORS AND ROADNARROWS LLC SPECIFICALLY DISCLAIM ANY WARRANTIES,
40  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
41  * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN
42  * "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO
43  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
44  *
45  * @EulaEnd@
46  */
47 ////////////////////////////////////////////////////////////////////////////////
48 
49 
50 #include <sys/types.h>
51 #include <stdio.h>
52 #include <string.h>
53 #include <unistd.h>
54 #include <regex.h>
55 #include <string>
56 
57 #include <rnr/rnrconfig.h>
58 #include <rnr/log.h>
59 
60 #include "dynashell_regex.h"
61 
62 
63 using namespace std;
64 
65 
66 // ----------------------------------------------------------------------------
67 // Class RegEx
68 // ----------------------------------------------------------------------------
69 
70 /*!
71  * \brief Compile a regular expression.
72  */
74 {
75  int errcode;
76 
77  memset(&m_regex, 0, sizeof(m_regex));
78 
79  if( m_strRegEx.length() == 0 )
80  {
81  m_bIsValid = false;
82  }
83  else if( (errcode = regcomp(&m_regex, m_strRegEx.c_str(), REG_NOSUB)) == 0 )
84  {
85  m_bIsValid = true;
86  }
87  else
88  {
89  char buf[80];
90  regerror(errcode, &m_regex, buf, sizeof(buf));
91  LOGERROR("%s.", buf);
92  m_bIsValid = false;
93  }
94 }
The Dynamixel Shell Regular Expression Class.
void Compile()
Compile a regular expression.