aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2009-03-22 20:10:26 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2009-03-22 20:10:26 +0000
commit79bb50545d75ab2ccdf4f70c7243b6eda8f671bb (patch)
tree339cb645fe43bbc9df71d0d230bd1fb3cb38d218
parentc553862e41331e4504a5309144dae179ca4449bb (diff)
downloadpaludis-79bb50545d75ab2ccdf4f70c7243b6eda8f671bb.tar.gz
paludis-79bb50545d75ab2ccdf4f70c7243b6eda8f671bb.tar.xz
Make vso_ignore_case work
-rw-r--r--.gitignore1
-rw-r--r--paludis/elike_package_dep_spec.cc4
-rw-r--r--paludis/util/files.m42
-rw-r--r--paludis/util/simple_parser.cc25
-rw-r--r--paludis/util/simple_parser.hh5
-rw-r--r--paludis/util/simple_parser_TEST.cc50
-rw-r--r--paludis/version_spec.cc45
-rw-r--r--paludis/version_spec_TEST.cc26
8 files changed, 138 insertions, 20 deletions
diff --git a/.gitignore b/.gitignore
index d024910..52c523e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -385,6 +385,7 @@ paludis-*.*.*.tar.bz2
/paludis/util/save_TEST
/paludis/util/sha1_TEST
/paludis/util/sha256_TEST
+/paludis/util/simple_parser_TEST
/paludis/util/stringify_TEST
/paludis/util/strip_TEST
/paludis/util/system_TEST
diff --git a/paludis/elike_package_dep_spec.cc b/paludis/elike_package_dep_spec.cc
index ab95c43..1065d38 100644
--- a/paludis/elike_package_dep_spec.cc
+++ b/paludis/elike_package_dep_spec.cc
@@ -28,6 +28,7 @@
#include <paludis/version_operator.hh>
#include <paludis/version_spec.hh>
#include <paludis/version_requirements.hh>
+#include <strings.h>
using namespace paludis;
@@ -375,7 +376,8 @@ paludis::elike_get_remove_trailing_version(std::string & s, const VersionSpecOpt
/* can't have an -scm before this */
break;
}
- else if (0 == s.compare(hyphen_pos + 1, 3, "scm"))
+ else if (0 == s.compare(hyphen_pos + 1, 3, "scm") ||
+ (version_options[vso_ignore_case] && 0 == strncasecmp(s.c_str() + hyphen_pos + 1, "scm", 3)))
{
if (std::string::npos == last_hyphen_pos)
{
diff --git a/paludis/util/files.m4 b/paludis/util/files.m4
index 23d58fa..0f0c56a 100644
--- a/paludis/util/files.m4
+++ b/paludis/util/files.m4
@@ -62,7 +62,7 @@ add(`sequence', `hh', `fwd', `impl', `cc')
add(`set', `hh', `fwd', `impl', `cc')
add(`sha1', `hh', `cc', `test')
add(`sha256', `hh', `cc', `test')
-add(`simple_parser', `hh', `cc')
+add(`simple_parser', `hh', `cc', `test')
add(`simple_visitor', `hh', `cc', `fwd', `impl')
add(`simple_visitor_cast', `hh', `cc', `fwd')
add(`stringify', `hh', `test')
diff --git a/paludis/util/simple_parser.cc b/paludis/util/simple_parser.cc
index ba2bded..2232248 100644
--- a/paludis/util/simple_parser.cc
+++ b/paludis/util/simple_parser.cc
@@ -1,7 +1,7 @@
/* vim: set sw=4 sts=4 et foldmethod=syntax : */
/*
- * Copyright (c) 2008 Ciaran McCreesh
+ * Copyright (c) 2008, 2009 Ciaran McCreesh
*
* 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
@@ -19,6 +19,7 @@
#include <paludis/util/simple_parser.hh>
#include <paludis/util/private_implementation_pattern-impl.hh>
+#include <strings.h>
using namespace paludis;
using namespace paludis::simple_parser;
@@ -108,14 +109,23 @@ namespace
return std::string::npos == len_1 ? 0 : len_1;
}
+ int compare_ignoring_case(const std::string & text, const std::string::size_type offset, const std::string::size_type length,
+ const std::string & pattern)
+ {
+ return strncasecmp(text.c_str() + offset, pattern.c_str(), length);
+ }
+
std::string::size_type
m_exact(const std::string & pattern, const std::string & text,
- const std::string::size_type offset)
+ const std::string::size_type offset, const bool ignore_case)
{
if (offset >= text.length())
return std::string::npos;
- return (0 == text.compare(offset, pattern.length(), pattern)) ? pattern.length() : std::string::npos;
+ if (! ignore_case)
+ return (0 == text.compare(offset, pattern.length(), pattern)) ? pattern.length() : std::string::npos;
+ else
+ return (0 == compare_ignoring_case(text, offset, pattern.length(), pattern)) ? pattern.length() : std::string::npos;
}
std::string::size_type
@@ -184,7 +194,14 @@ SimpleParserExpression
paludis::simple_parser::exact(const std::string & s)
{
using namespace std::tr1::placeholders;
- return SimpleParserExpression(std::tr1::bind(m_exact, s, _1, _2));
+ return SimpleParserExpression(std::tr1::bind(m_exact, s, _1, _2, false));
+}
+
+SimpleParserExpression
+paludis::simple_parser::exact_ignoring_case(const std::string & s)
+{
+ using namespace std::tr1::placeholders;
+ return SimpleParserExpression(std::tr1::bind(m_exact, s, _1, _2, true));
}
SimpleParserExpression
diff --git a/paludis/util/simple_parser.hh b/paludis/util/simple_parser.hh
index 9dbf214..1302269 100644
--- a/paludis/util/simple_parser.hh
+++ b/paludis/util/simple_parser.hh
@@ -1,7 +1,7 @@
/* vim: set sw=4 sts=4 et foldmethod=syntax : */
/*
- * Copyright (c) 2008 Ciaran McCreesh
+ * Copyright (c) 2008, 2009 Ciaran McCreesh
*
* 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
@@ -61,6 +61,9 @@ namespace paludis
SimpleParserExpression exact(const std::string &)
PALUDIS_VISIBLE PALUDIS_ATTRIBUTE((warn_unused_result));
+ SimpleParserExpression exact_ignoring_case(const std::string &)
+ PALUDIS_VISIBLE PALUDIS_ATTRIBUTE((warn_unused_result));
+
SimpleParserExpression any_of(const std::string &)
PALUDIS_VISIBLE PALUDIS_ATTRIBUTE((warn_unused_result));
diff --git a/paludis/util/simple_parser_TEST.cc b/paludis/util/simple_parser_TEST.cc
new file mode 100644
index 0000000..e6d285a
--- /dev/null
+++ b/paludis/util/simple_parser_TEST.cc
@@ -0,0 +1,50 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2009 Ciaran McCreesh
+ *
+ * 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 <paludis/util/simple_parser.hh>
+#include <test/test_runner.hh>
+#include <test/test_framework.hh>
+#include <test/test_concepts.hh>
+
+using namespace paludis;
+using namespace test;
+
+namespace test_cases
+{
+ struct TestSimpleParserIgnoreCase : TestCase
+ {
+ TestSimpleParserIgnoreCase() : TestCase("ignore case") { }
+
+ void run()
+ {
+ std::string text("oneTWOthree"), one, two, three;
+ SimpleParser parser(text);
+ TEST_CHECK(parser.consume(simple_parser::exact("one") >> one));
+ TEST_CHECK(parser.consume(simple_parser::exact_ignoring_case("two") >> two));
+ TEST_CHECK(! parser.consume(simple_parser::exact("THREE") >> three));
+ TEST_CHECK(parser.consume(simple_parser::exact_ignoring_case("THREE") >> three));
+
+ TEST_CHECK(parser.eof());
+ TEST_CHECK_EQUAL(one, "one");
+ TEST_CHECK_EQUAL(two, "TWO");
+ TEST_CHECK_EQUAL(three, "three");
+ }
+ } test_ignore_case;
+}
+
diff --git a/paludis/version_spec.cc b/paludis/version_spec.cc
index 212d797..c5effc1 100644
--- a/paludis/version_spec.cc
+++ b/paludis/version_spec.cc
@@ -90,12 +90,15 @@ VersionSpec::VersionSpec(const std::string & text, const VersionSpecOptions & op
/* parse */
SimpleParser parser(text);
- if (parser.consume(simple_parser::exact("scm")))
+ std::string scm_str;
+ if (parser.consume((options[vso_ignore_case] ? simple_parser::exact_ignoring_case("scm") : simple_parser::exact("scm")) >> scm_str))
+ {
_imp->parts.push_back(make_named_values<VersionSpecComponent>(
value_for<n::number_value>(""),
- value_for<n::text>("scm"),
+ value_for<n::text>(scm_str),
value_for<n::type>(vsct_scm)
));
+ }
else
{
/* numbers... */
@@ -126,21 +129,32 @@ VersionSpec::VersionSpec(const std::string & text, const VersionSpecOptions & op
value_for<n::text>(l),
value_for<n::type>(vsct_letter)
));
+ else if (options[vso_ignore_case] && parser.consume(simple_parser::any_of("ABCDEFGHIJKLMNOPQRSTUVWXYZ") >> l))
+ _imp->parts.push_back(make_named_values<VersionSpecComponent>(
+ value_for<n::number_value>(std::string(1, std::tolower(l.at(0)))),
+ value_for<n::text>(l),
+ value_for<n::type>(vsct_letter)
+ ));
}
while (true)
{
std::string suffix_str, number_str;
VersionSpecComponentType k(vsct_empty);
- if (parser.consume(simple_parser::exact("_alpha") >> suffix_str))
+ if (parser.consume((options[vso_ignore_case] ?
+ simple_parser::exact_ignoring_case("_alpha") : simple_parser::exact("_alpha")) >> suffix_str))
k = vsct_alpha;
- else if (parser.consume(simple_parser::exact("_beta") >> suffix_str))
+ else if (parser.consume((options[vso_ignore_case] ?
+ simple_parser::exact_ignoring_case("_beta") : simple_parser::exact("_beta")) >> suffix_str))
k = vsct_beta;
- else if (parser.consume(simple_parser::exact("_pre") >> suffix_str))
+ else if (parser.consume((options[vso_ignore_case] ?
+ simple_parser::exact_ignoring_case("_pre") : simple_parser::exact("_pre")) >> suffix_str))
k = vsct_pre;
- else if (parser.consume(simple_parser::exact("_rc") >> suffix_str))
+ else if (parser.consume((options[vso_ignore_case] ?
+ simple_parser::exact_ignoring_case("_rc") : simple_parser::exact("_rc")) >> suffix_str))
k = vsct_rc;
- else if (parser.consume(simple_parser::exact("_p") >> suffix_str))
+ else if (parser.consume((options[vso_ignore_case] ?
+ simple_parser::exact_ignoring_case("_p") : simple_parser::exact("_p")) >> suffix_str))
k = vsct_patch;
else
break;
@@ -164,13 +178,15 @@ VersionSpec::VersionSpec(const std::string & text, const VersionSpecOptions & op
}
/* try */
- if (parser.consume(simple_parser::exact("-try")))
+ std::string try_str;
+ if (parser.consume((options[vso_ignore_case] ?
+ simple_parser::exact_ignoring_case("-try") : simple_parser::exact("-try")) >> try_str))
{
std::string number_str;
if (! parser.consume(*simple_parser::any_of("0123456789") >> number_str))
throw BadVersionSpecError(text, "Expected optional number at offset " + stringify(parser.offset()));
- std::string raw_text("-try" + number_str);
+ std::string raw_text(try_str + number_str);
if (number_str.size() > 0)
{
number_str = strip_leading(number_str, "0");
@@ -185,7 +201,8 @@ VersionSpec::VersionSpec(const std::string & text, const VersionSpecOptions & op
}
/* scm */
- if (parser.consume(simple_parser::exact("-scm")))
+ if (parser.consume((options[vso_ignore_case] ?
+ simple_parser::exact_ignoring_case("-scm") : simple_parser::exact("-scm")) >> scm_str))
{
/* _suffix-scm? */
if (_imp->parts.back().number_value().empty())
@@ -193,7 +210,7 @@ VersionSpec::VersionSpec(const std::string & text, const VersionSpecOptions & op
_imp->parts.push_back(make_named_values<VersionSpecComponent>(
value_for<n::number_value>(""),
- value_for<n::text>("-scm"),
+ value_for<n::text>(scm_str),
value_for<n::type>(vsct_scm)
));
}
@@ -206,7 +223,9 @@ VersionSpec::VersionSpec(const std::string & text, const VersionSpecOptions & op
}
/* revision */
- if (parser.consume(simple_parser::exact("-r")))
+ std::string rev_str;
+ if (parser.consume((options[vso_ignore_case] ?
+ simple_parser::exact_ignoring_case("-r") : simple_parser::exact("-r")) >> rev_str))
{
bool first_revision(true);
do
@@ -218,7 +237,7 @@ VersionSpec::VersionSpec(const std::string & text, const VersionSpecOptions & op
/* Are we -r */
bool empty(number_str.empty());
- std::string raw_text(first_revision ? "-r" : ".");
+ std::string raw_text(first_revision ? rev_str : ".");
raw_text.append(number_str);
number_str = strip_leading(number_str, "0");
diff --git a/paludis/version_spec_TEST.cc b/paludis/version_spec_TEST.cc
index 686024d..78851c0 100644
--- a/paludis/version_spec_TEST.cc
+++ b/paludis/version_spec_TEST.cc
@@ -562,5 +562,31 @@ namespace test_cases
++i;
}
} test_version_spec_components;
+
+ struct VersionSpecIgnoreCaseTest : TestCase
+ {
+ VersionSpecIgnoreCaseTest() : TestCase("ignore case") { }
+
+ void run()
+ {
+ TEST_CHECK_THROWS(VersionSpec("1.2A", VersionSpecOptions()), BadVersionSpecError);
+ VersionSpec v1("1.2A", VersionSpecOptions() + vso_ignore_case);
+ VersionSpec v2("1.2a", VersionSpecOptions());
+ TEST_CHECK(v1 == v2);
+ TEST_CHECK(v1.hash() == v2.hash());
+
+ TEST_CHECK_THROWS(VersionSpec("1_ALPHA3", VersionSpecOptions()), BadVersionSpecError);
+ VersionSpec v3("1_ALPHA3", VersionSpecOptions() + vso_ignore_case);
+ VersionSpec v4("1_alpha3", VersionSpecOptions());
+ TEST_CHECK(v3 == v4);
+ TEST_CHECK(v3.hash() == v4.hash());
+
+ TEST_CHECK_THROWS(VersionSpec("SCM", VersionSpecOptions()), BadVersionSpecError);
+ VersionSpec v5("SCM", VersionSpecOptions() + vso_ignore_case);
+ VersionSpec v6("scm", VersionSpecOptions());
+ TEST_CHECK(v5 == v6);
+ TEST_CHECK(v5.hash() == v6.hash());
+ }
+ } test_version_spec_ignore_case;
}