Gentoo Archives: gentoo-commits

From: "Petteri Räty" <betelgeuse@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/libbash:master commit in: src/core/, src/core/tests/
Date: Wed, 27 Apr 2011 15:11:53
Message-Id: 8b62986248d9d7aa758f2b0e4d6b2a0a65a83987.betelgeuse@gentoo
1 commit: 8b62986248d9d7aa758f2b0e4d6b2a0a65a83987
2 Author: Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
3 AuthorDate: Fri Apr 22 07:29:13 2011 +0000
4 Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
5 CommitDate: Fri Apr 22 07:33:30 2011 +0000
6 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=8b629862
7
8 Core: fix bug in word splitting
9
10 Word splitting wouldn't trim leading and trailing IFS characters.
11 Now it's fixed.
12
13 ---
14 src/core/interpreter.cpp | 8 +++++++-
15 src/core/tests/interpreter_test.cpp | 14 ++++++++++++++
16 2 files changed, 21 insertions(+), 1 deletions(-)
17
18 diff --git a/src/core/interpreter.cpp b/src/core/interpreter.cpp
19 index f7e8f64..58b1495 100644
20 --- a/src/core/interpreter.cpp
21 +++ b/src/core/interpreter.cpp
22 @@ -69,7 +69,13 @@ void interpreter::get_all_elements_IFS_joined(const std::string& name,
23 void interpreter::split_word(const std::string& word, std::vector<std::string>& output)
24 {
25 const std::string& delimeter = resolve<std::string>("IFS");
26 - boost::split(output, word, boost::is_any_of(delimeter), boost::token_compress_on);
27 + std::string trimmed(word);
28 + boost::trim_if(trimmed, boost::is_any_of(delimeter));
29 +
30 + if(trimmed == "")
31 + return;
32 +
33 + boost::split(output, trimmed, boost::is_any_of(delimeter), boost::token_compress_on);
34 }
35
36 inline void define_function_arguments(std::unique_ptr<scope>& current_stack,
37
38 diff --git a/src/core/tests/interpreter_test.cpp b/src/core/tests/interpreter_test.cpp
39 index ce9d4ad..2e92a22 100644
40 --- a/src/core/tests/interpreter_test.cpp
41 +++ b/src/core/tests/interpreter_test.cpp
42 @@ -147,3 +147,17 @@ TEST(interperter, substring_expansion_exception)
43 interpreter walker;
44 EXPECT_THROW(walker.do_substring_expansion("", 0, -1, 0), interpreter_exception);
45 }
46 +
47 +TEST(interpreter, word_split)
48 +{
49 + interpreter walker;
50 + std::vector<std::string> splitted_values;
51 + walker.split_word(" \n\t", splitted_values);
52 + EXPECT_EQ(0, splitted_values.size());
53 +
54 + splitted_values.clear();
55 + walker.split_word(" \tfoo\n bar \n", splitted_values);
56 + EXPECT_EQ(2, splitted_values.size());
57 + EXPECT_STREQ("foo", splitted_values[0].c_str());
58 + EXPECT_STREQ("bar", splitted_values[1].c_str());
59 +}