File tree 3 files changed +49
-0
lines changed
solution/1400-1499/1410.HTML Entity Parser
3 files changed +49
-0
lines changed Original file line number Diff line number Diff line change @@ -182,6 +182,24 @@ public:
182
182
};
183
183
```
184
184
185
+ ### **TypeScript**
186
+
187
+ ```ts
188
+ function entityParser(text: string): string {
189
+ const d: { [key: string]: string } = {
190
+ '"': '"',
191
+ ''': "'",
192
+ '&': '&',
193
+ '>': '>',
194
+ '<': '<',
195
+ '⁄': '/',
196
+ };
197
+
198
+ const pattern = new RegExp(Object.keys(d).join('|'), 'g');
199
+ return text.replace(pattern, match => d[match]);
200
+ }
201
+ ```
202
+
185
203
### ** ...**
186
204
187
205
```
Original file line number Diff line number Diff line change @@ -151,6 +151,24 @@ public:
151
151
};
152
152
```
153
153
154
+ ### **TypeScript**
155
+
156
+ ```ts
157
+ function entityParser(text: string): string {
158
+ const d: { [key: string]: string } = {
159
+ '"': '"',
160
+ ''': "'",
161
+ '&': '&',
162
+ '>': '>',
163
+ '<': '<',
164
+ '⁄': '/',
165
+ };
166
+
167
+ const pattern = new RegExp(Object.keys(d).join('|'), 'g');
168
+ return text.replace(pattern, match => d[match]);
169
+ }
170
+ ```
171
+
154
172
### ** ...**
155
173
156
174
```
Original file line number Diff line number Diff line change
1
+ function entityParser ( text : string ) : string {
2
+ const d : { [ key : string ] : string } = {
3
+ '"' : '"' ,
4
+ ''' : "'" ,
5
+ '&' : '&' ,
6
+ '>' : '>' ,
7
+ '<' : '<' ,
8
+ '⁄' : '/' ,
9
+ } ;
10
+
11
+ const pattern = new RegExp ( Object . keys ( d ) . join ( '|' ) , 'g' ) ;
12
+ return text . replace ( pattern , match => d [ match ] ) ;
13
+ }
You can’t perform that action at this time.
0 commit comments