aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/CharacterSet.cpp4
-rw-r--r--test/src/CharacterSetTests.cpp14
2 files changed, 18 insertions, 0 deletions
diff --git a/src/CharacterSet.cpp b/src/CharacterSet.cpp
index 5287806..d0b31a4 100644
--- a/src/CharacterSet.cpp
+++ b/src/CharacterSet.cpp
@@ -9,6 +9,7 @@
#include "CharacterSet.hpp"
+#include <algorithm>
#include <set>
namespace Uri {
@@ -51,6 +52,9 @@ namespace Uri {
CharacterSet::CharacterSet(char first, char last)
: impl_(new Impl)
{
+ if (first > last) {
+ std::swap(first, last);
+ }
for (char c = first; c < last + 1; ++c) {
(void)impl_->charactersInSet.insert(c);
}
diff --git a/test/src/CharacterSetTests.cpp b/test/src/CharacterSetTests.cpp
index 7013127..3663ee6 100644
--- a/test/src/CharacterSetTests.cpp
+++ b/test/src/CharacterSetTests.cpp
@@ -43,6 +43,20 @@ TEST(CharacterSetTests, RangeConstructor) {
}
}
+TEST(CharacterSetTests, Range_Constructor_Reversed) {
+ Uri::CharacterSet cs('G', 'A');
+ for (char c = 0; c < 0x7F; ++c) {
+ if (
+ (c >= 'A')
+ && (c <= 'G')
+ ) {
+ ASSERT_TRUE(cs.Contains(c));
+ } else {
+ ASSERT_FALSE(cs.Contains(c));
+ }
+ }
+}
+
TEST(CharacterSetTests, InitializerListConstructor) {
Uri::CharacterSet cs1{'X'};
for (char c = 0; c < 0x7F; ++c) {