std::regex

互联网 行业动态 更新时间:2024-06-13 00:19:06

Sam*_*hik 5

这似乎是 libstdc++ 中的一个错误。使用我进入的调试器regex_replace,直到进入这一部分:

 // std [28.11.4] Function template regex_replace
  /**
   * @brief Search for a regular expression within a range for multiple times,
   and replace the matched parts through filling a format string.
   * @param __out   [OUT] The output iterator.
   * @param __first [IN]  The start of the string to search.
   * @param __last  [IN]  One-past-the-end of the string to search.
   * @param __e     [IN]  The regular expression to search for.
   * @param __fmt   [IN]  The format string.
   * @param __flags [IN]  Search and replace policy flags.
   *
   * @returns __out
   * @throws an exception of type regex_error.
   */
  template<typename _Out_iter, typename _Bi_iter,
       typename _Rx_traits, typename _Ch_type,
       typename _St, typename _Sa>
    inline _Out_iter
    regex_replace(_Out_iter __out, _Bi_iter __first, _Bi_iter __last,
          const basic_regex<_Ch_type, _Rx_traits>& __e,
          const basic_string<_Ch_type, _St, _Sa>& __fmt,
          regex_constants::match_flag_type __flags
          = regex_constants::match_default)
    {
      return regex_replace(__out, __first, __last, __e, __fmt.c_str(), __flags);
    }

参考cppreference.std::string上的这篇文章,这似乎是通过调用它c_str()然后调用第二个重载,即带有const char *参数的第二个重载,来实现第一个重载,即替换字符串的替换字符串。 . 这解释了观察到的行为。我找不到任何需要这种方法的东西。

进一步进入实际实施:

          auto __len = char_traits<_Ch_type>::length(__fmt);

              __out = __i->format(__out, __fmt, __fmt + __len, __flags);

因此,它确定替换字符串的长度并将替换字符串作为开始和结束迭代器传递到format().

这似乎应该是相反的方式,__fmt保留为 a std::basic_string,并将直接从它派生的迭代器传递到format().

更多推荐

std,regex

本文发布于:2023-04-20 20:23:43,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/hyzx/0fb169ce03562147298b2ff679283fd7.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:std   regex

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!