From 66b97b4d923274e1b6d2fd97df16cb73d820169b Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Mon, 30 Mar 2015 21:22:29 -0700 Subject: 996 - string literals --- cpp/029string | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 cpp/029string (limited to 'cpp/029string') diff --git a/cpp/029string b/cpp/029string new file mode 100644 index 00000000..4379c8ec --- /dev/null +++ b/cpp/029string @@ -0,0 +1,29 @@ +:(scenario "string_literal") +recipe main [ + s:address:array:character <- new [abc def] +] ++parse: ingredient: {name: "abc def", value: 0, type: 0, properties: [abc def: literal-string]} + +:(before "End Mu Types Initialization") +Type_number["literal-string"] = 0; + +:(after "string next_word(istream& in)") +if (in.peek() == '[') return slurp_quoted(in); + +:(code) +string slurp_quoted(istream& in) { + assert(!in.eof()); + assert(in.get() == '['); + ostringstream out; + int size = 1; + while (!in.eof()) { + char c = in.get(); + if (c == '[') ++size; + if (c == ']') --size; + if (size == 0) break; +//? cout << c << '\n'; //? 1 + out << c; +//? cout << out.str() << "$\n"; //? 1 + } + return out.str(); +} -- cgit 1.4.1-2-gfad0