X-Git-Url: http://git.tdb.fi/?p=libs%2Fcore.git;a=blobdiff_plain;f=source%2Fregmatch.h;fp=source%2Fregmatch.h;h=19cac11027dac128f6cdd537fe771d3a2316a2d9;hp=f1f2448d50eb257dfe058af008cde35c9bce51c9;hb=5b1368cb791cab043f0435628cacbaff36e39b7b;hpb=36f9e78ae75f5e14b132f37d249340ad3480b8ce diff --git a/source/regmatch.h b/source/regmatch.h index f1f2448..19cac11 100644 --- a/source/regmatch.h +++ b/source/regmatch.h @@ -4,6 +4,7 @@ This file is part of libmspstrings Copyright © 2007 Mikko Rasa Distributed under the LGPL */ + #ifndef MSP_STRINGS_REGMATCH_H_ #define MSP_STRINGS_REGMATCH_H_ @@ -14,12 +15,11 @@ namespace Msp { /** This class stores the result of a Regex being matched against a string. If the -match was successful, the RegMatch object evaluates to true, allowing it to be -used in constructs like \code if(RegMatch match=regex.match("foo")) \endcode. +match was successful, the RegMatch object evaluates to true. A RegMatch representing a successful match has one or more groups, indicating matching parts of the string. The first group (with index 0) indicates the -part matched by the whol regex. Further groups, if present, indicate parts +part matched by the whole regex. Further groups, if present, indicate parts matched by subregexes. These are ordered from left to right, by the opening parenthesis of the subregex. */ @@ -40,53 +40,40 @@ public: Group(): match(false) { } operator bool() const { return match; } }; + typedef std::vector GroupArray; - /** - Constructs a RegMatch representig a non-match. Used by Regex. - */ +private: + GroupArray groups; + +public: + /** Constructs a RegMatch representing a non-match. */ RegMatch() { } - /** - Constructs a new RegMatch from a string and groups. The length and str members - of each group are computed and need not be set. Used by Regex. - */ + /** Constructs a new RegMatch from a string and groups. The length and str + members of each group are computed and need not be set. Intended to be used + by the Regex class. */ RegMatch(const std::string &, const std::vector &); - /** - Returns a reference to a single group in the match. An exception is thrown - if the requested group does not exist. - */ + /** Returns a reference to a single group in the match. */ const Group &group(unsigned) const; - /** - Returns true if the RegMatch object represents a non-match. - */ + /** Returns true if the RegMatch object represents a non-match. */ bool empty() const { return groups.empty(); } - /** - Returns the number of groups in this match. - */ + /** Returns the number of groups in this match. */ unsigned size() const { return groups.size(); } - /** - Returns the begin offset of the whole match. - */ - unsigned begin() const { return groups.empty()?0:groups[0].begin; } + /** Returns the begin offset of the whole match. */ + unsigned begin() const { return groups.empty() ? 0 : groups[0].begin; } - /** - Returns the end offset of the whole match. - */ - unsigned end() const { return groups.empty()?0:groups[0].end; } + /** Returns the end offset of the whole match. */ + unsigned end() const { return groups.empty() ? 0 : groups[0].end; } - /** - Shortcut for the group() function. - */ + /** Shorthand for the group() function. */ const Group &operator[](unsigned i) const { return group(i); } operator bool() const { return !empty(); } -private: - std::vector groups; }; } // namespace Msp