Browse Source

Merge pull request #2622 from chriseth/spaceInJsConsole

Fixed extra space character and extended bracket detection.
cl-refactor
Gav Wood 10 years ago
parent
commit
7e2d65c239
  1. 18
      libjsconsole/JSConsole.h

18
libjsconsole/JSConsole.h

@ -58,8 +58,7 @@ public:
std::string rl; std::string rl;
#if ETH_READLINE #if ETH_READLINE
char* buff = readline(promptForIndentionLevel(openBrackets).c_str()); char* buff = readline(promptForIndentionLevel(openBrackets).c_str());
isEmpty = !buff; if (buff)
if (!isEmpty)
{ {
rl = std::string(buff); rl = std::string(buff);
free(buff); free(buff);
@ -67,16 +66,19 @@ public:
#else #else
std::cout << promptForIndentionLevel(openBrackets) << std::flush; std::cout << promptForIndentionLevel(openBrackets) << std::flush;
std::getline(std::cin, rl); std::getline(std::cin, rl);
isEmpty = rl.length() == 0;
#endif #endif
isEmpty = rl.empty();
//@todo this should eventually check the structure of the input, since unmatched
// brackets in strings will fail to execute the input now.
if (!isEmpty) if (!isEmpty)
{ {
cmd += rl; cmd += rl;
cmd += " "; int open = 0;
int open = std::count(cmd.begin(), cmd.end(), '{'); for (char c: {'{', '[', '('})
open += std::count(cmd.begin(), cmd.end(), '('); open += std::count(cmd.begin(), cmd.end(), c);
int closed = std::count(cmd.begin(), cmd.end(), '}'); int closed = 0;
closed += std::count(cmd.begin(), cmd.end(), ')'); for (char c: {'}', ']', ')'})
closed += std::count(cmd.begin(), cmd.end(), c);
openBrackets = open - closed; openBrackets = open - closed;
} }
} while (openBrackets > 0); } while (openBrackets > 0);

Loading…
Cancel
Save