Page Speed Optimization Libraries
1.13.35.1
|
Public Types | |
typedef Callback1< GoogleString * > | StringRewriter |
Public Member Functions | |
JsReplacer (const pagespeed::js::JsTokenizerPatterns *patterns) | |
Does not take ownership of patterns. | |
void | AddPattern (const GoogleString &object, const GoogleString &field, StringRewriter *rewriter) |
bool | Transform (StringPiece in, GoogleString *out) |
void net_instaweb::JsReplacer::AddPattern | ( | const GoogleString & | object, |
const GoogleString & | field, | ||
StringRewriter * | rewriter | ||
) |
Whenever a pattern of object.field = "literal" is seen, 'rewriter' will get called to change the value of literal. (This also includes something like otherobject.object.field = "literal") Does not take ownership of rewriter.
If there are multiple additions of patterns with same object and field, the first one gets invoked.
Note that this may not work right if the pattern uses a reserved keyword (e.g. things like 'class').
bool net_instaweb::JsReplacer::Transform | ( | StringPiece | in, |
GoogleString * | out | ||
) |
Transforms the JS by applying any patterns added by calls to AddPattern, and writes the result to *out. Quoting style of string literals is preserved, and the StringRewriter is responsible for proper escaping inside its output.
Returns true if the input was lexed successfully, and false if there were errors — in which case *out may not be complete.