From: "Petteri Räty" <betelgeuse@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/libbash:master commit in: src/core/, src/core/tests/
Date: Mon, 23 May 2011 14:34:20 +0000 (UTC) [thread overview]
Message-ID: <784193e4e4ba9ac58630eb791757f098492bc5f7.betelgeuse@gentoo> (raw)
commit: 784193e4e4ba9ac58630eb791757f098492bc5f7
Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Sat May 21 03:34:06 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Mon May 23 15:04:45 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=784193e4
Core: refactor get_all_elements_joined to use resolve_array
The resolve_array method is changed to return false if the array
doesn't exist.
---
src/core/interpreter.cpp | 12 +++---------
src/core/interpreter.h | 5 +++--
src/core/tests/interpreter_test.cpp | 3 ++-
3 files changed, 8 insertions(+), 12 deletions(-)
diff --git a/src/core/interpreter.cpp b/src/core/interpreter.cpp
index 85b0ded..80bc8be 100644
--- a/src/core/interpreter.cpp
+++ b/src/core/interpreter.cpp
@@ -143,18 +143,12 @@ void interpreter::get_all_elements_joined(const std::string& name,
const std::string& delim,
std::string& result) const
{
- std::vector<std::string> source;
+ std::vector<std::string> array;
- auto i = members.find(name);
- if(i != members.end())
- {
- i->second->get_all_values(source);
- result = boost::algorithm::join(source, delim);
- }
+ if(resolve_array(name, array))
+ result = boost::algorithm::join(array, delim);
else
- {
result = "";
- }
}
void interpreter::get_all_elements(const std::string& name,
diff --git a/src/core/interpreter.h b/src/core/interpreter.h
index 5d9f518..aa13b4e 100644
--- a/src/core/interpreter.h
+++ b/src/core/interpreter.h
@@ -437,13 +437,14 @@ public:
/// \param variable name
/// \param[out] vector that stores all array values
template <typename T>
- void resolve_array(const std::string& name, std::vector<T>& values) const
+ bool resolve_array(const std::string& name, std::vector<T>& values) const
{
auto i = members.find(name);
if(i == members.end())
- return;
+ return false;
i->second->get_all_values(values);
+ return true;
}
/// \brief check whether the value of the variable is null, return true
diff --git a/src/core/tests/interpreter_test.cpp b/src/core/tests/interpreter_test.cpp
index 54f25b0..a5e4ff9 100644
--- a/src/core/tests/interpreter_test.cpp
+++ b/src/core/tests/interpreter_test.cpp
@@ -136,10 +136,11 @@ TEST(interpreter, get_array_values)
walker.define("array", values);
std::vector<int> array_values;
- walker.resolve_array("array", array_values);
+ EXPECT_TRUE(walker.resolve_array("array", array_values));
EXPECT_EQ(1, array_values[0]);
EXPECT_EQ(2, array_values[1]);
EXPECT_EQ(3, array_values[2]);
+ EXPECT_FALSE(walker.resolve_array("undefined", array_values));
}
TEST(interpreter, unset_values)
next reply other threads:[~2011-05-23 14:34 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-05-23 14:34 Petteri Räty [this message]
-- strict thread matches above, loose matches on Subject: below --
2011-05-27 23:03 [gentoo-commits] proj/libbash:master commit in: src/core/, src/core/tests/ Petteri Räty
2011-05-25 19:42 Petteri Räty
2011-05-23 14:34 Petteri Räty
2011-05-08 13:07 Petteri Räty
2011-04-27 15:11 Petteri Räty
2011-04-14 4:50 Petteri Räty
2011-04-14 4:50 Petteri Räty
2011-04-12 18:29 Petteri Räty
2011-04-12 18:29 Petteri Räty
2011-04-12 18:29 Petteri Räty
2011-04-06 7:43 Petteri Räty
2011-04-04 16:09 Petteri Räty
2011-04-04 15:52 Petteri Räty
2011-04-04 15:52 Petteri Räty
2011-03-30 12:48 Petteri Räty
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=784193e4e4ba9ac58630eb791757f098492bc5f7.betelgeuse@gentoo \
--to=betelgeuse@gentoo.org \
--cc=gentoo-commits@lists.gentoo.org \
--cc=gentoo-dev@lists.gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox