aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-01-21 17:59:28 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-01-21 17:59:28 +0000
commit7bd6aec3d95aa387f92a59dedb021d4357cd7927 (patch)
tree0f42ceece4247d53ba4a67a0b0281cfd75eaecf1
parentfbd98bbc02df59c88cb8394edee74e34c6e26283 (diff)
downloadpaludis-7bd6aec3d95aa387f92a59dedb021d4357cd7927.tar.gz
paludis-7bd6aec3d95aa387f92a59dedb021d4357cd7927.tar.xz
Merge keyword_name_validator, keyword_name_error into keyword_name. Separate files are overkill here.
-rw-r--r--paludis/files.m42
-rw-r--r--paludis/keyword_name.cc46
-rw-r--r--paludis/keyword_name.hh39
-rw-r--r--paludis/keyword_name_error.cc29
-rw-r--r--paludis/keyword_name_error.hh54
-rw-r--r--paludis/keyword_name_validator.cc63
-rw-r--r--paludis/keyword_name_validator.hh51
7 files changed, 83 insertions, 201 deletions
diff --git a/paludis/files.m4 b/paludis/files.m4
index e183ca6..e8493c7 100644
--- a/paludis/files.m4
+++ b/paludis/files.m4
@@ -69,8 +69,6 @@ add(`join', `hh', `cc', `test')
add(`key_value_config_file', `hh', `cc', `test')
add(`key_value_config_file_error', `hh', `cc')
add(`keyword_name', `hh', `cc')
-add(`keyword_name_error', `hh', `cc')
-add(`keyword_name_validator', `hh', `cc')
add(`line_config_file', `hh', `cc', `test')
add(`mask_reasons', `hh', `cc')
add(`name_error', `hh', `cc')
diff --git a/paludis/keyword_name.cc b/paludis/keyword_name.cc
index da91aa3..7e1041f 100644
--- a/paludis/keyword_name.cc
+++ b/paludis/keyword_name.cc
@@ -20,3 +20,49 @@
#include "keyword_name.hh"
+using namespace paludis;
+
+KeywordNameError::KeywordNameError(const std::string & name) throw () :
+ NameError(name, "keyword name")
+{
+}
+
+void
+KeywordNameValidator::validate(const std::string & s)
+{
+ static const std::string allowed_chars(
+ "abcdefghijklmnopqrstuvwxyz"
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+ "0123456789-+_");
+
+ do
+ {
+ switch (s.length())
+ {
+ case 0:
+ continue;
+
+ case 1:
+ if ("*" == s)
+ return;
+ continue;
+
+ case 2:
+ if ("-*" == s)
+ return;
+
+ /* fall throuth */
+ default:
+ if (std::string::npos != s.find_first_not_of(allowed_chars,
+ ('~' == s.at(0) ? 1 : 0)))
+ continue;
+ }
+
+ return;
+
+ } while (false);
+
+ Context c("When validating keyword name '" + s + "':");
+ throw KeywordNameError(s);
+}
+
diff --git a/paludis/keyword_name.hh b/paludis/keyword_name.hh
index 156b028..0cf8ba2 100644
--- a/paludis/keyword_name.hh
+++ b/paludis/keyword_name.hh
@@ -21,17 +21,52 @@
#define PALUDIS_GUARD_PALUDIS_KEYWORD_NAME_HH 1
#include <paludis/validated.hh>
-#include <paludis/keyword_name_validator.hh>
+#include <paludis/instantiation_policy.hh>
+#include <paludis/name_error.hh>
#include <string>
/** \file
- * Declarations for the KeywordName class.
+ * Declarations for KeywordName and related classes.
*
* \ingroup Environment
+ * \ingroup Database
+ * \ingroup Exception
*/
namespace paludis
{
/**
+ * A KeywordNameValidator handles validation rules for the value of a
+ * UseFlagName.
+ *
+ * \ingroup Environment
+ */
+ struct KeywordNameValidator :
+ private InstantiationPolicy<KeywordNameValidator, instantiation_method::NonInstantiableTag>
+ {
+ /**
+ * If the parameter is not a valid value for a KeywordName,
+ * throw a KeywordNameError.
+ */
+ static void validate(const std::string &);
+ };
+
+ /**
+ * A KeywordNameError is thrown if an invalid value is assigned to
+ * a KeywordNameName.
+ *
+ * \ingroup Environment
+ * \ingroup Exception
+ */
+ class KeywordNameError : public NameError
+ {
+ public:
+ /**
+ * Constructor.
+ */
+ KeywordNameError(const std::string & name) throw ();
+ };
+
+ /**
* A KeywordName holds a std::string that is a valid name for a KEYWORD.
*
* \ingroup Database
diff --git a/paludis/keyword_name_error.cc b/paludis/keyword_name_error.cc
deleted file mode 100644
index b9fdce4..0000000
--- a/paludis/keyword_name_error.cc
+++ /dev/null
@@ -1,29 +0,0 @@
-/* vim: set sw=4 sts=4 et foldmethod=syntax : */
-
-/*
- * Copyright (c) 2006 Ciaran McCreesh <ciaranm@gentoo.org>
- *
- * This file is part of the Paludis package manager. Paludis is free software;
- * you can redistribute it and/or modify it under the terms of the GNU General
- * Public License as published by the Free Software Foundation; either version
- * 2 of the License, or (at your option) any later version.
- *
- * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
- * details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
- * Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#include "keyword_name_error.hh"
-
-using namespace paludis;
-
-KeywordNameError::KeywordNameError(const std::string & name) throw () :
- NameError(name, "keyword name")
-{
-}
-
diff --git a/paludis/keyword_name_error.hh b/paludis/keyword_name_error.hh
deleted file mode 100644
index 40ed708..0000000
--- a/paludis/keyword_name_error.hh
+++ /dev/null
@@ -1,54 +0,0 @@
-/* vim: set sw=4 sts=4 et foldmethod=syntax : */
-
-/*
- * Copyright (c) 2006 Ciaran McCreesh <ciaranm@gentoo.org>
- *
- * This file is part of the Paludis package manager. Paludis is free software;
- * you can redistribute it and/or modify it under the terms of the GNU General
- * Public License version 2, as published by the Free Software Foundation.
- *
- * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
- * details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
- * Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#ifndef PALUDIS_GUARD_PALUDIS_KEYWORD_NAME_ERROR_HH
-#define PALUDIS_GUARD_PALUDIS_KEYWORD_NAME_ERROR_HH 1
-
-#include <paludis/name_error.hh>
-#include <string>
-
-/** \file
- * Declarations for KeywordNameError.
- *
- * \ingroup Environment
- * \ingroup Exception
- */
-
-namespace paludis
-{
- /**
- * A KeywordNameError is thrown if an invalid value is assigned to
- * a KeywordNameName.
- *
- * \ingroup Environment
- * \ingroup Exception
- */
- class KeywordNameError : public NameError
- {
- public:
- /**
- * Constructor.
- */
- KeywordNameError(const std::string & name) throw ();
- };
-}
-
-
-
-#endif
diff --git a/paludis/keyword_name_validator.cc b/paludis/keyword_name_validator.cc
deleted file mode 100644
index e65632c..0000000
--- a/paludis/keyword_name_validator.cc
+++ /dev/null
@@ -1,63 +0,0 @@
-/* vim: set sw=4 sts=4 et foldmethod=syntax : */
-
-/*
- * Copyright (c) 2006 Ciaran McCreesh <ciaranm@gentoo.org>
- *
- * This file is part of the Paludis package manager. Paludis is free software;
- * you can redistribute it and/or modify it under the terms of the GNU General
- * Public License version 2, as published by the Free Software Foundation.
- *
- * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
- * details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
- * Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#include "keyword_name_validator.hh"
-#include "keyword_name_error.hh"
-
-using namespace paludis;
-
-void
-KeywordNameValidator::validate(const std::string & s)
-{
- static const std::string allowed_chars(
- "abcdefghijklmnopqrstuvwxyz"
- "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
- "0123456789-+_");
-
- do
- {
- switch (s.length())
- {
- case 0:
- continue;
-
- case 1:
- if ("*" == s)
- return;
- continue;
-
- case 2:
- if ("-*" == s)
- return;
-
- /* fall throuth */
- default:
- if (std::string::npos != s.find_first_not_of(allowed_chars,
- ('~' == s.at(0) ? 1 : 0)))
- continue;
- }
-
- return;
-
- } while (false);
-
- Context c("When validating keyword name '" + s + "':");
- throw KeywordNameError(s);
-}
-
diff --git a/paludis/keyword_name_validator.hh b/paludis/keyword_name_validator.hh
deleted file mode 100644
index b956aa8..0000000
--- a/paludis/keyword_name_validator.hh
+++ /dev/null
@@ -1,51 +0,0 @@
-/* vim: set sw=4 sts=4 et foldmethod=syntax : */
-
-/*
- * Copyright (c) 2006 Ciaran McCreesh <ciaranm@gentoo.org>
- *
- * This file is part of the Paludis package manager. Paludis is free software;
- * you can redistribute it and/or modify it under the terms of the GNU General
- * Public License version 2, as published by the Free Software Foundation.
- *
- * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
- * details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
- * Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#ifndef PALUDIS_GUARD_PALUDIS_KEYWORD_NAME_VALIDATOR_HH
-#define PALUDIS_GUARD_PALUDIS_KEYWORD_NAME_VALIDATOR_HH 1
-
-#include <paludis/instantiation_policy.hh>
-#include <string>
-
-/** \file
- * Declarations for the KeywordNameValidator class.
- *
- * \ingroup Environment
- */
-
-namespace paludis
-{
- /**
- * A KeywordNameValidator handles validation rules for the value of a
- * UseFlagName.
- *
- * \ingroup Environment
- */
- struct KeywordNameValidator :
- private InstantiationPolicy<KeywordNameValidator, instantiation_method::NonInstantiableTag>
- {
- /**
- * If the parameter is not a valid value for a KeywordName,
- * throw a KeywordNameError.
- */
- static void validate(const std::string &);
- };
-}
-
-#endif