From 5e2e2eb5da2bcbb0d4e485ecc73bb9697afa1bac Mon Sep 17 00:00:00 2001 From: Kartik Agaram Date: Tue, 10 Jul 2018 20:23:14 -0700 Subject: 4337 Return to the usual whitespace-skipping istreams. No need to go beyond word-based parsing. This exercise reinforces the amount of duplication between load_program() and transform_immediate(). --- subx/022transform_immediate.cc | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) (limited to 'subx/022transform_immediate.cc') diff --git a/subx/022transform_immediate.cc b/subx/022transform_immediate.cc index eefe9a40..48f5dfa9 100644 --- a/subx/022transform_immediate.cc +++ b/subx/022transform_immediate.cc @@ -23,17 +23,29 @@ Transform.push_back(transform_immediate); :(code) void transform_immediate(const string& input, string& output) { istringstream in(input); - in >> std::noskipws; ostringstream out; while (has_data(in)) { - string word = next_word(in); - if (word.find("/imm") == string::npos) - out << word << ' '; - else { - string output = transform_immediate(word); - trace("translate") << "converting '" << word << "' to '" << output << "'" << end(); - out << output << ' '; + string line_data; + getline(in, line_data); + istringstream line(line_data); + while (has_data(line)) { + string word; + line >> word; + if (word.empty()) continue; + if (word[0] == '#') { + // skip comment + break; + } + if (word.find("/imm") == string::npos) { + out << word << ' '; + } + else { + string output = transform_immediate(word); + trace("translate") << "converting '" << word << "' to '" << output << "'" << end(); + out << output << ' '; + } } + out << '\n'; } out.str().swap(output); } -- cgit 1.4.1-2-gfad0