| 139 | |
| 140 | template<class String> |
| 141 | inline Foam::string |
| 142 | Foam::string::quotemeta(const string& str, const char quote) |
| 143 | { |
| 144 | if (!quote) |
| 145 | { |
| 146 | return str; |
| 147 | } |
| 148 | |
| 149 | string sQuoted; |
| 150 | sQuoted.reserve(2*str.length()); |
| 151 | |
| 152 | int escaped = 0; |
| 153 | for (const_iterator iter = str.begin(); iter != str.end(); ++iter) |
| 154 | { |
| 155 | if (*iter == quote) |
| 156 | { |
| 157 | escaped ^= 1; // toggle state |
| 158 | } |
| 159 | else if (escaped) |
| 160 | { |
| 161 | escaped = 0; |
| 162 | } |
| 163 | else if (String::meta(*iter)) |
| 164 | { |
| 165 | sQuoted += quote; |
| 166 | } |
| 167 | |
| 168 | sQuoted += *iter; |
| 169 | } |
| 170 | |
| 171 | sQuoted.resize(sQuoted.length()); |
| 172 | |
| 173 | return sQuoted; |
| 174 | } |
| 175 | |
| 176 | |
| 177 | template<class String> |