public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
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: Wed, 27 Apr 2011 15:11:10 +0000 (UTC)	[thread overview]
Message-ID: <8b62986248d9d7aa758f2b0e4d6b2a0a65a83987.betelgeuse@gentoo> (raw)

commit:     8b62986248d9d7aa758f2b0e4d6b2a0a65a83987
Author:     Mu Qiao <qiaomuf <AT> gentoo <DOT> org>
AuthorDate: Fri Apr 22 07:29:13 2011 +0000
Commit:     Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Fri Apr 22 07:33:30 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/libbash.git;a=commit;h=8b629862

Core: fix bug in word splitting

Word splitting wouldn't trim leading and trailing IFS characters.
Now it's fixed.

---
 src/core/interpreter.cpp            |    8 +++++++-
 src/core/tests/interpreter_test.cpp |   14 ++++++++++++++
 2 files changed, 21 insertions(+), 1 deletions(-)

diff --git a/src/core/interpreter.cpp b/src/core/interpreter.cpp
index f7e8f64..58b1495 100644
--- a/src/core/interpreter.cpp
+++ b/src/core/interpreter.cpp
@@ -69,7 +69,13 @@ void interpreter::get_all_elements_IFS_joined(const std::string& name,
 void interpreter::split_word(const std::string& word, std::vector<std::string>& output)
 {
   const std::string& delimeter = resolve<std::string>("IFS");
-  boost::split(output, word, boost::is_any_of(delimeter), boost::token_compress_on);
+  std::string trimmed(word);
+  boost::trim_if(trimmed, boost::is_any_of(delimeter));
+
+  if(trimmed == "")
+    return;
+
+  boost::split(output, trimmed, boost::is_any_of(delimeter), boost::token_compress_on);
 }
 
 inline void define_function_arguments(std::unique_ptr<scope>& current_stack,

diff --git a/src/core/tests/interpreter_test.cpp b/src/core/tests/interpreter_test.cpp
index ce9d4ad..2e92a22 100644
--- a/src/core/tests/interpreter_test.cpp
+++ b/src/core/tests/interpreter_test.cpp
@@ -147,3 +147,17 @@ TEST(interperter, substring_expansion_exception)
   interpreter walker;
   EXPECT_THROW(walker.do_substring_expansion("", 0, -1, 0), interpreter_exception);
 }
+
+TEST(interpreter, word_split)
+{
+  interpreter walker;
+  std::vector<std::string> splitted_values;
+  walker.split_word(" \n\t", splitted_values);
+  EXPECT_EQ(0, splitted_values.size());
+
+  splitted_values.clear();
+  walker.split_word(" \tfoo\n bar \n", splitted_values);
+  EXPECT_EQ(2, splitted_values.size());
+  EXPECT_STREQ("foo", splitted_values[0].c_str());
+  EXPECT_STREQ("bar", splitted_values[1].c_str());
+}



             reply	other threads:[~2011-04-27 15:11 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-27 15:11 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-23 14:34 Petteri Räty
2011-05-08 13:07 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=8b62986248d9d7aa758f2b0e4d6b2a0a65a83987.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