html_namespacing 0.1.7 → 0.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -9,18 +9,21 @@
9
9
 
10
10
  #define WHITE_SPACE " \t\r\n"
11
11
 
12
- static const char* const IGNORE_TAGS[] = {
13
- "html",
14
- "head",
15
- "base",
16
- "meta",
17
- "title",
18
- "link",
19
- "script",
20
- "noscript",
21
- "style",
22
- NULL
12
+ static const struct IgnoreTag {
13
+ const char *str;
14
+ size_t len;
15
+ } IGNORE_TAGS[] = {
16
+ { "html", 4 },
17
+ { "head", 4 },
18
+ { "base", 4 },
19
+ { "meta", 4 },
20
+ { "title", 5 },
21
+ { "link", 4 },
22
+ { "script", 6 },
23
+ { "noscript", 8 },
24
+ { "style", 5 }
23
25
  };
26
+ static const int NUM_IGNORE_TAGS = 9;
24
27
 
25
28
  static int
26
29
  determine_alloc_size_of_at_least(int i)
@@ -147,12 +150,10 @@ static int
147
150
  should_ignore_tag(const char *tag_name, size_t tag_len)
148
151
  {
149
152
  int i = 0;
150
- const char *test_ignore;
151
153
 
152
- for (i = 0; (test_ignore = IGNORE_TAGS[i]); i++) {
153
- if (0 == strncmp(test_ignore, tag_name, tag_len)
154
- && strlen(test_ignore) == tag_len)
155
- {
154
+ for (i = 0; i < NUM_IGNORE_TAGS; i++) {
155
+ if (tag_len == IGNORE_TAGS[i].len
156
+ && 0 == strncmp(IGNORE_TAGS[i].str, tag_name, tag_len)) {
156
157
  return 1;
157
158
  }
158
159
  }
@@ -196,9 +197,9 @@ add_namespace_to_html_with_length_and_allocation_strategy(
196
197
  HtmlNamespacingAllocationStrategy allocation_strategy)
197
198
  {
198
199
 
199
- #define APPEND_STRING(s) \
200
+ #define APPEND_STRING(s, n) \
200
201
  do { \
201
- if (append_string(&r, &r_len, &r_p, s, strlen(s), allocation_strategy) != 0) goto error; \
202
+ if (append_string(&r, &r_len, &r_p, s, n, allocation_strategy) != 0) goto error; \
202
203
  } while (0)/*;*/
203
204
  #define APPEND_END_OF_STRING() \
204
205
  do { \
@@ -234,6 +235,7 @@ add_namespace_to_html_with_length_and_allocation_strategy(
234
235
  int open_tag_attribute_is_class_attribute;
235
236
  int open_tag_had_class_attribute;
236
237
  const char *open_tag_attribute_value;
238
+ size_t ns_len = strlen(ns);
237
239
 
238
240
  r_len = determine_alloc_size_of_at_least(html_len);
239
241
  r = allocation_strategy.malloc(sizeof(char) * r_len);
@@ -286,13 +288,13 @@ add_namespace_to_html_with_length_and_allocation_strategy(
286
288
  COPY_TO_HERE();
287
289
  if (*html_p == '/' && char_is_whitespace(*(html_p - 1))) {
288
290
  /* We're in an empty tag with a trailing space */
289
- APPEND_STRING("class=\"");
290
- APPEND_STRING(ns);
291
- APPEND_STRING("\" ");
291
+ APPEND_STRING("class=\"", 7);
292
+ APPEND_STRING(ns, ns_len);
293
+ APPEND_STRING("\" ", 2);
292
294
  } else {
293
- APPEND_STRING(" class=\"");
294
- APPEND_STRING(ns);
295
- APPEND_STRING("\"");
295
+ APPEND_STRING(" class=\"", 8);
296
+ APPEND_STRING(ns, ns_len);
297
+ APPEND_STRING("\"", 1);
296
298
  }
297
299
  }
298
300
 
@@ -339,8 +341,8 @@ add_namespace_to_html_with_length_and_allocation_strategy(
339
341
  if (open_tag_attribute_is_class_attribute
340
342
  && num_tags_open == 0) {
341
343
  COPY_TO_HERE();
342
- APPEND_STRING(" ");
343
- APPEND_STRING(ns);
344
+ APPEND_STRING(" ", 1);
345
+ APPEND_STRING(ns, ns_len);
344
346
  }
345
347
  open_tag_attribute_is_class_attribute = 0;
346
348
  state = PARSE_OPEN_TAG;
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: html_namespacing
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - adamh