File indexing completed on 2025-03-09 03:57:05

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2009-08-11
0007  * Description : the main parser object for the AdvancedRename utility
0008  *
0009  * SPDX-FileCopyrightText: 2009-2012 by Andi Clemens <andi dot clemens at gmail dot com>
0010  *
0011  * SPDX-License-Identifier: GPL-2.0-or-later
0012  *
0013  * ============================================================ */
0014 
0015 #ifndef DIGIKAM_PARSER_H
0016 #define DIGIKAM_PARSER_H
0017 
0018 // Qt includes
0019 
0020 #include <QList>
0021 #include <QMap>
0022 #include <QString>
0023 
0024 // Local includes
0025 
0026 #include "modifier.h"
0027 #include "option.h"
0028 
0029 namespace Digikam
0030 {
0031 
0032 class Modifier;
0033 class Option;
0034 
0035 class Parser
0036 {
0037 
0038 public:
0039 
0040     explicit Parser();
0041     virtual ~Parser();
0042 
0043     void          reset();
0044 
0045     QString       parse(ParseSettings& settings);
0046 
0047     RulesList     options()   const;
0048     RulesList     modifiers() const;
0049 
0050     bool          tokenAtPosition(ParseSettings& settings, int pos);
0051     bool          tokenAtPosition(ParseSettings& settings, int pos, int& start, int& length);
0052 
0053     ParseResults  invalidModifiers(ParseSettings& settings);
0054 
0055     /**
0056      * check if the given parse string is valid
0057      * @param str the parse string
0058      * @return true if valid / can be parsed
0059      */
0060     static bool parseStringIsValid(const QString& str);
0061 
0062 protected:
0063 
0064     void registerOption(Rule* option);
0065     void unregisterOption(const Rule* option);
0066 
0067     void registerModifier(Rule* modifier);
0068     void unregisterModifier(const Rule* modifier);
0069 
0070 private:
0071 
0072     ParseResults results(ParseSettings& settings);
0073 
0074     /**
0075      * Applies modifiers to the given ParseResults.
0076      * @param   settings        the ParseSettings with parseString to analyze
0077      * @param   results         the ParseResults object the modifiers should be applied to
0078      * @return  a ParseResults object with invalid modifiers (modifiers that have a wrong position in the parse string)
0079      */
0080     ParseResults applyModifiers(const ParseSettings& _settings, ParseResults& results);
0081 
0082 private:
0083 
0084     // Disable
0085     Parser(const Parser&)            = delete;
0086     Parser& operator=(const Parser&) = delete;
0087 
0088 private:
0089 
0090     class Private;
0091     Private* const d;
0092 };
0093 
0094 } // namespace Digikam
0095 
0096 #endif // DIGIKAM_PARSER_H