ext/redcloth_scan/redcloth.h in BBRedCloth-0.8.4 vs ext/redcloth_scan/redcloth.h in BBRedCloth-0.8.5

- old
+ new

@@ -13,10 +13,26 @@ #endif #ifndef RARRAY_PTR #define RARRAY_PTR(x) (RARRAY(x)->ptr) #endif +// Different string conversions for ruby 1.8 and ruby 1.9. For 1.9, +// we need to set the encoding of the string. + +// For Ruby 1.9 +#ifdef HAVE_RUBY_ENCODING_H +#include "ruby/encoding.h" +#define STR_NEW(p,n) rb_enc_str_new((p),(n),rb_utf8_encoding()) +#define STR_NEW2(p) rb_enc_str_new((p),strlen(p),rb_utf8_encoding()) + +// For Ruby 1.8 +#else +#define STR_NEW(p,n) rb_str_new((p),(n)) +#define STR_NEW2(p) rb_str_new2((p)) + +#endif + /* variable defs */ #ifndef redcloth_scan_c extern VALUE super_ParseError, mRedCloth, super_RedCloth; extern int SYM_escape_preformatted; #endif @@ -47,22 +63,22 @@ #define CALL_STACK_SIZE 20 #define UNLESS_DISABLED_BLOCK(H, T, F) \ if (rb_funcall(rb_funcall(self, rb_intern("disable_inline"), 0),rb_intern("include?"), 1,ID2SYM(rb_intern(#T))) != Qtrue) { F } #define UNLESS_DISABLED_INLINE(H, T, F) \ if (rb_funcall(rb_funcall(self, rb_intern("disable_inline"), 0),rb_intern("include?"), 1,ID2SYM(rb_intern(#T))) == Qtrue) { rb_str_append(H,red_passthrough(self, ts, te, refs)); } \ - else { /*VALUE test = rb_str_new(ts,te-ts); printf("\nred_passthrough_else() '%s'\n", RSTRING(test)->ptr);*/ F } + else { /*VALUE test = STR_NEW(ts,te-ts); printf("\nred_passthrough_else() '%s'\n", RSTRING(test)->ptr);*/ F } #define UNLESS_DISABLED_ATTRIBUTE(T, F) \ if (!(rb_funcall(rb_funcall(self, rb_intern("disable_inline"), 0),rb_intern("include?"), 1,ID2SYM(rb_intern(#T))) == Qtrue)) { F } //if !(rb_funcall(rb_funcall(self, rb_intern("disable_inline"), 0),rb_intern("include?"), 1,ID2SYM(rb_intern(#T))) == Qtrue) { F } #define CLEAR_REGS() regs = rb_hash_new(); #define RESET_REG() reg = NULL #define CAT(H) rb_str_cat(H, ts, te-ts) -#define CLEAR(H) H = rb_str_new2("") -#define SET_PLAIN_BLOCK(T) plain_block = rb_str_new2(T) +#define CLEAR(H) H = STR_NEW2("") +#define SET_PLAIN_BLOCK(T) plain_block = STR_NEW2(T) #define RESET_TYPE(T) rb_hash_aset(regs, ID2SYM(rb_intern("type")), plain_block) #define INLINE(H, T) rb_str_append(H, rb_funcall(self, rb_intern(T), 1, regs)) #define DONE(H) rb_str_append(html, H); CLEAR(H); CLEAR_REGS() -#define BBDONE() failed_start = rb_str_new2(""); html = rb_str_new2(""); CLEAR_REGS(); RESET_REG(); +#define BBDONE() failed_start = STR_NEW2(""); html = STR_NEW2(""); CLEAR_REGS(); RESET_REG(); #define PASS(H, A, T) rb_str_append(H, red_pass(self, regs, ID2SYM(rb_intern(A)), rb_intern(T), refs)) #define PARSE_ATTR(A) red_parse_attr(self, regs, ID2SYM(rb_intern(A))) #define PARSE_LINK_ATTR(A) red_parse_link_attr(self, regs, ID2SYM(rb_intern(A))) #define PASS_CODE(H, A, T, O) rb_str_append(H, red_pass_code(self, regs, ID2SYM(rb_intern(A)), rb_intern(T))) #define ADD_BLOCK() \ @@ -73,11 +89,11 @@ #define ADD_EXTENDED_BLOCK() rb_str_append(html, red_block(self, regs, block, refs)); CLEAR(block); #define END_EXTENDED() extend = Qnil; CLEAR_REGS(); #define IS_NOT_EXTENDED() NIL_P(extend) #define ADD_BLOCKCODE() rb_str_append(html, red_blockcode(self, regs, block)); CLEAR(block); CLEAR_REGS() #define ADD_EXTENDED_BLOCKCODE() rb_str_append(html, red_blockcode(self, regs, block)); CLEAR(block); -#define ASET(T, V) rb_hash_aset(regs, ID2SYM(rb_intern(T)), rb_str_new2(V)); +#define ASET(T, V) rb_hash_aset(regs, ID2SYM(rb_intern(T)), STR_NEW2(V)); #define AINC(T) red_inc(regs, ID2SYM(rb_intern(T))); #define SET_ATTRIBUTES() \ VALUE buf = Qnil; \ SET_ATTRIBUTE("class_buf", "class"); \ SET_ATTRIBUTE("id_buf", "id"); \ @@ -94,19 +110,19 @@ } else { \ rb_hash_aset(regs, ID2SYM(rb_intern(T)), Qnil); \ } #define STORE(T) \ if (p > reg && reg >= ts) { \ - VALUE str = rb_str_new(reg, p-reg); \ + VALUE str = STR_NEW(reg, p-reg); \ rb_hash_aset(regs, ID2SYM(rb_intern(T)), str); \ /* printf("STORE(" T ") '%s' (p:'%d' reg:'%d')\n", RSTRING(str)->ptr, p, reg);*/ \ } else { \ rb_hash_aset(regs, ID2SYM(rb_intern(T)), Qnil); \ } #define STORE_B(T) \ if (p > bck && bck >= ts) { \ - VALUE str = rb_str_new(bck, p-bck); \ + VALUE str = STR_NEW(bck, p-bck); \ rb_hash_aset(regs, ID2SYM(rb_intern(T)), str); \ /* printf("STORE_B(" T ") '%s' (p:'%d' reg:'%d')\n", RSTRING(str)->ptr, p, reg);*/ \ } else { \ rb_hash_aset(regs, ID2SYM(rb_intern(T)), Qnil); \ } @@ -175,10 +191,10 @@ rb_ary_store(list_index, nest-1, start_num); \ } \ } \ rb_hash_aset(regs, ID2SYM(rb_intern("nest")), INT2NUM(nest)); \ rb_str_append(html, rb_funcall(self, rb_intern(listm), 1, regs)); \ - rb_ary_store(list_layout, nest-1, rb_str_new2(list_type)); \ + rb_ary_store(list_layout, nest-1, STR_NEW2(list_type)); \ CLEAR_REGS(); \ ASET("first", "true"); \ } \ LIST_CLOSE(); \ rb_hash_aset(regs, ID2SYM(rb_intern("nest")), INT2NUM(RARRAY_LEN(list_layout))); \