1
/* This file is part of the KDE project
2
Copyright (C) 2003-2005 Jarosław Staniek <staniek@kde.org>
3
Copyright (C) 2005 Martin Ellis <martin.ellis@kdemail.net>
5
This program is free software; you can redistribute it and/or
6
modify it under the terms of the GNU Library General Public
7
License as published by the Free Software Foundation; either
8
version 2 of the License, or (at your option) any later version.
10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
Library General Public License for more details.
15
You should have received a copy of the GNU Library General Public License
16
along with this program; see the file COPYING. If not, write to
17
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18
* Boston, MA 02110-1301, USA.
21
#ifndef KEXIUTILS_IDENTIFIER_H
22
#define KEXIUTILS_IDENTIFIER_H
24
#include "validator.h"
30
/*! \return true if \a s is a valid identifier, ie. starts with a letter or '_' character
31
and contains only letters, numbers and '_' character. */
32
KEXIUTILS_EXPORT bool isIdentifier(const QString& s);
34
/*! \return valid identifier based on \a s.
35
Non-alphanumeric characters (or spaces) are replaced with '_'.
36
If a number is at the beginning, '_' is added at start.
37
Empty strings are not changed. Case remains unchanged. */
38
KEXIUTILS_EXPORT QString string2Identifier(const QString &s);
40
/*! \return useful message "Value of "valueName" column must be an identifier.
41
"v" is not a valid identifier.". It is also used by IdentifierValidator. */
42
KEXIUTILS_EXPORT QString identifierExpectedMessage(const QString &valueName,
45
//! \return Valid filename based on \a s
46
KEXIUTILS_EXPORT QString string2FileName(const QString &s);
48
//! Validates input for identifier name.
49
class KEXIUTILS_EXPORT IdentifierValidator : public Validator
52
IdentifierValidator(QObject * parent = 0);
53
virtual ~IdentifierValidator();
54
virtual State validate(QString & input, int & pos) const;
57
virtual Validator::Result internalCheck(const QString &valueName, const QVariant& v,
58
QString &message, QString &details);