- boost::regex::flag_type b_mode = boost::regex::perl;
- if (mode.find_first_of('i') != std::string::npos)
- b_mode |= boost::regex::icase;
- boost::regex e(pattern, b_mode);
-
- boost::match_flag_type match_mode = boost::format_first_only;
- if (mode.find_first_of('g') != std::string::npos)
- match_mode = boost::format_all;
- result += regex_replace(text, e, replacement, match_mode);
+ if (pattern.length() > 0)
+ {
+ boost::regex::flag_type b_mode = boost::regex::perl;
+ if (mode.find_first_of('i') != std::string::npos)
+ b_mode |= boost::regex::icase;
+ boost::regex e(pattern, b_mode);
+ boost::match_flag_type match_mode = boost::format_first_only;
+ if (mode.find_first_of('g') != std::string::npos)
+ match_mode = boost::format_all;
+ text = regex_replace(text, e, replacement, match_mode);
+ }
+ if (!uri_encode)
+ result += text;
+ else
+ {
+ char src[2];
+ char dst[4];
+ size_t i;
+ for (i = 0; i < text.length(); i++)
+ {
+ src[0] = text[i];
+ src[1] = '\0';
+ yaz_encode_uri_component(dst, src);
+ result += dst;
+ }
+ }