fixes: 1. do not skip over first non-empty line; 2. skip over all empty lines
This commit is contained in:
		
							parent
							
								
									ff01cf3a3c
								
							
						
					
					
						commit
						eebcddb472
					
				@ -24,6 +24,7 @@ struct semicolon_is_space : std::ctype<char> {
 | 
				
			|||||||
    return &rc[0];
 | 
					    return &rc[0];
 | 
				
			||||||
  };
 | 
					  };
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class input {
 | 
					class input {
 | 
				
			||||||
public:
 | 
					public:
 | 
				
			||||||
  std::string s;
 | 
					  std::string s;
 | 
				
			||||||
@ -33,9 +34,7 @@ public:
 | 
				
			|||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
std::istream &operator>>(std::istream &in, input &i) {
 | 
					std::istream &operator>>(std::istream &in, input &i) {
 | 
				
			||||||
  std::getline(in, i.s, '\n'); // An inelegant hack to skip newline character
 | 
					  in >> i.s >> i.k;
 | 
				
			||||||
  std::getline(in, i.s, ';');
 | 
					 | 
				
			||||||
  in >> i.k;
 | 
					 | 
				
			||||||
  return in;
 | 
					  return in;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -128,10 +127,10 @@ int main(int argc, char *argv[]) {
 | 
				
			|||||||
  std::vector<test_case> test_cases;
 | 
					  std::vector<test_case> test_cases;
 | 
				
			||||||
  semicolon_is_space delimeter;
 | 
					  semicolon_is_space delimeter;
 | 
				
			||||||
  for (int i = 1; i < argc; i++) {
 | 
					  for (int i = 1; i < argc; i++) {
 | 
				
			||||||
    test_case t;
 | 
					 | 
				
			||||||
    std::ifstream f(argv[i]);
 | 
					    std::ifstream f(argv[i]);
 | 
				
			||||||
    f.imbue(std::locale(f.getloc(), new semicolon_is_space));
 | 
					    f.imbue(std::locale(f.getloc(), new semicolon_is_space));
 | 
				
			||||||
    while (f.good()) {
 | 
					    while (f.good()) {
 | 
				
			||||||
 | 
					      test_case t;
 | 
				
			||||||
      f >> t;
 | 
					      f >> t;
 | 
				
			||||||
      if (t.i.s.length()) { // skip empty line/string inputs
 | 
					      if (t.i.s.length()) { // skip empty line/string inputs
 | 
				
			||||||
        std::cout << t;
 | 
					        std::cout << t;
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user