OLD | NEW |
| (Empty) |
1 #include "config.h" | |
2 #include "DumpRenderTree.h" | |
3 | |
4 #include <algorithm> | |
5 #include <ctype.h> | |
6 #include <stdio.h> | |
7 #include <stdlib.h> | |
8 #include <string> | |
9 | |
10 class CommandTokenizer { | |
11 public: | |
12 explicit CommandTokenizer(const std::string& input) | |
13 : m_input(input) | |
14 , m_posNextSeparator(0) | |
15 { | |
16 pump(); | |
17 } | |
18 | |
19 bool hasNext() const; | |
20 std::string next(); | |
21 | |
22 private: | |
23 void pump(); | |
24 static const char kSeparator = '\''; | |
25 const std::string& m_input; | |
26 std::string m_next; | |
27 size_t m_posNextSeparator; | |
28 }; | |
29 | |
30 void CommandTokenizer::pump() | |
31 { | |
32 if (m_posNextSeparator == std::string::npos || m_posNextSeparator == m_input
.size()) { | |
33 m_next = std::string(); | |
34 return; | |
35 } | |
36 size_t start = m_posNextSeparator ? m_posNextSeparator + 1 : 0; | |
37 m_posNextSeparator = m_input.find(kSeparator, start); | |
38 size_t size = m_posNextSeparator == std::string::npos ? std::string::npos :
m_posNextSeparator - start; | |
39 m_next = std::string(m_input, start, size); | |
40 } | |
41 | |
42 std::string CommandTokenizer::next() | |
43 { | |
44 ASSERT(hasNext()); | |
45 | |
46 std::string oldNext = m_next; | |
47 pump(); | |
48 return oldNext; | |
49 } | |
50 | |
51 bool CommandTokenizer::hasNext() const | |
52 { | |
53 return !m_next.empty(); | |
54 } | |
55 | |
56 NO_RETURN static void die(const std::string& inputLine) | |
57 { | |
58 fprintf(stderr, "Unexpected input line: %s\n", inputLine.c_str()); | |
59 exit(1); | |
60 } | |
61 | |
62 TestCommand parseInputLine(const std::string& inputLine) | |
63 { | |
64 TestCommand result; | |
65 CommandTokenizer tokenizer(inputLine); | |
66 if (!tokenizer.hasNext()) | |
67 die(inputLine); | |
68 | |
69 std::string arg = tokenizer.next(); | |
70 result.pathOrURL = arg; | |
71 while (tokenizer.hasNext()) { | |
72 arg = tokenizer.next(); | |
73 if (arg == std::string("--timeout")) { | |
74 std::string timeoutToken = tokenizer.next(); | |
75 result.timeout = atoi(timeoutToken.c_str()); | |
76 } else if (arg == std::string("-p") || arg == std::string("--pixel-test"
)) { | |
77 result.shouldDumpPixels = true; | |
78 if (tokenizer.hasNext()) | |
79 result.expectedPixelHash = tokenizer.next(); | |
80 } else | |
81 die(inputLine); | |
82 } | |
83 | |
84 return result; | |
85 } | |
OLD | NEW |