Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
jami-daemon
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
savoirfairelinux
jami-daemon
Commits
d2f15f8d
Commit
d2f15f8d
authored
13 years ago
by
Tristan Matthews
Browse files
Options
Downloads
Patches
Plain Diff
* #7131: remove prefix from pattern
parent
2f15047c
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
daemon/src/sip/pattern.cpp
+62
-95
62 additions, 95 deletions
daemon/src/sip/pattern.cpp
daemon/src/sip/pattern.h
+31
-49
31 additions, 49 deletions
daemon/src/sip/pattern.h
with
93 additions
and
144 deletions
daemon/src/sip/pattern.cpp
+
62
−
95
View file @
d2f15f8d
...
...
@@ -34,36 +34,35 @@
namespace
sfl
{
Pattern
::
Pattern
(
const
std
::
string
&
pattern
,
const
std
::
string
&
options
)
:
_
pattern
(
pattern
),
_
re
(
NULL
),
_
ovector
(
NULL
),
_
ovectorSize
(
0
),
_
count
(
0
),
_
options
(
0
)
pattern
_
(
pattern
),
re
_
(
NULL
),
ovector
_
(
NULL
),
ovectorSize
_
(
0
),
count
_
(
0
),
options
_
(
0
)
{
// Set offsets
_
offset
[
0
]
=
_
offset
[
1
]
=
0
;
offset
_
[
0
]
=
offset
_
[
1
]
=
0
;
// Set options.
_
optionsDescription
=
options
;
optionsDescription
_
=
options
;
for
(
unsigned
int
i
=
0
;
i
<
options
.
length
();
i
++
)
{
switch
(
options
.
at
(
i
))
{
case
'i'
:
_
options
|=
PCRE_CASELESS
;
options
_
|=
PCRE_CASELESS
;
break
;
case
'm'
:
_
options
|=
PCRE_MULTILINE
;
options
_
|=
PCRE_MULTILINE
;
break
;
case
's'
:
_
options
|=
PCRE_DOTALL
;
options
_
|=
PCRE_DOTALL
;
break
;
case
'x'
:
_
options
|=
PCRE_EXTENDED
;
options
_
|=
PCRE_EXTENDED
;
break
;
}
}
...
...
@@ -74,22 +73,21 @@ Pattern::Pattern(const std::string& pattern, const std::string& options) :
Pattern
::~
Pattern
()
{
if
(
_re
!=
NULL
)
{
pcre_free
(
_re
);
}
if
(
re_
!=
NULL
)
pcre_free
(
re_
);
delete
[]
_
ovector
;
delete
[]
ovector
_
;
}
void
Pattern
::
compile
(
void
)
void
Pattern
::
compile
()
{
// Compile the pattern
int
offset
;
const
char
*
error
;
_
re
=
pcre_compile
(
_
pattern
.
c_str
(),
0
,
&
error
,
&
offset
,
NULL
);
re
_
=
pcre_compile
(
pattern
_
.
c_str
(),
0
,
&
error
,
&
offset
,
NULL
);
if
(
_
re
==
NULL
)
{
if
(
re
_
==
NULL
)
{
std
::
string
offsetStr
;
std
::
stringstream
ss
;
ss
<<
offset
;
...
...
@@ -104,29 +102,29 @@ void Pattern::compile(void)
// of memory for the output vector.
int
captureCount
;
pcre_fullinfo
(
_
re
,
NULL
,
PCRE_INFO_CAPTURECOUNT
,
&
captureCount
);
pcre_fullinfo
(
re
_
,
NULL
,
PCRE_INFO_CAPTURECOUNT
,
&
captureCount
);
delete
[]
_
ovector
;
delete
[]
ovector
_
;
_
ovector
=
new
int
[(
captureCount
+
1
)
*
3
];
ovector
_
=
new
int
[(
captureCount
+
1
)
*
3
];
_
ovectorSize
=
(
captureCount
+
1
)
*
3
;
ovectorSize
_
=
(
captureCount
+
1
)
*
3
;
}
unsigned
int
Pattern
::
getCaptureGroupCount
(
void
)
unsigned
int
Pattern
::
getCaptureGroupCount
()
{
int
captureCount
;
pcre_fullinfo
(
_
re
,
NULL
,
PCRE_INFO_CAPTURECOUNT
,
&
captureCount
);
pcre_fullinfo
(
re
_
,
NULL
,
PCRE_INFO_CAPTURECOUNT
,
&
captureCount
);
return
captureCount
;
}
std
::
vector
<
std
::
string
>
Pattern
::
groups
(
void
)
std
::
vector
<
std
::
string
>
Pattern
::
groups
()
{
const
char
**
stringList
;
pcre_get_substring_list
(
_
subject
.
c_str
(),
_
ovector
,
_
count
,
pcre_get_substring_list
(
subject
_
.
c_str
(),
ovector
_
,
count
_
,
&
stringList
);
std
::
vector
<
std
::
string
>
matchedSubstrings
;
...
...
@@ -143,16 +141,11 @@ std::string Pattern::group(int groupNumber)
{
const
char
*
stringPtr
;
int
rc
=
pcre_get_substring
(
_subject
.
substr
(
_offset
[
0
]).
c_str
(),
_ovector
,
_count
,
groupNumber
,
&
stringPtr
);
int
rc
=
pcre_get_substring
(
subject_
.
substr
(
offset_
[
0
]).
c_str
(),
ovector_
,
count_
,
groupNumber
,
&
stringPtr
);
if
(
rc
<
0
)
{
switch
(
rc
)
{
case
PCRE_ERROR_NOSUBSTRING
:
throw
std
::
out_of_range
(
"Invalid group reference."
);
...
...
@@ -174,20 +167,13 @@ std::string Pattern::group(int groupNumber)
std
::
string
Pattern
::
group
(
const
std
::
string
&
groupName
)
{
const
char
*
stringPtr
=
NULL
;
int
rc
=
pcre_get_named_substring
(
_re
,
_subject
.
substr
(
_offset
[
0
]).
c_str
(),
_ovector
,
_count
,
groupName
.
c_str
(),
int
rc
=
pcre_get_named_substring
(
re_
,
subject_
.
substr
(
offset_
[
0
]).
c_str
(),
ovector_
,
count_
,
groupName
.
c_str
(),
&
stringPtr
);
if
(
rc
<
0
)
{
switch
(
rc
)
{
case
PCRE_ERROR_NOSUBSTRING
:
break
;
case
PCRE_ERROR_NOMEMORY
:
...
...
@@ -201,106 +187,89 @@ std::string Pattern::group(const std::string& groupName)
std
::
string
matchedStr
;
if
(
stringPtr
)
{
matchedStr
=
stringPtr
;
pcre_free_substring
(
stringPtr
);
}
else
{
matchedStr
=
""
;
}
return
matchedStr
;
}
void
Pattern
::
start
(
const
std
::
string
&
groupName
)
const
{
int
index
=
pcre_get_stringnumber
(
_
re
,
groupName
.
c_str
());
int
index
=
pcre_get_stringnumber
(
re
_
,
groupName
.
c_str
());
start
(
index
);
}
size_t
Pattern
::
start
(
unsigned
int
groupNumber
)
const
{
if
(
groupNumber
<=
(
unsigned
int
)
_
count
)
{
return
_
ovector
[(
groupNumber
+
1
)
*
2
];
}
else
{
if
(
groupNumber
<=
(
unsigned
int
)
count
_
)
return
ovector
_
[(
groupNumber
+
1
)
*
2
];
else
throw
std
::
out_of_range
(
"Invalid group reference."
);
}
}
size_t
Pattern
::
start
(
void
)
const
size_t
Pattern
::
start
()
const
{
return
_
ovector
[
0
]
+
_
offset
[
0
];
return
ovector
_
[
0
]
+
offset
_
[
0
];
}
void
Pattern
::
end
(
const
std
::
string
&
groupName
)
const
{
int
index
=
pcre_get_stringnumber
(
_
re
,
groupName
.
c_str
());
int
index
=
pcre_get_stringnumber
(
re
_
,
groupName
.
c_str
());
end
(
index
);
}
size_t
Pattern
::
end
(
unsigned
int
groupNumber
)
const
{
if
(
groupNumber
<=
(
unsigned
int
)
_
count
)
{
return
_
ovector
[((
groupNumber
+
1
)
*
2
)
+
1
]
-
1
;
}
else
{
if
(
groupNumber
<=
(
unsigned
int
)
count
_
)
return
ovector
_
[((
groupNumber
+
1
)
*
2
)
+
1
]
-
1
;
else
throw
std
::
out_of_range
(
"Invalid group reference."
);
}
}
size_t
Pattern
::
end
(
void
)
const
size_t
Pattern
::
end
()
const
{
return
(
_
ovector
[
1
]
-
1
)
+
_
offset
[
0
];
return
(
ovector
_
[
1
]
-
1
)
+
offset
_
[
0
];
}
bool
Pattern
::
matches
(
void
)
throw
(
match_error
)
bool
Pattern
::
matches
()
{
return
matches
(
_
subject
);
return
matches
(
subject
_
);
}
bool
Pattern
::
matches
(
const
std
::
string
&
subject
)
throw
(
match_error
)
bool
Pattern
::
matches
(
const
std
::
string
&
subject
)
{
// Try to find a match for this pattern
int
rc
=
pcre_exec
(
_re
,
NULL
,
subject
.
substr
(
_offset
[
1
]).
c_str
(),
subject
.
length
()
-
_offset
[
1
],
0
,
_options
,
_ovector
,
_ovectorSize
);
int
rc
=
pcre_exec
(
re_
,
NULL
,
subject
.
substr
(
offset_
[
1
]).
c_str
(),
subject
.
length
()
-
offset_
[
1
],
0
,
options_
,
ovector_
,
ovectorSize_
);
// Matching failed.
if
(
rc
<
0
)
{
_
offset
[
0
]
=
_
offset
[
1
]
=
0
;
offset
_
[
0
]
=
offset
_
[
1
]
=
0
;
return
false
;
}
// Handle the case if matching should be done globally
if
(
_
optionsDescription
.
find
(
"g"
)
!=
std
::
string
::
npos
)
{
_
offset
[
0
]
=
_
offset
[
1
];
if
(
optionsDescription
_
.
find
(
"g"
)
!=
std
::
string
::
npos
)
{
offset
_
[
0
]
=
offset
_
[
1
];
// New offset is old offset + end of relative offset
_
offset
[
1
]
=
_
ovector
[
1
]
+
_
offset
[
0
];
offset
_
[
1
]
=
ovector
_
[
1
]
+
offset
_
[
0
];
}
// Matching succeded but not enough space.
if
(
rc
==
0
)
{
// @TODO figure out something more clever to do in this case.
if
(
rc
==
0
)
throw
match_error
(
"No space to store all substrings."
);
// @TODO figure out something more clever to do in that case.
}
// Matching succeeded. Keep the number of substrings for
// subsequent calls to group().
_
count
=
rc
;
count
_
=
rc
;
return
true
;
}
std
::
vector
<
std
::
string
>
Pattern
::
split
(
void
)
std
::
vector
<
std
::
string
>
Pattern
::
split
()
{
size_t
tokenEnd
=
-
1
;
size_t
tokenStart
=
0
;
...
...
@@ -309,15 +278,13 @@ std::vector<std::string> Pattern::split(void)
while
(
matches
())
{
tokenStart
=
start
();
substringSplitted
.
push_back
(
_
subject
.
substr
(
tokenEnd
+
1
,
substringSplitted
.
push_back
(
subject
_
.
substr
(
tokenEnd
+
1
,
tokenStart
-
tokenEnd
-
1
));
tokenEnd
=
end
();
}
substringSplitted
.
push_back
(
_
subject
.
substr
(
tokenEnd
+
1
,
tokenStart
-
tokenEnd
-
1
));
substringSplitted
.
push_back
(
subject
_
.
substr
(
tokenEnd
+
1
,
tokenStart
-
tokenEnd
-
1
));
return
substringSplitted
;
}
}
This diff is collapsed.
Click to expand it.
daemon/src/sip/pattern.h
+
31
−
49
View file @
d2f15f8d
...
...
@@ -95,12 +95,12 @@ class Pattern {
* @param pattern The new pattern
*/
void
operator
=
(
const
std
::
string
&
pattern
)
{
_
pattern
=
pattern
;
pattern
_
=
pattern
;
compile
();
}
void
operator
=
(
const
char
*
pattern
)
{
_
pattern
=
pattern
;
pattern
_
=
pattern
;
compile
();
}
...
...
@@ -109,7 +109,7 @@ class Pattern {
* from the pattern that was set for
* this object.
*/
void
compile
(
void
);
void
compile
();
/**
* Get the currently set regular expression
...
...
@@ -117,8 +117,8 @@ class Pattern {
*
* @return The currently set pattern
*/
std
::
string
getPattern
(
void
)
const
{
return
_
pattern
;
std
::
string
getPattern
()
const
{
return
pattern
_
;
}
/**
...
...
@@ -131,7 +131,7 @@ class Pattern {
*
*/
void
operator
<<
(
const
std
::
string
&
subject
)
{
_
subject
=
subject
;
subject
_
=
subject
;
}
/**
...
...
@@ -139,7 +139,7 @@ class Pattern {
*
* @return the start position of the overall match.
*/
size_t
start
(
void
)
const
;
size_t
start
()
const
;
/**
* Get the start position of the specified match.
...
...
@@ -162,7 +162,7 @@ class Pattern {
*
* @return the end position of the overall match.
*/
size_t
end
(
void
)
const
;
size_t
end
()
const
;
/**
* Get the end position of the specified match.
...
...
@@ -191,7 +191,7 @@ class Pattern {
* @pre The regular expression should have been
* compiled prior to the execution of this method.
*/
unsigned
int
getCaptureGroupCount
(
void
);
unsigned
int
getCaptureGroupCount
();
/**
* Get the substring matched in a capturing
...
...
@@ -241,7 +241,7 @@ class Pattern {
* @pre The regular expression should have been
* compiled prior to the execution of this method.
*/
std
::
vector
<
std
::
string
>
groups
(
void
);
std
::
vector
<
std
::
string
>
groups
();
/**
* Try to match the compiled pattern with a
...
...
@@ -260,7 +260,7 @@ class Pattern {
* with the new matches. Therefore, subsequent
* calls to group may return different results.
*/
bool
matches
(
const
std
::
string
&
subject
)
throw
(
match_error
)
;
bool
matches
(
const
std
::
string
&
subject
);
/**
* Try to match the compiled pattern with the implicit
...
...
@@ -276,7 +276,7 @@ class Pattern {
* with the new matches. Therefore, subsequent
* calls to group may return different results.
*/
bool
matches
(
void
)
throw
(
match_error
);
bool
matches
();
/**
* Split the subject into a list of substrings.
...
...
@@ -290,59 +290,41 @@ class Pattern {
* by this operation. In other words: subject_before =
* subject_after.
*/
std
::
vector
<
std
::
string
>
split
(
void
);
// throw(match_error
);
std
::
vector
<
std
::
string
>
split
();
private
:
/**
* The regular expression that represents that pattern.
*/
std
::
string
_pattern
;
// The regular expression that represents that pattern.
std
::
string
pattern_
;
/**
* The optional subject string.
*/
std
::
string
_subject
;
// The optional subject string.
std
::
string
subject_
;
/**
* PCRE struct that
* contains the compiled regular
* expression
*/
pcre
*
_
re
;
pcre
*
re
_
;
/**
* The internal output vector used by PCRE.
*/
int
*
_ovector
;
// The internal output vector used by PCRE.
int
*
ovector_
;
/**
* The size of the _ovector
*/
int
_ovectorSize
;
// The size of the ovector_
int
ovectorSize_
;
/**
* Current offset in the _ovector;
*/
int
_offset
[
2
];
// Current offset in the ovector_;
int
offset_
[
2
];
/**
* The number of substrings matched after calling
* pcre_exec.
*/
int
_count
;
// The number of substrings matched after calling pcre_exec.
int
count_
;
/**
* PCRE options for this pattern.
*/
int
_options
;
// PCRE options for this pattern.
int
options_
;
/**
* String representation of the options.
*/
std
::
string
_optionsDescription
;
// String representation of the options.
std
::
string
optionsDescription_
;
};
}
#endif // __PATTERN_H__
#endif // __PATTERN_H__ // __PATTERN_H__ // __PATTERN_H__ // __PATTERN_H__
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment