// BEGIN mycpp output #include "gc_heap.h" using gc_heap::Alloc; using gc_heap::kZeroMask; using gc_heap::StackRoots; #include "my_runtime.h" #include "mylib2.h" using gc_heap::NewStr; using gc_heap::NewList; using gc_heap::NewDict; GLOBAL_STR(str0, "\\"); GLOBAL_STR(str1, ""); GLOBAL_STR(str2, "\\*?[]-:!"); GLOBAL_STR(str3, "."); GLOBAL_STR(str4, "NOT IN ."); GLOBAL_STR(str5, "*"); GLOBAL_STR(str6, "NOT IN *"); GLOBAL_STR(str7, "result: %s"); GLOBAL_STR(str8, "echo *.[ch] *.?"); GLOBAL_STR(str9, "echo *.[ch] *.?"); namespace escape { // forward declare } // forward declare namespace escape namespace escape { // declare Str* BackslashEscape(Str* s, Str* meta_chars); extern Str* GLOB_META_CHARS; void TestNotIn(); void run_tests(); void run_benchmarks(); inline Str* fmt0(Str* a0) { gBuf.reset(); gBuf.write_const("result: ", 8); gBuf.format_s(a0); return gBuf.getvalue(); } } // declare namespace escape namespace escape { // define Str* BackslashEscape(Str* s, Str* meta_chars) { List* escaped = nullptr; StackRoots _roots({&s, &meta_chars, &escaped}); escaped = Alloc>(); for (StrIter it(s); !it.Done(); it.Next()) { Str* c = it.Value(); StackRoots _for({&c }); if (str_contains(meta_chars, c)) { escaped->append(str0); } escaped->append(c); } return str1->join(escaped); } Str* GLOB_META_CHARS = str2; void TestNotIn() { if (!str_contains(GLOB_META_CHARS, str3)) { print(str4); } if (!str_contains(GLOB_META_CHARS, str5)) { print(str6); } } void run_tests() { println_stderr(fmt0(BackslashEscape(str8, GLOB_META_CHARS))); TestNotIn(); } void run_benchmarks() { int i; int n; Str* s = nullptr; StackRoots _roots({&s}); i = 0; n = 200000; while (i < n) { s = str9; BackslashEscape(s, GLOB_META_CHARS); i = (i + 1); } } } // define namespace escape