00001 /****************************************************************************** 00002 * Copyright (C) 2014 by Ralf Kaestner * 00003 * ralf.kaestner@gmail.com * 00004 * * 00005 * This program is free software; you can redistribute it and/or modify * 00006 * it under the terms of the Lesser GNU General Public License as published by* 00007 * the Free Software Foundation; either version 3 of the License, or * 00008 * (at your option) any later version. * 00009 * * 00010 * This program is distributed in the hope that it will be useful, * 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00013 * Lesser GNU General Public License for more details. * 00014 * * 00015 * You should have received a copy of the Lesser GNU General Public License * 00016 * along with this program. If not, see <http://www.gnu.org/licenses/>. * 00017 ******************************************************************************/ 00018 00019 #include "variant_topic_tools/MessageTypeParser.h" 00020 00021 namespace variant_topic_tools { 00022 00023 /*****************************************************************************/ 00024 /* Static initializers */ 00025 /*****************************************************************************/ 00026 00027 const boost::regex MessageTypeParser::packageExpression = 00028 boost::regex("[a-zA-Z][a-zA-Z1-9_]*"); 00029 00030 const boost::regex MessageTypeParser::typeExpression = 00031 boost::regex("[a-zA-Z][a-zA-Z1-9_]*"); 00032 00033 const boost::regex MessageTypeParser::plainTypeExpression = 00034 boost::regex("("+typeExpression.str()+")"); 00035 00036 const boost::regex MessageTypeParser::packageTypeExpression = 00037 boost::regex("("+packageExpression.str()+")/("+typeExpression.str()+")"); 00038 00039 /*****************************************************************************/ 00040 /* Constructors and Destructor */ 00041 /*****************************************************************************/ 00042 00043 MessageTypeParser::MessageTypeParser() { 00044 } 00045 00046 MessageTypeParser::~MessageTypeParser() { 00047 } 00048 00049 /*****************************************************************************/ 00050 /* Methods */ 00051 /*****************************************************************************/ 00052 00053 bool MessageTypeParser::matchType(const std::string& expression, std::string& 00054 package, std::string& type) { 00055 boost::smatch match; 00056 00057 if (boost::regex_match(expression, match, packageTypeExpression)) { 00058 package = std::string(match[1].first, match[1].second); 00059 type = std::string(match[2].first, match[2].second); 00060 00061 return true; 00062 } 00063 else if (boost::regex_match(expression, match, plainTypeExpression)) { 00064 package = std::string(); 00065 type = std::string(match[1].first, match[1].second); 00066 00067 return true; 00068 } 00069 else 00070 return false; 00071 } 00072 00073 }