Page Speed Optimization Libraries  1.13.35.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
js_replacer.h
Go to the documentation of this file.
1 /*
2  * Copyright 2014 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http:///www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
21 
22 #ifndef NET_INSTAWEB_REWRITER_PUBLIC_JS_REPLACER_H_
23 #define NET_INSTAWEB_REWRITER_PUBLIC_JS_REPLACER_H_
24 
25 #include <vector>
26 
31 #include "pagespeed/kernel/js/js_tokenizer.h"
32 
33 namespace net_instaweb {
34 
35 class JsReplacer {
36  public:
38 
41  : js_tokenizer_patterns_(patterns) {}
42 
43  ~JsReplacer();
44 
55  void AddPattern(const GoogleString& object,
56  const GoogleString& field,
57  StringRewriter* rewriter);
58 
66  bool Transform(StringPiece in, GoogleString* out);
67 
68  private:
69  struct Pattern {
70  Pattern() : rewriter(NULL) {}
71  Pattern(const GoogleString& object, const GoogleString& field,
72  StringRewriter* rewriter)
73  : object(object), field(field), rewriter(rewriter) {}
74 
75  GoogleString object;
76  GoogleString field;
77  StringRewriter* rewriter;
78  };
79 
83  bool HandleCandidate(const GoogleString& object, const GoogleString& field,
84  StringPiece value, GoogleString* out);
85 
86  std::vector<Pattern> patterns_;
87  const pagespeed::js::JsTokenizerPatterns* js_tokenizer_patterns_;
88 
89 
90 };
91 
92 }
93 
94 #endif
JsReplacer(const pagespeed::js::JsTokenizerPatterns *patterns)
Does not take ownership of patterns.
Definition: js_replacer.h:40
Definition: js_replacer.h:35
bool Transform(StringPiece in, GoogleString *out)
std::string GoogleString
PAGESPEED_KERNEL_BASE_STRING_H_.
Definition: string.h:24
Definition: js_tokenizer.h:194
Definition: callback.h:44
void AddPattern(const GoogleString &object, const GoogleString &field, StringRewriter *rewriter)