mirror of https://github.com/CGAL/cgal
* new feature: regular expressions (based on posix regex)
* bugfix: based on regex, \labels inside sections/chapters etc
are now correctly handled (ie, html-anchors above <h1> etc)
* improved layout for pkgdesc
This commit is contained in:
parent
64a4aba329
commit
3e9da694df
|
|
@ -1056,6 +1056,8 @@ Manual_tools/src/latex_converter_config/gif/cc_wp.gif -text svneol=unset#unset
|
|||
Manual_tools/src/latex_converter_config/gif/cc_wr.gif -text svneol=unset#unset
|
||||
Manual_tools/src/latex_converter_config/gif/cc_zeta.gif -text svneol=unset#unset
|
||||
Manual_tools/src/mstring.doc -text
|
||||
Manual_tools/src/regex++.C -text
|
||||
Manual_tools/src/regex_dictionary.C -text
|
||||
Manual_tools/sty/eps_tabs/cc_Class.eps -text
|
||||
Manual_tools/sty/eps_tabs/cc_Class.pdf -text svneol=unset#unset
|
||||
Manual_tools/sty/eps_tabs/cc_Concept.eps -text
|
||||
|
|
|
|||
|
|
@ -136,7 +136,9 @@ OBJHTML = lexer.o \
|
|||
cpp_formatting.o \
|
||||
input.o \
|
||||
output.o \
|
||||
cc_extract_html.o
|
||||
cc_extract_html.o \
|
||||
regex++.o \
|
||||
regex_dictionary.o
|
||||
|
||||
OBJIMAGES = cc_extract_images_lexer.C cc_extract_images.o
|
||||
|
||||
|
|
|
|||
|
|
@ -27,6 +27,8 @@
|
|||
#include <sstream>
|
||||
#include <cassert>
|
||||
|
||||
#include <regex_dictionary.h>
|
||||
|
||||
#include <map>
|
||||
|
||||
typedef std::map< string, string, Case_insensitive_string_greater_than > String_map;
|
||||
|
|
@ -1082,9 +1084,9 @@ string // macro
|
|||
handle_chapter( const string&, string param[], size_t n, size_t opt) {
|
||||
NParamCheck( 1, 0);
|
||||
push_current_output();
|
||||
string chapter_title( param[0]);
|
||||
crop_string( chapter_title);
|
||||
remove_separator( chapter_title);
|
||||
//string chapter_title( param[0]);
|
||||
//crop_string( chapter_title);
|
||||
//remove_separator( chapter_title);
|
||||
|
||||
string new_main_filename;
|
||||
string new_main_filepath = macroX( "\\lciInputPath");
|
||||
|
|
@ -1345,6 +1347,32 @@ sorted_map_is_empty( const string&, string param[], size_t n, size_t opt) {
|
|||
}
|
||||
|
||||
|
||||
/* regular expressions */
|
||||
|
||||
|
||||
string
|
||||
handle_regex_register( const string&, string param[], size_t n, size_t opt) {
|
||||
NParamCheck( 2, 0);
|
||||
regex_register( param[0], param[1] );
|
||||
return string();
|
||||
}
|
||||
|
||||
string
|
||||
handle_regex_does_match( const string&, string param[], size_t n, size_t opt) {
|
||||
NParamCheck( 2, 0);
|
||||
if( regex_does_match( param[0], param[1] ) )
|
||||
return string("\\lcTrue");
|
||||
else
|
||||
return string("\\lcFalse");
|
||||
}
|
||||
|
||||
string
|
||||
handle_regex_result( const string&, string param[], size_t n, size_t opt) {
|
||||
NParamCheck( 1, 0);
|
||||
unsigned int index = atoi( param[0].c_str() );
|
||||
return regex_get_submatch(index);
|
||||
}
|
||||
|
||||
// Initialize
|
||||
// ======================================================================
|
||||
void init_internal_macros() {
|
||||
|
|
@ -1422,7 +1450,7 @@ void init_internal_macros() {
|
|||
insertInternalGlobalMacro( "\\lciIfFileExists", if_file_exists, 1);
|
||||
insertInternalGlobalMacro( "\\lciCopyFile", copy_file, 2);
|
||||
|
||||
insertInternalGlobalMacro( "\\lciChapter", handle_chapter, 1);
|
||||
insertInternalGlobalMacro( "\\lciChapter", handle_chapter, 0);
|
||||
|
||||
insertInternalGlobalMacro( "\\lciPopOutput", pop_output, 0);
|
||||
insertInternalGlobalMacro( "\\lciPushOutput", push_output, 1);
|
||||
|
|
@ -1435,6 +1463,10 @@ void init_internal_macros() {
|
|||
insertInternalGlobalMacro( "\\lciIncludeOnly", handle_include_only, 1);
|
||||
insertInternalGlobalMacro( "\\lciIfToBeIncluded", handle_to_be_included, 1);
|
||||
insertInternalGlobalMacro( "\\lciToHtmlWidth", to_html_width, 1);
|
||||
|
||||
insertInternalGlobalMacro( "\\lciRegexRegister", handle_regex_register, 2 );
|
||||
insertInternalGlobalMacro( "\\lcRegexDoesMatch", handle_regex_does_match, 2 );
|
||||
insertInternalGlobalMacro( "\\lcRegexResult", handle_regex_result, 1 );
|
||||
}
|
||||
|
||||
// EOF //
|
||||
|
|
|
|||
|
|
@ -32,7 +32,6 @@
|
|||
\newcommand{\ccAuto}{\lcAuto}
|
||||
|
||||
|
||||
|
||||
% ###########################################################################
|
||||
% |
|
||||
% | o
|
||||
|
|
@ -987,6 +986,12 @@
|
|||
\newcommand{\lciFlushPkgDescription}[2]{%
|
||||
\lciFlushPkgDescriptionX{#X1}{#X2}{\ccValueofPkgName}%
|
||||
}
|
||||
|
||||
\newcommand{\lciCheckForLabelInsideHeadingX}[2]{%
|
||||
\lciCheckForLabelInsideHeading{#XC1}{#2}{\lciLocalVariableLabel}%
|
||||
\lciLocalVariableLabel%
|
||||
}
|
||||
|
||||
\newcommand{\lciFlushPkgDescriptionX}[3]{%
|
||||
\lciIfEmpty{#X3}{}{%
|
||||
\lciIfEmpty{\lciCurrentPartName}{}{%
|
||||
|
|
@ -994,24 +999,20 @@
|
|||
\gdef\lciCurrentPartName{}%
|
||||
}%
|
||||
\lciPushOutput{description}%
|
||||
\lcRawHtml{<h3>}\ccValueofPkgName\lcRawHtml{</h3>}
|
||||
\lcRawHtml{<table><tr valign="top"><td }%
|
||||
%\lciPkgDescriptionIsOddEntry
|
||||
% {\lcRawHtml{ bgcolor="#C0C0C0" }}
|
||||
% {}
|
||||
\lcRawHtml{width="58\%">}
|
||||
\lcRawHtml{<tr><td colspan="3">}%
|
||||
\lciCheckForLabelInsideHeadingX{\ccValueofPkgName}{\lciCurrentPackageName}%
|
||||
\lcRawHtml{<h3>}\lciCurrentPackageName\lcRawHtml{</h3></td></tr>}
|
||||
%\lcRawHtml{<TABLE>}
|
||||
\lcRawHtml{<tr valign="top"><td width="75\%">}
|
||||
\ccValueofPkgSummary
|
||||
%\lcRawHtml{</td><td width="4\%">}
|
||||
\lcRawHtml{</td><td }%
|
||||
%\lciPkgDescriptionIsOddEntry
|
||||
% {}
|
||||
% {\lcRawHtml{ bgcolor="#C0C0C0" }}
|
||||
\lcRawHtml{width="38\%">}
|
||||
\lcRawHtml{</td><td width="2\%">}
|
||||
\lcRawHtml{</td><td width="23\%">}
|
||||
\ccValueofPkgMaturity
|
||||
\ccValueofPkgDependsOn
|
||||
\ccValueofPkgLicense
|
||||
\lcRawHtml{<a href="#C1">User Manual</a> <a href="#C2">Reference Manual</a>}
|
||||
\lcRawHtml{</td></td></table>}
|
||||
\lcRawHtml{</td></td>}
|
||||
%\lcRawHtml{</table>}
|
||||
\lciPopOutput%
|
||||
\gdef\ccValueofPkgName{}%
|
||||
%\lciPkgDescriptionIsOddEntry
|
||||
|
|
@ -1052,6 +1053,7 @@
|
|||
\lciSortedMapClear{TocReferenceLinks}
|
||||
}
|
||||
}
|
||||
|
||||
% ___________________________________________________________________________
|
||||
% ###########################################################################
|
||||
% | EOF
|
||||
|
|
|
|||
|
|
@ -70,8 +70,7 @@ l% ___________________________________________________________________________
|
|||
% |#########################################################################|
|
||||
|
||||
|
||||
% Load latex_to_html.sty that provides the basic converter capabilities.
|
||||
% redefined in latex_to_html.sty
|
||||
|
||||
\newcommand{\lcFalse}[2]{#2}
|
||||
\newcommand{\lcTrue}[2]{#1}
|
||||
|
||||
|
|
@ -95,6 +94,37 @@ l% ___________________________________________________________________________
|
|||
\newcommand{\lcStyleFile}[1]{\lciInputStyleFile{\lciConfigPath}{#XC1}}
|
||||
\newcommand{\lciInputStyleFile}[2]{\lciInclude{#XC1#C2.sty}}
|
||||
}
|
||||
|
||||
% ___________________________________________________________________________
|
||||
% ###########################################################################
|
||||
% | Regular Expressions
|
||||
% ###########################################################################
|
||||
|
||||
|
||||
\newcommand{\lcRegexRegister}[1]{%
|
||||
\def\lciRegexNameToBeRegistered{#1}%
|
||||
\lciParseUntilDelimiter{\lciRegexRegisterX}}
|
||||
|
||||
\newcommand{\lciRegexRegisterX}[1]{\lciRegexRegisterXX{\lciRegexNameToBeRegistered}{#1}}
|
||||
\newcommand{\lciRegexRegisterXX}[2]{\lciRegexRegister{#XC1}{#C2}}
|
||||
|
||||
\lcRegexRegister{checkforlabel}@(.+)(\\label[^\}]+\})(.*)@
|
||||
|
||||
|
||||
\newcommand{\lciCheckForLabelInsideHeading}[3]{%
|
||||
\lcRegexDoesMatch{checkforlabel}{#1}{%
|
||||
% xdef doesnt work, either ..
|
||||
\gdef#2{\lcRegexResult{1}\lcRegexResult{3}}%
|
||||
\gdef#3{\lcRegexResult{2}}
|
||||
}{%
|
||||
\gdef#2{#1}%
|
||||
\gdef#3{}%
|
||||
}%
|
||||
}%
|
||||
|
||||
|
||||
% Load latex_to_html.sty that provides the basic converter capabilities.
|
||||
% redefined in latex_to_html.sty
|
||||
\lcStyleFile{latex_to_html}
|
||||
|
||||
% print own release number
|
||||
|
|
@ -196,6 +226,7 @@ l% ___________________________________________________________________________
|
|||
\lciHtmlFileHeader{Package Description}%
|
||||
\lciHtmlNavigationTop
|
||||
\lcRawHtml{<H1>Package Description</H1>}
|
||||
\lcRawHtml{<table>}
|
||||
\lciPopOutput%
|
||||
}{%
|
||||
% print remaining footnotes at the end of the conversion
|
||||
|
|
@ -211,6 +242,7 @@ l% ___________________________________________________________________________
|
|||
\lciOpenTmpFile{\lciIndexHeader}\lciIndexFileHeader\lciCloseFile
|
||||
\lciOpenTmpFile{\lciIndexFooter}\lciIndexFileFooter\lciCloseFile
|
||||
\lciPushOutput{description}%
|
||||
\lcRawHtml{</table>}
|
||||
\lciHtmlNavigationBottom
|
||||
\lciHtmlFileFooter%
|
||||
\lciPopOutput%
|
||||
|
|
@ -1087,14 +1119,18 @@ l% ___________________________________________________________________________
|
|||
\gdef{\lciIfHtmlLinks}{\lcTrue}%
|
||||
\gdef{\lciIfHtmlIndex}{\lcTrue}%
|
||||
\refstepcounter{chapter}%
|
||||
\lciChapter{#1}% does also a PushOutput
|
||||
|
||||
\lciCheckForLabelInsideHeading{#1}%
|
||||
{\lciLocalVariableChapterNameTOC}%
|
||||
{\lciLocalVariableLabel}%
|
||||
\lciChapter% does also a PushOutput
|
||||
% cross linking rules
|
||||
\lciPushOutput{anchor}%
|
||||
\lcRawHtml{i Next_chapter_link_}\value{part}\_\value{chapter}%
|
||||
\lcRawHtml{ <div class="NavNext"><hr> Next chapter: <a href="}%
|
||||
\lcRawHtmlExpanded{\lciReplaceWithCurrentPathToken}%
|
||||
\lcRawHtmlExpanded{\lciOutputBasename}%
|
||||
\lcRawHtml{">}#1\lcRawHtml{</a>
|
||||
\lcRawHtml{">}\lciLocalVariableChapterNameTOC\lcRawHtml{</a>
|
||||
}%
|
||||
\lcRawHtml{i Up_chapter_link_}\value{part}\_\value{chapter}%
|
||||
\lcRawHtml{ <a href="}%
|
||||
|
|
@ -1111,14 +1147,14 @@ l% ___________________________________________________________________________
|
|||
% however, setting this to a default of TRUE at the beginning of each
|
||||
% chapter seems safe.
|
||||
% file header
|
||||
\lciHtmlFileHeader{#1}%
|
||||
\lciHtmlFileHeader{\lciLocalVariableChapterNameTOC}%
|
||||
\lciHtmlNavigationTop
|
||||
\lciIfLessExpanded{\lciCountersecnumdepth}{0}%
|
||||
{%
|
||||
\lciHtmlChapterToc{\thechapter}{#1}%
|
||||
\lciHtmlChapterToc{\thechapter}{\lciLocalVariableChapterNameTOC}%
|
||||
\lciHtmlChapterHeader{#2}%
|
||||
}{%
|
||||
\lciHtmlChapterToc{\thechapter}{\thechapter~~~#1}%
|
||||
\lciHtmlChapterToc{\thechapter}{\thechapter~~~\lciLocalVariableChapterNameTOC}%
|
||||
\lciHtmlChapterHeader{Chapter \thechapter\\#2}%
|
||||
}%
|
||||
}
|
||||
|
|
@ -1150,6 +1186,7 @@ l% ___________________________________________________________________________
|
|||
\newcommand{\section@om}{%
|
||||
\lciEndSection
|
||||
\refstepcounter{section}%
|
||||
\lciLocalVariableLabel
|
||||
\lciIfLessExpanded{\lciCountersecnumdepth}{1}{%
|
||||
\lciHtmlSectionToc{\thesection}{#1}%
|
||||
\lciHtmlSectionHeader{#2}}%
|
||||
|
|
|
|||
|
|
@ -432,19 +432,26 @@
|
|||
\newcommand{\lciHtmlPartPkgDesciption}[1]{
|
||||
\lciPushOutput{description}
|
||||
\lcRawHtml{
|
||||
<table width="100\%" border="0" cellspacing="0" cellpadding="0"><tr><td>
|
||||
<tr><td colspan="3">
|
||||
<h2 class="PkgDescPart"><br>}#XC1\lcRawHtml{</h1>
|
||||
</td></tr></table>}
|
||||
</td></tr>}
|
||||
\lciPopOutput
|
||||
}
|
||||
|
||||
% Args: <header-text>
|
||||
\newcommand{\lciHtmlChapterHeader}[1]{\lcRawHtml{
|
||||
<h1>}#C1\lcRawHtml{</h1>
|
||||
\newcommand{\lciHtmlChapterHeader}[1]{
|
||||
\lciCheckForLabelInsideHeading{#C1}%
|
||||
{\lciLocalVariableChapterName}%
|
||||
{\lciLocalVariableLabel}%
|
||||
\lciLocalVariableLabel
|
||||
\lcRawHtml{<h1>}\lciLocalVariableChapterName\lcRawHtml{</h1>
|
||||
}}
|
||||
|
||||
% Args: <anchor-counter> <toc-entry>: Respect secnumdepth counter.
|
||||
\newcommand{\lciHtmlChapterToc}[2]{%
|
||||
%\lciCheckForLabelInsideHeading{#2}%
|
||||
% {\lciLocalVariableChapterName}%
|
||||
% {\lciLocalVariableLabel}%
|
||||
\lciIfEmpty{#C1}{}{\lciIfLessExpanded{\lciCountertocdepth}{0}{}{%
|
||||
\lcRawHtml{<a name="Chapter_}#C1\lcRawHtml{"></a>}}}
|
||||
\lciIfLessExpanded{\lciCountertocdepth}{0}{}{%
|
||||
|
|
@ -454,7 +461,7 @@
|
|||
% \lcRawHtml{##Chapter_}#C1 % omit anchor, we start at the page top
|
||||
\lcRawHtml{ <tr><td class="TocChapter" colspan="6">
|
||||
<!-- --------------------------------------------------- -->
|
||||
<a class="TocLinkChapter" href="}\lcRawHtmlExpanded{\lciOut}%
|
||||
<a class="TocLinkChapter" href="}\lcRawHtmlExpanded{\lciOut}% \lciLocalVariableChapterName
|
||||
\lcRawHtml{"
|
||||
>}#C2\lcRawHtml{</a>
|
||||
</td></tr>
|
||||
|
|
@ -464,12 +471,20 @@
|
|||
|
||||
|
||||
% Args: <header-text>:
|
||||
\newcommand{\lciHtmlSectionHeader}[1]{\lcRawHtml{
|
||||
<h2>}#C1\lcRawHtml{</h2>
|
||||
}}
|
||||
\newcommand{\lciHtmlSectionHeader}[1]{%
|
||||
\lciCheckForLabelInsideHeading{#C1}%
|
||||
{\lciLocalVariableSectionName}%
|
||||
{\lciLocalVariableLabel}%
|
||||
\lciLocalVariableLabel
|
||||
\lcRawHtml{<h2>}\lciLocalVariableSectionName\lcRawHtml{</h2>
|
||||
}
|
||||
}
|
||||
|
||||
% Args: <anchor-counter> <toc-entry>: Respect secnumdepth counter.
|
||||
\newcommand{\lciHtmlSectionToc}[2]{%
|
||||
\lciCheckForLabelInsideHeading{#C2}%
|
||||
{\lciLocalVariableSectionName}%
|
||||
{\lciLocalVariableLabel}%
|
||||
\lciIfLessExpanded{\lciCountertocdepth}{1}{}{%
|
||||
\lcRawHtml{<a name="Section_}#C1\lcRawHtml{"></a>}
|
||||
\edef\lciOut{\lciOutputFilename}%
|
||||
|
|
@ -480,16 +495,16 @@
|
|||
\lcRawHtml{ <td class="TocSection" colspan="5">
|
||||
<a class="TocLinkSection" href="}\lcRawHtmlExpanded{\lciOut}%
|
||||
\lcRawHtml{##Section_}#C1\lcRawHtml{"
|
||||
>}#C2\lcRawHtml{</a>
|
||||
>}\lciLocalVariableSectionName\lcRawHtml{</a>
|
||||
</td>
|
||||
</tr>
|
||||
}%
|
||||
\lciPopOutput}}
|
||||
|
||||
% Args: <header-text>:
|
||||
\newcommand{\lciHtmlReferenceHeader}[1]{\lcRawHtml{
|
||||
<h2>}#C1\lcRawHtml{</h2>
|
||||
}}
|
||||
\newcommand{\lciHtmlReferenceHeader}[1]{
|
||||
\lcRawHtml{<h2>}#C1\lcRawHtml{</h2>}
|
||||
}
|
||||
|
||||
% Args: <anchor-counter> <toc-entry>: Respect secnumdepth counter.
|
||||
\newcommand{\lciHtmlReferenceToc}[2]{%
|
||||
|
|
@ -514,13 +529,20 @@
|
|||
% Args: <anchor-counter> <header-text>: if anchor counter is empty, no
|
||||
% anchor is defined. Respect secnumdepth counter.
|
||||
\newcommand{\lciHtmlSubsectionHeader}[2]{%
|
||||
\lciCheckForLabelInsideHeading{#C2}%
|
||||
{\lciLocalVariableSubSectionName}%
|
||||
{\lciLocalVariableLabel}%
|
||||
\lciLocalVariableLabel
|
||||
\lciIfEmpty{#C1}{}{\lciIfLessExpanded{\lciCountertocdepth}{2}{}{%
|
||||
\lcRawHtml{<a name="Subsection_}#C1\lcRawHtml{"></a>}}}\lcRawHtml{
|
||||
<h3>}#C2\lcRawHtml{</h3>
|
||||
<h3>}\lciLocalVariableSubSectionName\lcRawHtml{</h3>
|
||||
}}
|
||||
|
||||
% Args: <anchor-counter> <toc-entry>
|
||||
\newcommand{\lciHtmlSubsectionToc}[2]{%
|
||||
\lciCheckForLabelInsideHeading{#C2}%
|
||||
{\lciLocalVariableSubSectionName}%
|
||||
{\lciLocalVariableLabel}%
|
||||
\lciIfLessExpanded{\lciCountertocdepth}{2}{}{%
|
||||
\edef\lciOut{\lciOutputFilename}%
|
||||
\lciPushOutput{toc}%
|
||||
|
|
@ -529,8 +551,7 @@
|
|||
}\lciTocIndentWidth\lciTocIndentWidth
|
||||
\lcRawHtml{ <td class="TocSubsection" colspan="4">
|
||||
<a class="TocLinkSubsection" href="}\lcRawHtmlExpanded{\lciOut}%
|
||||
\lcRawHtml{##Subsection_}#C1\lcRawHtml{"
|
||||
>}#C2\lcRawHtml{</a>
|
||||
\lcRawHtml{##Subsection_}#C1\lcRawHtml{">}\lciLocalVariableSubSectionName\lcRawHtml{</a>
|
||||
</td>
|
||||
</tr>
|
||||
}%
|
||||
|
|
|
|||
|
|
@ -0,0 +1,72 @@
|
|||
#include <iostream>
|
||||
#include <mstring.h>
|
||||
#include <cassert>
|
||||
#include "regex++.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
const unsigned int maxgroups = 20;
|
||||
|
||||
vector<string>
|
||||
Regular_expression::submatch(maxgroups);
|
||||
|
||||
|
||||
Regular_expression::Regular_expression( const char* rx )
|
||||
{ init( rx ); }
|
||||
|
||||
Regular_expression::Regular_expression( const string& rx )
|
||||
{ init( rx.c_str() ); }
|
||||
|
||||
void
|
||||
Regular_expression::init( const char* rx ) {
|
||||
assert( rx != NULL );
|
||||
if( regcomp( ®ex, rx, REG_EXTENDED ) != REG_NOERROR ) {
|
||||
std::cout << "!! Error: regex compilation error" << std::endl;
|
||||
exit(1);
|
||||
}
|
||||
regmatch = ( regmatch_t* ) malloc ( maxgroups * sizeof ( regmatch_t ) );
|
||||
assert( regmatch != NULL );
|
||||
}
|
||||
|
||||
Regular_expression::~Regular_expression() {
|
||||
if( regmatch != NULL ) {
|
||||
regfree ( ®ex );
|
||||
free ( regmatch );
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
Regular_expression::match( const string& s ) {
|
||||
assert( regmatch != NULL );
|
||||
if( regexec( ®ex, s.c_str(), maxgroups, regmatch, 0 ) == REG_NOERROR ) {
|
||||
int so, eo;
|
||||
for ( unsigned int i = 0; i < maxgroups; i++ ) {
|
||||
so = regmatch[ i ].rm_so;
|
||||
eo = regmatch[ i ].rm_eo;
|
||||
if ( so != -1 )
|
||||
submatch[ i ] = s.substr ( so, eo - so );
|
||||
else
|
||||
submatch[ i ] = "";
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool
|
||||
Regular_expression::match( const char *s )
|
||||
{ return Regular_expression::match( string( s ) ); }
|
||||
|
||||
const string&
|
||||
Regular_expression::get_match( unsigned int num ) {
|
||||
static string emptystring;
|
||||
if( num >= maxgroups ) {
|
||||
std::cerr << "!! warning: accessing bad regex submatch #" << num << std::endl;
|
||||
return emptystring;
|
||||
}
|
||||
|
||||
return submatch[num];
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
#ifndef REGEXPP_H
|
||||
#define REGEXPP_H
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <regex.h>
|
||||
#include <mstring.h>
|
||||
#include <vector>
|
||||
|
||||
struct Regular_expression {
|
||||
struct Exception {};
|
||||
Regular_expression() : regmatch(NULL) {}
|
||||
Regular_expression( const string& rx );
|
||||
Regular_expression( const char* rx );
|
||||
~Regular_expression();
|
||||
|
||||
void init( const char *rx );
|
||||
|
||||
bool match( const string& s );
|
||||
bool match( const char* s );
|
||||
|
||||
static const string& get_match( unsigned int num );
|
||||
protected:
|
||||
|
||||
static vector <string> submatch;
|
||||
regex_t regex;
|
||||
regmatch_t *regmatch;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
#include <regex_dictionary.h>
|
||||
#include <regex++.h>
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
typedef hash_map< string, Regular_expression > Regex_map;
|
||||
|
||||
static Regex_map regex_map;
|
||||
|
||||
void
|
||||
regex_register( const string& name, const string ®ex ) {
|
||||
regex_map[name].init( regex.c_str() );
|
||||
//std::cerr << "!! Warning: registered name=[" << name << "] regex=[" << regex << "]" << std::endl;
|
||||
}
|
||||
|
||||
bool
|
||||
regex_does_match( const string& name, const string& text ) {
|
||||
bool result = regex_map[name].match( text );
|
||||
std::cerr << "!! checking " << name << " against " << text << " yields: " << result << std::endl;
|
||||
std::cerr << "match1 : " << regex_get_submatch(1) << std::endl;
|
||||
std::cerr << "match2 : " << regex_get_submatch(2) << std::endl;
|
||||
std::cerr << "match3 : " << regex_get_submatch(3) << std::endl;
|
||||
return result;
|
||||
}
|
||||
|
||||
const string&
|
||||
regex_get_submatch( unsigned int num ) {
|
||||
return Regular_expression::get_match( num );
|
||||
}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
#ifndef REGEX_DICTIONARY_H
|
||||
#define REGEX_DICTIONARY_H
|
||||
|
||||
#include <mstring.h>
|
||||
|
||||
void regex_register( const string& name, const string ®ex );
|
||||
bool regex_does_match( const string& name, const string& text );
|
||||
const string& regex_get_submatch( unsigned int num );
|
||||
|
||||
#endif
|
||||
Loading…
Reference in New Issue