@@ -185,23 +185,43 @@ find_member(std::string name, const std::vector<std::string> names, bool ignore_
185185 return (it != std::end (names)) ? (it - std::begin (names)) : (-1 );
186186}
187187
188- CLI11_MODULE_INLINE const std::string &escapedChars (" \b\t\n\f\r\"\\ " );
189- CLI11_MODULE_INLINE const std::string &escapedCharsCode (" btnfr\"\\ " );
188+ CLI11_MODULE_INLINE const std::string &escapedChars () {
189+ static const std::string s{" \b\t\n\f\r\"\\ " };
190+ return s;
191+ }
192+ CLI11_MODULE_INLINE const std::string &escapedCharsCode () {
193+ static const std::string s{" btnfr\"\\ " };
194+ return s;
195+ }
196+ CLI11_MODULE_INLINE const std::string &bracketChars () {
197+ static const std::string s{" \" '`[(<{" };
198+ return s;
199+ }
200+ CLI11_MODULE_INLINE const std::string &matchBracketChars () {
201+ static const std::string s{" \" '`])>}" };
202+ return s;
203+ }
204+
205+ // CLI11_MODULE_INLINE constexpr char escapedChars[]="\b\t\n\f\r\"\\";
206+ // CLI11_MODULE_INLINE constexpr char escapedCharsCode[]="btnfr\"\\";
207+ /*
208+ const std::string &escapedChars("\b\t\n\f\r\"\\");
209+
190210CLI11_MODULE_INLINE const std::string &bracketChars("\"'`[(<{");
191211CLI11_MODULE_INLINE const std::string &matchBracketChars("\"'`])>}");
192-
212+ */
193213CLI11_INLINE bool has_escapable_character (const std::string &str) {
194- return (str.find_first_of (escapedChars) != std::string::npos);
214+ return (str.find_first_of (escapedChars () ) != std::string::npos);
195215}
196216
197217CLI11_INLINE std::string add_escaped_characters (const std::string &str) {
198218 std::string out;
199219 out.reserve (str.size () + 4 );
200220 for (char s : str) {
201- auto sloc = escapedChars.find_first_of (s);
221+ auto sloc = escapedChars () .find_first_of (s);
202222 if (sloc != std::string::npos) {
203223 out.push_back (' \\ ' );
204- out.push_back (escapedCharsCode[sloc]);
224+ out.push_back (escapedCharsCode () [sloc]);
205225 } else {
206226 out.push_back (s);
207227 }
@@ -258,9 +278,9 @@ CLI11_INLINE std::string remove_escaped_characters(const std::string &str) {
258278 if (str.end () - loc < 2 ) {
259279 throw std::invalid_argument (" invalid escape sequence " + str);
260280 }
261- auto ecloc = escapedCharsCode.find_first_of (*(loc + 1 ));
281+ auto ecloc = escapedCharsCode () .find_first_of (*(loc + 1 ));
262282 if (ecloc != std::string::npos) {
263- out.push_back (escapedChars[ecloc]);
283+ out.push_back (escapedChars () [ecloc]);
264284 ++loc;
265285 } else if (*(loc + 1 ) == ' u' ) {
266286 // must have 4 hex characters
@@ -330,7 +350,7 @@ CLI11_INLINE std::size_t close_literal_quote(const std::string &str, std::size_t
330350
331351CLI11_INLINE std::size_t close_sequence (const std::string &str, std::size_t start, char closure_char) {
332352
333- auto bracket_loc = matchBracketChars.find (closure_char);
353+ auto bracket_loc = matchBracketChars () .find (closure_char);
334354 switch (bracket_loc) {
335355 case 0 :
336356 return close_string_quote (str, start, closure_char);
@@ -356,7 +376,7 @@ CLI11_INLINE std::size_t close_sequence(const std::string &str, std::size_t star
356376 return loc;
357377 }
358378 }
359- bracket_loc = bracketChars.find (str[loc]);
379+ bracket_loc = bracketChars () .find (str[loc]);
360380 if (bracket_loc != std::string::npos) {
361381 switch (bracket_loc) {
362382 case 0 :
@@ -367,7 +387,7 @@ CLI11_INLINE std::size_t close_sequence(const std::string &str, std::size_t star
367387 loc = close_literal_quote (str, loc, str[loc]);
368388 break ;
369389 default :
370- closures.push_back (matchBracketChars[bracket_loc]);
390+ closures.push_back (matchBracketChars () [bracket_loc]);
371391 break ;
372392 }
373393 }
@@ -388,9 +408,9 @@ CLI11_INLINE std::vector<std::string> split_up(std::string str, char delimiter)
388408
389409 std::vector<std::string> output;
390410 while (!str.empty ()) {
391- if (bracketChars.find_first_of (str[0 ]) != std::string::npos) {
392- auto bracketLoc = bracketChars.find_first_of (str[0 ]);
393- auto end = close_sequence (str, 0 , matchBracketChars[bracketLoc]);
411+ if (bracketChars () .find_first_of (str[0 ]) != std::string::npos) {
412+ auto bracketLoc = bracketChars () .find_first_of (str[0 ]);
413+ auto end = close_sequence (str, 0 , matchBracketChars () [bracketLoc]);
394414 if (end >= str.size ()) {
395415 output.push_back (std::move (str));
396416 str.clear ();
0 commit comments