From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from pigeon.gentoo.org ([208.92.234.80] helo=lists.gentoo.org) by finch.gentoo.org with esmtp (Exim 4.60) (envelope-from ) id 1QOWDO-0005Kg-Up for garchives@archives.gentoo.org; Mon, 23 May 2011 14:34:40 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 292401C053; Mon, 23 May 2011 14:34:22 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id E03691C053 for ; Mon, 23 May 2011 14:34:21 +0000 (UTC) Received: from pelican.gentoo.org (unknown [66.219.59.40]) (using TLSv1 with cipher ADH-CAMELLIA256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 950DC1B4024 for ; Mon, 23 May 2011 14:34:21 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by pelican.gentoo.org (Postfix) with ESMTP id F1C8680505 for ; Mon, 23 May 2011 14:34:20 +0000 (UTC) From: "Petteri Räty" To: gentoo-commits@lists.gentoo.org Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Petteri Räty" Message-ID: <784193e4e4ba9ac58630eb791757f098492bc5f7.betelgeuse@gentoo> Subject: [gentoo-commits] proj/libbash:master commit in: src/core/, src/core/tests/ X-VCS-Repository: proj/libbash X-VCS-Files: src/core/interpreter.cpp src/core/interpreter.h src/core/tests/interpreter_test.cpp X-VCS-Directories: src/core/ src/core/tests/ X-VCS-Committer: betelgeuse X-VCS-Committer-Name: Petteri Räty X-VCS-Revision: 784193e4e4ba9ac58630eb791757f098492bc5f7 Date: Mon, 23 May 2011 14:34:20 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: quoted-printable X-Archives-Salt: X-Archives-Hash: 8806afa5ffb3196d6b2232197bf1fe4e commit: 784193e4e4ba9ac58630eb791757f098492bc5f7 Author: Mu Qiao gentoo org> AuthorDate: Sat May 21 03:34:06 2011 +0000 Commit: Petteri R=C3=A4ty gentoo org> CommitDate: Mon May 23 15:04:45 2011 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=3Dproj/libbash.git;a= =3Dcommit;h=3D784193e4 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 source; + std::vector array; =20 - auto i =3D members.find(name); - if(i !=3D members.end()) - { - i->second->get_all_values(source); - result =3D boost::algorithm::join(source, delim); - } + if(resolve_array(name, array)) + result =3D boost::algorithm::join(array, delim); else - { result =3D ""; - } } =20 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 - void resolve_array(const std::string& name, std::vector& values) co= nst + bool resolve_array(const std::string& name, std::vector& values) co= nst { auto i =3D members.find(name); if(i =3D=3D members.end()) - return; + return false; =20 i->second->get_all_values(values); + return true; } =20 /// \brief check whether the value of the variable is null, return tru= e diff --git a/src/core/tests/interpreter_test.cpp b/src/core/tests/interpr= eter_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); =20 std::vector 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)); } =20 TEST(interpreter, unset_values)