diff options
author | Richard Walters <rwalters@digitalstirling.com> | 2018-07-01 16:58:37 -0700 |
---|---|---|
committer | Richard Walters <rwalters@digitalstirling.com> | 2018-07-01 16:58:37 -0700 |
commit | 16b5c56c4ecbbb5c6153f9e16228a8d8cf95c50d (patch) | |
tree | 9bf5689b45b08c4d6a9319651a6ca80e4f7830c6 /src/IsCharacterInSet.hpp | |
parent | cdc3f449812d0d45a3ea271636d669eb05ba3751 (diff) |
Refactoring
Added CharacterSet as a class to represent character sets,
allowing us to build singletons and composite character sets
more concisely.
Diffstat (limited to 'src/IsCharacterInSet.hpp')
-rw-r--r-- | src/IsCharacterInSet.hpp | 86 |
1 files changed, 85 insertions, 1 deletions
diff --git a/src/IsCharacterInSet.hpp b/src/IsCharacterInSet.hpp index f17460c..93d8fa9 100644 --- a/src/IsCharacterInSet.hpp +++ b/src/IsCharacterInSet.hpp @@ -10,10 +10,94 @@ */ #include <initializer_list> +#include <memory> namespace Uri { /** + * This represents a set of characters which can be queried + * to find out if a character is in the set or not. + */ + class CharacterSet { + // Lifecycle management + public: + ~CharacterSet(); + CharacterSet(const CharacterSet&); + CharacterSet(CharacterSet&&); + CharacterSet& operator=(const CharacterSet&); + CharacterSet& operator=(CharacterSet&&); + + // Methods + public: + /** + * This is the default constructor. + */ + CharacterSet(); + + /** + * This constructs a character set that contains + * just the given character. + * + * @param[in] c + * This is the only character to put in the set. + */ + CharacterSet(char c); + + /** + * This constructs a character set that contains all the + * characters between the given "first" and "last" + * characters, inclusive. + * + * @param[in] first + * This is the first of the range of characters + * to put in the set. + * + * @param[in] last + * This is the last of the range of characters + * to put in the set. + */ + CharacterSet(char first, char last); + + /** + * This constructs a character set that contains all the + * characters in all the other given character sets. + * + * @param[in] characterSets + * These are the character sets to include. + */ + CharacterSet( + std::initializer_list< const CharacterSet > characterSets + ); + + /** + * This method checks to see if the given character + * is in the character set. + * + * @param[in] c + * This is the character to check. + * + * @return + * An indication of whether or not the given character + * is in the character set is returned. + */ + bool Contains(char c) const; + + // Private Properties + private: + /** + * This is the type of structure that contains the private + * properties of the instance. It is defined in the implementation + * and declared here to ensure that it is scoped inside the class. + */ + struct Impl; + + /** + * This contains the private properties of the instance. + */ + std::unique_ptr< struct Impl > impl_; + }; + + /** * This function determines whether or not the given character * is in the given character set. * @@ -29,7 +113,7 @@ namespace Uri { */ bool IsCharacterInSet( char c, - std::initializer_list< char > characterSet + const CharacterSet& characterSet ); } |