Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ISC Open Source Projects
Kea
Commits
cb28f3c4
Commit
cb28f3c4
authored
Mar 02, 2012
by
Jelte Jansen
Browse files
[1602] rename split methods
leftSplit() -> stripLeft() rightSplit() -> stripRight()
parent
c271fcc0
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/lib/dns/labelsequence.cc
View file @
cb28f3c4
...
...
@@ -51,18 +51,18 @@ LabelSequence::equals(const LabelSequence& other, bool case_sensitive) const {
}
void
LabelSequence
::
leftSpli
t
(
size_t
i
)
{
LabelSequence
::
stripLef
t
(
size_t
i
)
{
if
(
i
>=
getLabelCount
())
{
isc_throw
(
OutOfRange
,
"Cannot s
plit
to zero or less labels; "
<<
i
<<
isc_throw
(
OutOfRange
,
"Cannot s
trip
to zero or less labels; "
<<
i
<<
" (labelcount: "
<<
getLabelCount
()
<<
")"
);
}
first_label_
+=
i
;
}
void
LabelSequence
::
rightSpli
t
(
size_t
i
)
{
LabelSequence
::
stripRigh
t
(
size_t
i
)
{
if
(
i
>=
getLabelCount
())
{
isc_throw
(
OutOfRange
,
"Cannot s
plit
to zero or less labels; "
<<
i
<<
isc_throw
(
OutOfRange
,
"Cannot s
trip
to zero or less labels; "
<<
i
<<
" (labelcount: "
<<
getLabelCount
()
<<
")"
);
}
last_label_
-=
i
;
...
...
src/lib/dns/labelsequence.h
View file @
cb28f3c4
...
...
@@ -24,16 +24,17 @@ namespace dns {
/// \brief Light-weight Accessor to Name object
///
/// The purpose of this class is to easily match Names and parts of Names,
/// without needing to copy the underlying data on each
split
.
/// without needing to copy the underlying data on each
label strip
.
///
/// It can only work on existing Name objects, and the Name object MUST
/// remain in scope during the entire lifetime of its associated
/// LabelSequence(s).
///
/// Upon creation of a LabelSequence, it records the offsets of the
/// labels in the wireformat data of the Name. When split() is called on
/// the LabelSequence, no changes in the Name's data occur, but the
/// internal pointers of the LabelSequence are modified.
/// labels in the wireformat data of the Name. When stripLeft() or
/// stripRight() is called on the LabelSequence, no changes in the
/// Name's data occur, but the internal pointers of the
/// LabelSequence are modified.
///
/// LabelSequences can be compared to other LabelSequences, and their
/// data can be requested (which then points to part of the original
...
...
@@ -88,7 +89,7 @@ public:
/// of labels currently pointed to by this LabelSequence
///
/// \param i The number of labels to remove.
void
leftSpli
t
(
size_t
i
);
void
stripLef
t
(
size_t
i
);
/// \brief Remove labels from the end of this LabelSequence
///
...
...
@@ -99,7 +100,7 @@ public:
/// of labels currently pointed to by this LabelSequence
///
/// \param i The number of labels to remove.
void
rightSpli
t
(
size_t
i
);
void
stripRigh
t
(
size_t
i
);
/// \brief Returns the current number of labels for this LabelSequence
///
...
...
src/lib/dns/tests/labelsequence_unittest.cc
View file @
cb28f3c4
...
...
@@ -143,89 +143,89 @@ TEST_F(LabelSequenceTest, getData) {
getDataCheck
(
"
\000
"
,
1
,
ls7
);
};
TEST_F
(
LabelSequenceTest
,
leftSpli
t
)
{
TEST_F
(
LabelSequenceTest
,
stripLef
t
)
{
EXPECT_TRUE
(
ls1
.
equals
(
ls3
));
ls1
.
leftSpli
t
(
0
);
ls1
.
stripLef
t
(
0
);
getDataCheck
(
"
\007
example
\003
org
\000
"
,
13
,
ls1
);
EXPECT_TRUE
(
ls1
.
equals
(
ls3
));
ls1
.
leftSpli
t
(
1
);
ls1
.
stripLef
t
(
1
);
getDataCheck
(
"
\003
org
\000
"
,
5
,
ls1
);
EXPECT_FALSE
(
ls1
.
equals
(
ls3
));
ls1
.
leftSpli
t
(
1
);
ls1
.
stripLef
t
(
1
);
getDataCheck
(
"
\000
"
,
1
,
ls1
);
EXPECT_TRUE
(
ls1
.
equals
(
ls7
));
ls2
.
leftSpli
t
(
2
);
ls2
.
stripLef
t
(
2
);
getDataCheck
(
"
\000
"
,
1
,
ls2
);
EXPECT_TRUE
(
ls2
.
equals
(
ls7
));
}
TEST_F
(
LabelSequenceTest
,
rightSpli
t
)
{
TEST_F
(
LabelSequenceTest
,
stripRigh
t
)
{
EXPECT_TRUE
(
ls1
.
equals
(
ls3
));
ls1
.
rightSpli
t
(
1
);
ls1
.
stripRigh
t
(
1
);
getDataCheck
(
"
\007
example
\003
org"
,
12
,
ls1
);
EXPECT_FALSE
(
ls1
.
equals
(
ls3
));
ls1
.
rightSpli
t
(
1
);
ls1
.
stripRigh
t
(
1
);
getDataCheck
(
"
\007
example"
,
8
,
ls1
);
EXPECT_FALSE
(
ls1
.
equals
(
ls3
));
ASSERT_FALSE
(
ls1
.
equals
(
ls2
));
ls2
.
rightSpli
t
(
2
);
ls2
.
stripRigh
t
(
2
);
getDataCheck
(
"
\007
example"
,
8
,
ls2
);
EXPECT_TRUE
(
ls1
.
equals
(
ls2
));
}
TEST_F
(
LabelSequenceTest
,
s
plit_oor
)
{
EXPECT_THROW
(
ls1
.
leftSpli
t
(
100
),
isc
::
OutOfRange
);
EXPECT_THROW
(
ls1
.
leftSpli
t
(
5
),
isc
::
OutOfRange
);
EXPECT_THROW
(
ls1
.
leftSpli
t
(
4
),
isc
::
OutOfRange
);
EXPECT_THROW
(
ls1
.
leftSpli
t
(
3
),
isc
::
OutOfRange
);
TEST_F
(
LabelSequenceTest
,
s
tripOutOfRange
)
{
EXPECT_THROW
(
ls1
.
stripLef
t
(
100
),
isc
::
OutOfRange
);
EXPECT_THROW
(
ls1
.
stripLef
t
(
5
),
isc
::
OutOfRange
);
EXPECT_THROW
(
ls1
.
stripLef
t
(
4
),
isc
::
OutOfRange
);
EXPECT_THROW
(
ls1
.
stripLef
t
(
3
),
isc
::
OutOfRange
);
getDataCheck
(
"
\007
example
\003
org
\000
"
,
13
,
ls1
);
EXPECT_THROW
(
ls1
.
rightSpli
t
(
100
),
isc
::
OutOfRange
);
EXPECT_THROW
(
ls1
.
rightSpli
t
(
5
),
isc
::
OutOfRange
);
EXPECT_THROW
(
ls1
.
rightSpli
t
(
4
),
isc
::
OutOfRange
);
EXPECT_THROW
(
ls1
.
rightSpli
t
(
3
),
isc
::
OutOfRange
);
EXPECT_THROW
(
ls1
.
stripRigh
t
(
100
),
isc
::
OutOfRange
);
EXPECT_THROW
(
ls1
.
stripRigh
t
(
5
),
isc
::
OutOfRange
);
EXPECT_THROW
(
ls1
.
stripRigh
t
(
4
),
isc
::
OutOfRange
);
EXPECT_THROW
(
ls1
.
stripRigh
t
(
3
),
isc
::
OutOfRange
);
getDataCheck
(
"
\007
example
\003
org
\000
"
,
13
,
ls1
);
}
TEST_F
(
LabelSequenceTest
,
getLabelCount
)
{
EXPECT_EQ
(
3
,
ls1
.
getLabelCount
());
ls1
.
leftSpli
t
(
0
);
ls1
.
stripLef
t
(
0
);
EXPECT_EQ
(
3
,
ls1
.
getLabelCount
());
ls1
.
leftSpli
t
(
1
);
ls1
.
stripLef
t
(
1
);
EXPECT_EQ
(
2
,
ls1
.
getLabelCount
());
ls1
.
leftSpli
t
(
1
);
ls1
.
stripLef
t
(
1
);
EXPECT_EQ
(
1
,
ls1
.
getLabelCount
());
EXPECT_EQ
(
3
,
ls2
.
getLabelCount
());
ls2
.
rightSpli
t
(
1
);
ls2
.
stripRigh
t
(
1
);
EXPECT_EQ
(
2
,
ls2
.
getLabelCount
());
ls2
.
rightSpli
t
(
1
);
ls2
.
stripRigh
t
(
1
);
EXPECT_EQ
(
1
,
ls2
.
getLabelCount
());
EXPECT_EQ
(
3
,
ls3
.
getLabelCount
());
ls3
.
rightSpli
t
(
2
);
ls3
.
stripRigh
t
(
2
);
EXPECT_EQ
(
1
,
ls3
.
getLabelCount
());
EXPECT_EQ
(
5
,
ls4
.
getLabelCount
());
ls4
.
rightSpli
t
(
3
);
ls4
.
stripRigh
t
(
3
);
EXPECT_EQ
(
2
,
ls4
.
getLabelCount
());
EXPECT_EQ
(
3
,
ls5
.
getLabelCount
());
ls5
.
leftSpli
t
(
2
);
ls5
.
stripLef
t
(
2
);
EXPECT_EQ
(
1
,
ls5
.
getLabelCount
());
}
TEST_F
(
LabelSequenceTest
,
comparePart
)
{
EXPECT_FALSE
(
ls1
.
equals
(
ls8
));
//
Split
root label from example.org.
ls1
.
rightSpli
t
(
1
);
//
Split
foo from foo.example.org.bar.
ls8
.
leftSpli
t
(
1
);
//
Split
bar. (i.e. bar and root) too
ls8
.
rightSpli
t
(
2
);
//
strip
root label from example.org.
ls1
.
stripRigh
t
(
1
);
//
strip
foo from foo.example.org.bar.
ls8
.
stripLef
t
(
1
);
//
strip
bar. (i.e. bar and root) too
ls8
.
stripRigh
t
(
2
);
EXPECT_TRUE
(
ls1
.
equals
(
ls8
));
...
...
@@ -238,16 +238,16 @@ TEST_F(LabelSequenceTest, comparePart) {
TEST_F
(
LabelSequenceTest
,
isAbsolute
)
{
ASSERT_TRUE
(
ls1
.
isAbsolute
());
ls1
.
leftSpli
t
(
1
);
ls1
.
stripLef
t
(
1
);
ASSERT_TRUE
(
ls1
.
isAbsolute
());
ls1
.
rightSpli
t
(
1
);
ls1
.
stripRigh
t
(
1
);
ASSERT_FALSE
(
ls1
.
isAbsolute
());
ASSERT_TRUE
(
ls2
.
isAbsolute
());
ls2
.
rightSpli
t
(
1
);
ls2
.
stripRigh
t
(
1
);
ASSERT_FALSE
(
ls2
.
isAbsolute
());
ASSERT_TRUE
(
ls3
.
isAbsolute
());
ls3
.
leftSpli
t
(
2
);
ls3
.
stripLef
t
(
2
);
ASSERT_TRUE
(
ls3
.
isAbsolute
());
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment