- Renamed ::split to ::word_split, for clarity and because of the need for a
  full token split, coming next.
This commit is contained in:
Paul Beckingham 2014-05-31 13:48:52 -04:00
parent e753473dc4
commit 0af9bbdc03
5 changed files with 18 additions and 18 deletions

View file

@ -92,7 +92,7 @@ void Alias::resolve (Tree* tree)
something = true; something = true;
std::vector <std::string> words; std::vector <std::string> words;
Lexer::split (words, context.aliases[raw]); Lexer::word_split (words, context.aliases[raw]);
std::vector <std::string>::iterator word; std::vector <std::string>::iterator word;
for (word = words.begin (); word != words.end (); ++word) for (word = words.begin (); word != words.end (); ++word)

View file

@ -619,7 +619,7 @@ bool Lexer::is_ws (int c)
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Split 'input' into 'words' on Lexer::is_ws boundaries, observing quotes. // Split 'input' into 'words' on Lexer::is_ws boundaries, observing quotes.
void Lexer::split (std::vector <std::string>& words, const std::string& input) void Lexer::word_split (std::vector <std::string>& words, const std::string& input)
{ {
words.clear (); words.clear ();

View file

@ -65,7 +65,7 @@ public:
static const std::string type_name (const Type&); static const std::string type_name (const Type&);
static bool is_ws (int); static bool is_ws (int);
static void split (std::vector <std::string>&, const std::string&); static void word_split (std::vector <std::string>&, const std::string&);
private: private:
bool is_punct (int) const; bool is_punct (int) const;

View file

@ -468,7 +468,7 @@ void Parser::injectDefaults ()
// because captureFirst inserts args immediately after the command, and // because captureFirst inserts args immediately after the command, and
// so has the effect of reversing the list. // so has the effect of reversing the list.
std::vector <std::string> args; std::vector <std::string> args;
Lexer::split (args, defaultCommand); Lexer::word_split (args, defaultCommand);
std::vector <std::string>::reverse_iterator r; std::vector <std::string>::reverse_iterator r;
for (r = args.rbegin (); r != args.rend (); ++r) for (r = args.rbegin (); r != args.rend (); ++r)
{ {

View file

@ -299,25 +299,25 @@ int main (int argc, char** argv)
t.is (tokens[20].first, ")", "tokens[20] == ')'"); t.is (tokens[20].first, ")", "tokens[20] == ')'");
t.is (tokens[20].second, Lexer::typeOperator, "tokens[20] == typeOperator"); // 170 t.is (tokens[20].second, Lexer::typeOperator, "tokens[20] == typeOperator"); // 170
// void splitq (std::vector<std::string>&, const std::string&); // void word_split (std::vector<std::string>&, const std::string&);
std::string unsplit = " ( A or B ) "; std::string unsplit = " ( A or B ) ";
std::vector <std::string> items; std::vector <std::string> items;
Lexer::split (items, unsplit); Lexer::word_split (items, unsplit);
t.is (items.size (), (size_t) 5, "split ' ( A or B ) '"); t.is (items.size (), (size_t) 5, "word_split ' ( A or B ) '");
t.is (items[0], "(", "split ' ( A or B ) ' -> [0] '('"); t.is (items[0], "(", "word_split ' ( A or B ) ' -> [0] '('");
t.is (items[1], "A", "split ' ( A or B ) ' -> [1] 'A'"); t.is (items[1], "A", "word_split ' ( A or B ) ' -> [1] 'A'");
t.is (items[2], "or", "split ' ( A or B ) ' -> [2] 'or'"); t.is (items[2], "or", "word_split ' ( A or B ) ' -> [2] 'or'");
t.is (items[3], "B", "split ' ( A or B ) ' -> [3] 'B'"); t.is (items[3], "B", "word_split ' ( A or B ) ' -> [3] 'B'");
t.is (items[4], ")", "split ' ( A or B ) ' -> [4] ')'"); t.is (items[4], ")", "word_split ' ( A or B ) ' -> [4] ')'");
// Test simple mode with contrived tokens that ordinarily split. // Test simple mode with contrived tokens that ordinarily split.
unsplit = " +-* a+b 12.3e4 'c d'"; unsplit = " +-* a+b 12.3e4 'c d'";
Lexer::split (items, unsplit); Lexer::word_split (items, unsplit);
t.is (items.size (), (size_t) 4, "split ' +-* a+b 12.3e4 'c d''"); t.is (items.size (), (size_t) 4, "word_split ' +-* a+b 12.3e4 'c d''");
t.is (items[0], "+-*", "split ' +-* a+b 12.3e4 'c d'' -> [0] '+-*'"); t.is (items[0], "+-*", "word_split ' +-* a+b 12.3e4 'c d'' -> [0] '+-*'");
t.is (items[1], "a+b", "split ' +-* a+b 12.3e4 'c d'' -> [1] 'a+b'"); t.is (items[1], "a+b", "word_split ' +-* a+b 12.3e4 'c d'' -> [1] 'a+b'");
t.is (items[2], "12.3e4", "split ' +-* a+b 12.3e4 'c d'' -> [2] '12.3e4'"); t.is (items[2], "12.3e4", "word_split ' +-* a+b 12.3e4 'c d'' -> [2] '12.3e4'");
t.is (items[3], "c d", "split ' +-* a+b 12.3e4 'c d'' -> [3] 'c d'"); t.is (items[3], "c d", "word_split ' +-* a+b 12.3e4 'c d'' -> [3] 'c d'");
return 0; return 0;
} }