miyamuko #2157(2007/08/14 12:39 GMT) [ xtal ] Rating0/0=0.00
ひたすら一文字づつ見てパースしました。正規表現ほしぃ。。。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
Iterator::with_peek: method fiber { prev, curr: null, null; noloop: true; this {|next| if (curr) { yield prev, curr, next; } prev, curr = curr, next; noloop = false; } if (!noloop) { yield prev, curr, null; } } remover: fun(str) fiber { in_comment: false; str.split("").each.with_peek {|prev,it,next| if (in_comment) { if (prev == "*" && it == "/") { in_comment = false; } } else { if (it == "/" && next == "*") { in_comment = true; } else { yield it; } } } } remove_comment: fun(str) { return remover(str).to_a.join(""); } assert remove_comment("AAA") == "AAA"; assert remove_comment("AAA/*BBB*/") == "AAA"; assert remove_comment("AAA/*BBB") == "AAA"; assert remove_comment("AAA/*BBB*/CCC") == "AAACCC"; assert remove_comment("AAA/*BBB/*CCC*/DDD*/EEE") == "AAADDD*/EEE"; assert remove_comment("AAA/a//*BB*B**/CCC") == "AAA/a/CCC";
Rating0/0=0.00-0+
[ reply ]
miyamuko
#2157()
[
xtal
]
Rating0/0=0.00
Iterator::with_peek: method fiber { prev, curr: null, null; noloop: true; this {|next| if (curr) { yield prev, curr, next; } prev, curr = curr, next; noloop = false; } if (!noloop) { yield prev, curr, null; } } remover: fun(str) fiber { in_comment: false; str.split("").each.with_peek {|prev,it,next| if (in_comment) { if (prev == "*" && it == "/") { in_comment = false; } } else { if (it == "/" && next == "*") { in_comment = true; } else { yield it; } } } } remove_comment: fun(str) { return remover(str).to_a.join(""); } assert remove_comment("AAA") == "AAA"; assert remove_comment("AAA/*BBB*/") == "AAA"; assert remove_comment("AAA/*BBB") == "AAA"; assert remove_comment("AAA/*BBB*/CCC") == "AAACCC"; assert remove_comment("AAA/*BBB/*CCC*/DDD*/EEE") == "AAADDD*/EEE"; assert remove_comment("AAA/a//*BB*B**/CCC") == "AAA/a/CCC";Rating0/0=0.00-0+
[ reply ]