From 86acd63036d059a4c7b89cf01ae49ad169cb04e0 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Wed, 22 Apr 2015 11:35:52 -0700 Subject: 1124 --- cpp/001test | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'cpp/001test') diff --git a/cpp/001test b/cpp/001test index 12352de1..8c4bc5e3 100644 --- a/cpp/001test +++ b/cpp/001test @@ -48,7 +48,7 @@ if (argc == 2 && is_equal(argv[1], "test")) { return 0; } // pass in a set of line numbers in test_file to run just those tests -if (argc > 2 && is_equal(argv[1], "test")) { +if (argc > 2 && is_equal(argv[1], "test") && is_number(argv[2])) { for (int i = 2; i < argc; ++i) { run_test(to_int(argv[i])-1); } @@ -87,6 +87,10 @@ bool is_equal(char* s, const char* lit) { return strncmp(s, lit, strlen(lit)) == 0; } +bool is_number(const string& s) { + return s.find_first_not_of("0123456789-.") == string::npos; +} + int to_int(string n) { char* end = NULL; int result = strtol(n.c_str(), &end, /*any base*/0); -- cgit 1.4.1-2-gfad0