port string interpolation from c++14 to c++98

核能气质少年 提交于 2019-12-01 14:19:07

There's a lot of involved in that, whoever wrote it really knows his stuff.

The code that you're looking at uses a style for-loop, a for_each-loop, and a traditional for-loop to effectively do three things:

  1. Loop through all the keys that could be interpolated
  2. Loop through all the value strings to interpolate
  3. Loop through the entire string to interpolate all keys

In your best bet is likely just a triple nested for-loop:

for(map<string, string>::iterator i = interpolate.begin(); i != interpolate.end(); ++i) {
    for(map<string, string>::iterator it = interpolate.begin(); it != interpolate.end(); ++it) {
        for(string::size_type pos = it->second.find(i->first); pos != string::npos; pos = it->second.find(i->first, pos)) {
            it->second.replace(pos, i->first.size(), '(' + i->second + ')');
        }
    }
}

Live Example

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!