@@ -162,6 +162,52 @@ module StringOps {
162
162
}
163
163
}
164
164
165
+ /**
166
+ * An expression that is equivalent to `strings.ReplaceAll(s, old, new)`.
167
+ *
168
+ * Extend this class to refine existing API models. If you want to model new APIs,
169
+ * extend `StringOps::ReplaceAll::Range` instead.
170
+ */
171
+ class ReplaceAll extends DataFlow:: Node instanceof ReplaceAll:: Range {
172
+ /**
173
+ * Gets the `old` in `strings.ReplaceAll(s, old, new)`.
174
+ */
175
+ string getReplacedString ( ) { result = super .getReplacedString ( ) }
176
+ }
177
+
178
+ /** Provides predicates and classes for working with prefix checks. */
179
+ module ReplaceAll {
180
+ /**
181
+ * An expression that is equivalent to `strings.ReplaceAll(s, old, new)`.
182
+ *
183
+ * Extend this class to model new APIs. If you want to refine existing API models, extend
184
+ * `StringOps::ReplaceAll` instead.
185
+ */
186
+ abstract class Range extends DataFlow:: Node {
187
+ /**
188
+ * Gets the `old` in `strings.ReplaceAll(s, old, new)`.
189
+ */
190
+ abstract string getReplacedString ( ) ;
191
+ }
192
+
193
+ /**
194
+ * A call to `strings.ReplaceAll` or `strings.Replace` with a negative `n`
195
+ * so that all instances are replaced.
196
+ */
197
+ private class StringsReplaceAll extends Range , DataFlow:: CallNode {
198
+ StringsReplaceAll ( ) {
199
+ exists ( string name | this .getTarget ( ) .hasQualifiedName ( "strings" , name ) |
200
+ name = "ReplaceAll"
201
+ or
202
+ name = "Replace" and
203
+ this .getArgument ( 3 ) .getNumericValue ( ) < 0
204
+ )
205
+ }
206
+
207
+ override string getReplacedString ( ) { result = this .getArgument ( 1 ) .getStringValue ( ) }
208
+ }
209
+ }
210
+
165
211
/** Provides predicates and classes for working with Printf-style formatters. */
166
212
module Formatting {
167
213
/**
0 commit comments