Skip to content

Instantly share code, notes, and snippets.

@bdrewery
Created May 16, 2010 03:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bdrewery/402616 to your computer and use it in GitHub Desktop.
Save bdrewery/402616 to your computer and use it in GitHub Desktop.
Subst api mockup
String String::subst(HashTable<String, String> hashes) const {
String newStr(*this);
Array<String> keys(hashes.keys());
Array<String> values(hashes.values());
for (size_t i = 0; i < keys.length(); ++i) {
const String key(keys[i]), value(values[i]);
//::printf("%s -> %s\n", key.c_str(), value.c_str());
newStr = newStr.sub(key, value);
}
return newStr;
}
*a = "$this $is $a $test";
HashTable<String, String> hashes;
hashes["$this"] = "THIS";
hashes["$is"] = "IS";
hashes["$a"] = "A";
hashes["$test"] = "TEST";
*b = a->subst(hashes);
CPPUNIT_ASSERT_STRING_EQUAL("$this $is $a $test", *a);
CPPUNIT_ASSERT_STRING_EQUAL("THIS IS A TEST", *b);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment