1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
/*
* pin.c: A plugin for the Video Disk Recorder
*
* See the README file for copyright information and how to reach the author.
*
* Date: 29.01.2006, horchi
*/
#include <stdio.h>
#include <sys/types.h>
#include <regex.h>
#include "rep.h"
#include "def.h"
//**************************************************************************
// Regular Expression Searching
//**************************************************************************
int rep(const char* string, const char* expression, Option options)
{
const char* tmpA;
const char* tmpB;
return rep( string, expression, tmpA, tmpB, options);
}
int rep(const char* string, const char* expression, const char*& s_location,
Option options)
{
const char* tmpA;
return rep( string, expression, s_location, tmpA, options);
}
int rep(const char* string, const char* expression, const char*& s_location,
const char*& e_location, Option options)
{
regex_t reg;
regmatch_t rm;
int status;
int opt = 0;
// Vorbereiten von reg fuer die Expressionsuche mit regexec
// Flags: REG_EXTENDED = Use Extended Regular Expressions
// REG_ICASE = Ignore case in match.
reg.re_nsub = 0;
// Options umwandeln
if (options & repUseRegularExpression)
opt = opt | REG_EXTENDED;
if (options & repIgnoreCase)
opt = opt | REG_ICASE;
if (regcomp( ®, expression, opt) != 0)
return fail;
// Suchen des ersten Vorkommens von reg in string
status = regexec( ®, string, 1, &rm, 0);
regfree(®);
if (status != 0)
return fail;
// Suche erfolgreich =>
// Setzen der ermittelten Start- und Endpositionen
s_location = (char*)(string + rm.rm_so);
e_location = (char*)(string + rm.rm_eo);
return success;
}
|