diff options
author | 2014-10-11 16:50:16 -0700 | |
---|---|---|
committer | 2014-10-11 16:50:16 -0700 | |
commit | fbade198b942a666d3fc1110804a7da2c47918f1 (patch) | |
tree | 6f56426f78f34b15b937c862c54fac5b2091ba2a /expand.cpp | |
parent | d982f2a5752428b437c204a777aa1830bd50ee77 (diff) |
Support space separators for abbreviations as part of #731
Diffstat (limited to 'expand.cpp')
-rw-r--r-- | expand.cpp | 12 |
1 files changed, 7 insertions, 5 deletions
@@ -2107,13 +2107,15 @@ bool expand_abbreviation(const wcstring &src, wcstring *output) wcstokenizer tokenizer(var, ARRAY_SEP_STR); while (tokenizer.next(line)) { - /* Line is expected to be of the form 'foo=bar'. Parse out the first =. Be forgiving about spaces, but silently skip on failure (no equals, or equals at the end or beginning). Try to avoid copying any strings until we are sure this is a match. */ - size_t equals = line.find(L'='); - if (equals == wcstring::npos || equals == 0 || equals + 1 == line.size()) + /* Line is expected to be of the form 'foo=bar' or 'foo bar'. Parse out the first = or space. Silently skip on failure (no equals, or equals at the end or beginning). Try to avoid copying any strings until we are sure this is a match. */ + size_t equals_pos = line.find(L'='); + size_t space_pos = line.find(L' '); + size_t separator = mini(equals_pos, space_pos); + if (separator == wcstring::npos || separator == 0 || separator + 1 == line.size()) continue; /* Find the character just past the end of the command. Walk backwards, skipping spaces. */ - size_t cmd_end = equals; + size_t cmd_end = separator; while (cmd_end > 0 && iswspace(line.at(cmd_end - 1))) cmd_end--; @@ -2122,7 +2124,7 @@ bool expand_abbreviation(const wcstring &src, wcstring *output) { /* Success. Set output to everythign past the end of the string. */ if (output != NULL) - output->assign(line, equals + 1, wcstring::npos); + output->assign(line, separator + 1, wcstring::npos); result = true; break; |