tstring-re.patch 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. --- a/re2/re2.h (index)
  2. +++ b/re2/re2.h (working tree)
  3. @@ -210,6 +210,7 @@
  4. #include <string>
  5. #include <type_traits>
  6. #include <vector>
  7. +#include <util/generic/string.h>
  8. #include "absl/base/call_once.h"
  9. #include "absl/strings/string_view.h"
  10. @@ -461,6 +464,14 @@ class RE2 {
  11. static bool Replace(std::string* str,
  12. const RE2& re,
  13. absl::string_view rewrite);
  14. + static bool Replace(TString* str,
  15. + const RE2& pattern,
  16. + absl::string_view rewrite) {
  17. + std::string tmp(*str);
  18. + bool res = Replace(&tmp, pattern, rewrite);
  19. + *str = tmp;
  20. + return res;
  21. + }
  22. // Like Replace(), except replaces successive non-overlapping occurrences
  23. // of the pattern in the string with the rewrite. E.g.
  24. @@ -479,6 +492,15 @@ class RE2 {
  25. const RE2& re,
  26. absl::string_view rewrite);
  27. + static int GlobalReplace(TString* str,
  28. + const RE2& pattern,
  29. + absl::string_view rewrite) {
  30. + std::string tmp(*str);
  31. + int res = GlobalReplace(&tmp, pattern, rewrite);
  32. + *str = tmp;
  33. + return res;
  34. + }
  35. +
  36. // Like Replace, except that if the pattern matches, "rewrite"
  37. // is copied into "out" with substitutions. The non-matching
  38. // portions of "text" are ignored.
  39. @@ -492,6 +516,16 @@ class RE2 {
  40. absl::string_view rewrite,
  41. std::string* out);
  42. + static bool Extract(const StringPiece& text,
  43. + const RE2& pattern,
  44. + absl::string_view rewrite,
  45. + TString *out) {
  46. + std::string tmp;
  47. + bool res = Extract(text, pattern, rewrite, &tmp);
  48. + *out = tmp;
  49. + return res;
  50. + }
  51. +
  52. // Escapes all potentially meaningful regexp characters in
  53. // 'unquoted'. The returned string, used as a regular expression,
  54. // will match exactly the original string. For example,
  55. @@ -581,6 +617,21 @@ class RE2 {
  56. bool CheckRewriteString(absl::string_view rewrite,
  57. std::string* error) const;
  58. + bool CheckRewriteString(absl::string_view rewrite, std::nullptr_t error) const {
  59. + return CheckRewriteString(rewrite, static_cast<std::string*>(error));
  60. + }
  61. +
  62. + bool CheckRewriteString(absl::string_view rewrite, TString* error) const {
  63. + if (error) {
  64. + std::string tmp;
  65. + bool res = CheckRewriteString(rewrite, &tmp);
  66. + error->assign(tmp.data(), tmp.size());
  67. + return res;
  68. + } else {
  69. + return CheckRewriteString(rewrite, nullptr);
  70. + }
  71. + }
  72. +
  73. // Returns the maximum submatch needed for the rewrite to be done by
  74. // Replace(). E.g. if rewrite == "foo \\2,\\1", returns 2.
  75. static int MaxSubmatch(const StringPiece& rewrite);