diff options
author | Richard Walters <rwalters@digitalstirling.com> | 2018-07-01 23:39:59 -0700 |
---|---|---|
committer | Richard Walters <rwalters@digitalstirling.com> | 2018-07-01 23:39:59 -0700 |
commit | ff1f4f43d37d0f3c3b599e6a714239962e1cc2f7 (patch) | |
tree | b11a356e3779178c744b6173b32bf90c66d0e6e7 /src/CharacterSet.cpp | |
parent | b6728bb7151b3b72cbd6787e3a9d9d581c6e741c (diff) |
Rename IsCharacterInSet module to CharacterSet
Diffstat (limited to 'src/CharacterSet.cpp')
-rw-r--r-- | src/CharacterSet.cpp | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/src/CharacterSet.cpp b/src/CharacterSet.cpp new file mode 100644 index 0000000..3869ec5 --- /dev/null +++ b/src/CharacterSet.cpp @@ -0,0 +1,87 @@ +/** + * @file IsCharacterInSet.cpp + * + * This module contains the implementation of the + * Uri::IsCharacterInSet function and the CharacterSet class. + * + * © 2018 by Richard Walters + */ + +#include "CharacterSet.hpp" + +#include <set> + +namespace Uri { + + /** + * This contains the private properties of the CharacterSet class. + */ + struct CharacterSet::Impl { + /** + * This holds the characters in the set. + */ + std::set< char > charactersInSet; + }; + + CharacterSet::~CharacterSet() = default; + CharacterSet::CharacterSet(const CharacterSet& other) + : impl_(new Impl(*other.impl_)) + { + } + CharacterSet::CharacterSet(CharacterSet&& other) = default; + CharacterSet& CharacterSet::operator=(const CharacterSet& other) { + if (this != &other) { + *impl_ = *other.impl_; + } + return *this; + } + CharacterSet& CharacterSet::operator=(CharacterSet&& other) = default; + + CharacterSet::CharacterSet() + : impl_(new Impl) + { + } + + CharacterSet::CharacterSet(char c) + : impl_(new Impl) + { + (void)impl_->charactersInSet.insert(c); + } + + CharacterSet::CharacterSet(char first, char last) + : impl_(new Impl) + { + for (char c = first; c < last + 1; ++c) { + (void)impl_->charactersInSet.insert(c); + } + } + + CharacterSet::CharacterSet( + std::initializer_list< const CharacterSet > characterSets + ) + : impl_(new Impl) + { + for ( + auto characterSet = characterSets.begin(); + characterSet != characterSets.end(); + ++characterSet + ) { + impl_->charactersInSet.insert( + characterSet->impl_->charactersInSet.begin(), + characterSet->impl_->charactersInSet.end() + ); + } + } + + bool CharacterSet::Contains(char c) const { + return impl_->charactersInSet.find(c) != impl_->charactersInSet.end(); + } + + bool IsCharacterInSet( + char c, + const CharacterSet& characterSet + ) { + return characterSet.Contains(c); + } + +} |