dtext_rb 1.0.9 → 1.0.10

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.
data/ext/dtext/dtext.rl CHANGED
@@ -34,6 +34,7 @@ typedef struct StateMachine {
34
34
  int list_nest;
35
35
  int d;
36
36
  int b;
37
+ int quote;
37
38
  } StateMachine;
38
39
 
39
40
  static const size_t MAX_STACK_DEPTH = 512;
@@ -318,7 +319,10 @@ inline := |*
318
319
  append(sm, true, "<a href=\"");
319
320
  append_segment_html_escaped(sm, sm->b1, sm->b2 - sm->d);
320
321
  append(sm, true, "\">");
321
- append_segment_html_escaped(sm, sm->a1, sm->a2 - 1);
322
+ link_content_sm = parse_helper(sm->a1, sm->a2 - sm->a1, false, true);
323
+ append(sm, true, link_content_sm->output->str);
324
+ free_machine(link_content_sm);
325
+ link_content_sm = NULL;
322
326
  append(sm, true, "</a>");
323
327
 
324
328
  if (sm->b) {
@@ -1072,7 +1076,7 @@ static inline void append_segment_html_escaped(StateMachine * sm, const char * a
1072
1076
 
1073
1077
  static inline void append_block(StateMachine * sm, const char * s) {
1074
1078
  if (sm->f_inline) {
1075
- sm->output = g_string_append_c(sm->output, ' ');
1079
+ // sm->output = g_string_append_c(sm->output, ' ');
1076
1080
  } else if (sm->f_strip) {
1077
1081
  // do nothing
1078
1082
  } else {
@@ -1244,18 +1248,18 @@ static bool print_machine(StateMachine * sm) {
1244
1248
  return true;
1245
1249
  }
1246
1250
 
1247
- static void init_machine(StateMachine * sm, VALUE input) {
1251
+ static void init_machine(StateMachine * sm, const char * src, size_t len) {
1248
1252
  size_t output_length = 0;
1249
- sm->p = RSTRING_PTR(input);
1253
+ sm->p = src;
1250
1254
  sm->pb = sm->p;
1251
- sm->pe = sm->p + RSTRING_LEN(input);
1255
+ sm->pe = sm->p + len;
1252
1256
  sm->eof = sm->pe;
1253
1257
  sm->ts = NULL;
1254
1258
  sm->te = NULL;
1255
1259
  sm->cs = 0;
1256
1260
  sm->act = 0;
1257
1261
  sm->top = 0;
1258
- output_length = RSTRING_LEN(input);
1262
+ output_length = len;
1259
1263
  if (output_length < (INT16_MAX / 2)) {
1260
1264
  output_length *= 2;
1261
1265
  }
@@ -1273,6 +1277,7 @@ static void init_machine(StateMachine * sm, VALUE input) {
1273
1277
  sm->header_mode = false;
1274
1278
  sm->d = 0;
1275
1279
  sm->b = 0;
1280
+ sm->quote = 0;
1276
1281
  }
1277
1282
 
1278
1283
  static void free_machine(StateMachine * sm) {
@@ -1282,6 +1287,23 @@ static void free_machine(StateMachine * sm) {
1282
1287
  g_free(sm);
1283
1288
  }
1284
1289
 
1290
+ static StateMachine * parse_helper(const char * src, size_t len, bool f_strip, bool f_inline) {
1291
+ StateMachine * sm = NULL;
1292
+ StateMachine * link_content_sm = NULL;
1293
+
1294
+ sm = (StateMachine *)g_malloc0(sizeof(StateMachine));
1295
+ init_machine(sm, src, len);
1296
+ sm->f_strip = f_strip;
1297
+ sm->f_inline = f_inline;
1298
+
1299
+ %% write init;
1300
+ %% write exec;
1301
+
1302
+ dstack_close(sm);
1303
+
1304
+ return sm;
1305
+ }
1306
+
1285
1307
  static VALUE parse(int argc, VALUE * argv, VALUE self) {
1286
1308
  VALUE input;
1287
1309
  VALUE input0;
@@ -1291,6 +1313,8 @@ static VALUE parse(int argc, VALUE * argv, VALUE self) {
1291
1313
  VALUE ret;
1292
1314
  rb_encoding * encoding = NULL;
1293
1315
  StateMachine * sm = NULL;
1316
+ bool f_strip = false;
1317
+ bool f_inline = false;
1294
1318
 
1295
1319
  g_debug("start\n");
1296
1320
 
@@ -1305,31 +1329,25 @@ static VALUE parse(int argc, VALUE * argv, VALUE self) {
1305
1329
  }
1306
1330
 
1307
1331
  input0 = rb_str_dup(input);
1308
-
1309
- sm = (StateMachine *)g_malloc0(sizeof(StateMachine));
1310
1332
  input0 = rb_str_cat(input0, "\0", 1);
1311
- init_machine(sm, input0);
1312
-
1333
+
1313
1334
  if (argc > 1) {
1314
1335
  options = argv[1];
1315
1336
 
1316
1337
  if (!NIL_P(options)) {
1317
1338
  opt_strip = rb_hash_aref(options, ID2SYM(rb_intern("strip")));
1318
1339
  if (RTEST(opt_strip)) {
1319
- sm->f_strip = true;
1340
+ f_strip = true;
1320
1341
  }
1321
1342
 
1322
1343
  opt_inline = rb_hash_aref(options, ID2SYM(rb_intern("inline")));
1323
1344
  if (RTEST(opt_inline)) {
1324
- sm->f_inline = true;
1345
+ f_inline = true;
1325
1346
  }
1326
1347
  }
1327
1348
  }
1328
1349
 
1329
- %% write init;
1330
- %% write exec;
1331
-
1332
- dstack_close(sm);
1350
+ sm = parse_helper(RSTRING_PTR(input0), RSTRING_LEN(input0), f_strip, f_inline);
1333
1351
 
1334
1352
  encoding = rb_enc_find("utf-8");
1335
1353
  ret = rb_enc_str_new(sm->output->str, sm->output->len, encoding);
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dtext_rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.9
4
+ version: 1.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - r888888888
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-30 00:00:00.000000000 Z
11
+ date: 2016-09-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest