aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-01-21 18:20:23 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-01-21 18:20:23 +0000
commit5710bbe9feb9f0d998cee3cdf64ab9293f4842f7 (patch)
tree943ab7353d22517bd48f7ea37aae851e8c0faacc
parent046afbcd3aa18ba6b7546bed5de1686b9a1513ae (diff)
downloadpaludis-5710bbe9feb9f0d998cee3cdf64ab9293f4842f7.tar.gz
paludis-5710bbe9feb9f0d998cee3cdf64ab9293f4842f7.tar.xz
Merge package_name_validator, package_name_error into package_name. Separate files are overkill here.
-rw-r--r--paludis/files.m42
-rw-r--r--paludis/package_name_part.cc50
-rw-r--r--paludis/package_name_part.hh38
-rw-r--r--paludis/package_name_part_TEST.cc1
-rw-r--r--paludis/package_name_part_error.cc28
-rw-r--r--paludis/package_name_part_error.hh52
-rw-r--r--paludis/package_name_part_validator.cc67
-rw-r--r--paludis/package_name_part_validator.hh51
8 files changed, 86 insertions, 203 deletions
diff --git a/paludis/files.m4 b/paludis/files.m4
index 609d365..f2caa3a 100644
--- a/paludis/files.m4
+++ b/paludis/files.m4
@@ -84,8 +84,6 @@ add(`package_database_lookup_error', `hh', `cc')
add(`package_dep_atom', `hh', `cc')
add(`package_name_part', `hh', `cc', `test')
add(`package_name_part_collection', `hh', `cc')
-add(`package_name_part_error', `hh', `cc')
-add(`package_name_part_validator', `hh', `cc')
add(`paludis', `hh', `cc')
add(`portage_repository', `hh', `cc')
add(`private_implementation_pattern', `hh', `cc')
diff --git a/paludis/package_name_part.cc b/paludis/package_name_part.cc
index 3268283..7e7131f 100644
--- a/paludis/package_name_part.cc
+++ b/paludis/package_name_part.cc
@@ -19,3 +19,53 @@
#include "package_name_part.hh"
+using namespace paludis;
+
+PackageNamePartError::PackageNamePartError(const std::string & name) throw () :
+ NameError(name, "package name part")
+{
+}
+
+void
+PackageNamePartValidator::validate(const std::string & s)
+{
+ /* this gets called a lot, make it fast */
+
+ static const std::string allowed_chars(
+ "abcdefghijklmnopqrstuvwxyz"
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+ "0123456789-+_");
+
+ static const std::string number_chars(
+ "0123456789");
+
+ if (s.empty())
+ {
+ Context c("When validating package name part '" + s + "':");
+ throw PackageNamePartError(s);
+ }
+
+ /* we don't allow - followed by only numbers, because it could be
+ * a version spec. */
+ for (std::string::size_type p(0) ; p < s.length() ; ++p)
+ {
+ if (std::string::npos == allowed_chars.find(s[p]))
+ {
+ Context c("When validating package name part '" + s + "':");
+ throw PackageNamePartError(s);
+ }
+
+ if ('-' != s[p])
+ continue;
+ if (++p >= s.length())
+ break;
+ if ((std::string::npos != number_chars.find(s[p]) &&
+ std::string::npos == s.find_first_not_of(number_chars, p)) ||
+ (std::string::npos == allowed_chars.find(s[p])))
+ {
+ Context c("When validating package name part '" + s + "':");
+ throw PackageNamePartError(s);
+ }
+ }
+}
+
diff --git a/paludis/package_name_part.hh b/paludis/package_name_part.hh
index 9d4a13b..941ff8f 100644
--- a/paludis/package_name_part.hh
+++ b/paludis/package_name_part.hh
@@ -21,18 +21,52 @@
#define PALUDIS_GUARD_PALUDIS_PACKAGE_NAME_PART_HH 1
#include <paludis/validated.hh>
-#include <paludis/package_name_part_validator.hh>
+#include <paludis/name_error.hh>
+#include <paludis/private_implementation_pattern.hh>
#include <string>
/** \file
- * Declarations for the PackageNamePart class.
+ * Declarations for PackageNamePart and related classes.
*
* \ingroup Database
+ * \ingroup Exception
*/
namespace paludis
{
/**
+ * A PackageNamePartError is thrown if an invalid value is assigned to
+ * a PackageNamePart.
+ *
+ * \ingroup Database
+ * \ingroup Exception
+ */
+ class PackageNamePartError : public NameError
+ {
+ public:
+ /**
+ * Constructor.
+ */
+ PackageNamePartError(const std::string & name) throw ();
+ };
+
+ /**
+ * A PackageNamePartValidator handles validation rules for the value
+ * of a PackageNamePart.
+ *
+ * \ingroup Database
+ */
+ struct PackageNamePartValidator :
+ private InstantiationPolicy<PackageNamePartValidator, instantiation_method::NonInstantiableTag>
+ {
+ /**
+ * If the parameter is not a valid value for a PackageNamePart,
+ * throw a PackageNamePartError.
+ */
+ static void validate(const std::string &);
+ };
+
+ /**
* A PackageNamePart holds a std::string that is a valid name for the
* category part of a QualifiedPackageName.
*
diff --git a/paludis/package_name_part_TEST.cc b/paludis/package_name_part_TEST.cc
index fc0890f..f771703 100644
--- a/paludis/package_name_part_TEST.cc
+++ b/paludis/package_name_part_TEST.cc
@@ -18,7 +18,6 @@
*/
#include "package_name_part.hh"
-#include "package_name_part_error.hh"
#include <test/test_framework.hh>
#include <test/test_runner.hh>
#include <string>
diff --git a/paludis/package_name_part_error.cc b/paludis/package_name_part_error.cc
deleted file mode 100644
index f0771cf..0000000
--- a/paludis/package_name_part_error.cc
+++ /dev/null
@@ -1,28 +0,0 @@
-/* vim: set sw=4 sts=4 et foldmethod=syntax : */
-
-/*
- * Copyright (c) 2005, 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 "package_name_part_error.hh"
-
-using namespace paludis;
-
-PackageNamePartError::PackageNamePartError(const std::string & name) throw () :
- NameError(name, "package name part")
-{
-}
-
diff --git a/paludis/package_name_part_error.hh b/paludis/package_name_part_error.hh
deleted file mode 100644
index 29ec9ba..0000000
--- a/paludis/package_name_part_error.hh
+++ /dev/null
@@ -1,52 +0,0 @@
-/* vim: set sw=4 sts=4 et foldmethod=syntax : */
-
-/*
- * Copyright (c) 2005, 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_PACKAGE_NAME_PART_ERROR_HH
-#define PALUDIS_GUARD_PALUDIS_PACKAGE_NAME_PART_ERROR_HH 1
-
-#include <paludis/name_error.hh>
-#include <string>
-
-/** \file
- * Declarations for PackageNamePartError.
- *
- * \ingroup Database
- * \ingroup Exception
- */
-
-namespace paludis
-{
- /**
- * A PackageNamePartError is thrown if an invalid value is assigned to
- * a PackageNamePart.
- *
- * \ingroup Database
- * \ingroup Exception
- */
- class PackageNamePartError : public NameError
- {
- public:
- /**
- * Constructor.
- */
- PackageNamePartError(const std::string & name) throw ();
- };
-}
-
-#endif
diff --git a/paludis/package_name_part_validator.cc b/paludis/package_name_part_validator.cc
deleted file mode 100644
index 5bbc124..0000000
--- a/paludis/package_name_part_validator.cc
+++ /dev/null
@@ -1,67 +0,0 @@
-/* vim: set sw=4 sts=4 et foldmethod=syntax : */
-
-/*
- * Copyright (c) 2005, 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 "package_name_part_validator.hh"
-#include "package_name_part_error.hh"
-
-using namespace paludis;
-
-void
-PackageNamePartValidator::validate(const std::string & s)
-{
- /* this gets called a lot, make it fast */
-
- static const std::string allowed_chars(
- "abcdefghijklmnopqrstuvwxyz"
- "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
- "0123456789-+_");
-
- static const std::string number_chars(
- "0123456789");
-
- if (s.empty())
- {
- Context c("When validating package name part '" + s + "':");
- throw PackageNamePartError(s);
- }
-
- /* we don't allow - followed by only numbers, because it could be
- * a version spec. */
- for (std::string::size_type p(0) ; p < s.length() ; ++p)
- {
- if (std::string::npos == allowed_chars.find(s[p]))
- {
- Context c("When validating package name part '" + s + "':");
- throw PackageNamePartError(s);
- }
-
- if ('-' != s[p])
- continue;
- if (++p >= s.length())
- break;
- if ((std::string::npos != number_chars.find(s[p]) &&
- std::string::npos == s.find_first_not_of(number_chars, p)) ||
- (std::string::npos == allowed_chars.find(s[p])))
- {
- Context c("When validating package name part '" + s + "':");
- throw PackageNamePartError(s);
- }
- }
-}
-
diff --git a/paludis/package_name_part_validator.hh b/paludis/package_name_part_validator.hh
deleted file mode 100644
index 7b72b17..0000000
--- a/paludis/package_name_part_validator.hh
+++ /dev/null
@@ -1,51 +0,0 @@
-/* vim: set sw=4 sts=4 et foldmethod=syntax : */
-
-/*
- * Copyright (c) 2005, 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_PACKAGE_NAME_PART_VALIDATOR_HH
-#define PALUDIS_GUARD_PALUDIS_PACKAGE_NAME_PART_VALIDATOR_HH 1
-
-#include <string>
-#include <paludis/instantiation_policy.hh>
-
-/** \file
- * Declarations for the PackageNamePartValidator class.
- *
- * \ingroup Database
- */
-
-namespace paludis
-{
- /**
- * A PackageNamePartValidator handles validation rules for the value
- * of a PackageNamePart.
- *
- * \ingroup Database
- */
- struct PackageNamePartValidator :
- private InstantiationPolicy<PackageNamePartValidator, instantiation_method::NonInstantiableTag>
- {
- /**
- * If the parameter is not a valid value for a PackageNamePart,
- * throw a PackageNamePartError.
- */
- static void validate(const std::string &);
- };
-}
-
-#endif