@@ -720,55 +720,6 @@ static inline ast_t* BOOLOP_01(Allocator &al, Location &loc,
720720#define COMPARE (x, op, y, l ) make_Compare_t(p.m_a, l, \
721721 EXPR (x), cmpopType::op, EXPRS(A2LIST(p.m_a, y)), 1)
722722
723- char *get_raw_string(Allocator &al, std::string s) {
724- std::string x;
725- for (size_t idx=0 ; idx < s.size (); idx++) {
726- if (s[idx] == ' \n ' ) {
727- x += " \\ n" ;
728- } else if (s[idx] == ' \t ' ) {
729- x += " \\ t" ;
730- } else if (s[idx] == ' \b ' ) {
731- x += " \\ b" ;
732- } else if (s[idx] == ' \v ' ) {
733- x += " \\ v" ;
734- } else if (s[idx] == ' \\ ' && (s[idx+1 ] == ' n' || s[idx+1 ] == ' N'
735- || s[idx+1 ] == ' t' || s[idx+1 ] == ' b' || s[idx+1 ] == ' v' )) {
736- x += " \\\\ " ;
737- x += s[idx+1 ];
738- idx++;
739- } else if (s[idx] == ' \\ ' ) {
740- x += " \\\\ " ;
741- } else if (s[idx] == ' "' ) {
742- x += " \\\" " ;
743- } else {
744- x += s[idx];
745- }
746- }
747- return LCompilers::s2c (al, x);
748- }
749-
750- char * escape_string (Allocator &al, LCompilers::Str &s) {
751- std::string x;
752- for (size_t idx=0 ; idx < s.size (); idx++) {
753- if (s.p [idx] == ' \n ' ) {
754- x += " \\ n" ;
755- } else if (s.p [idx] == ' \\ ' && s.p [idx+1 ] == ' \n ' ) {
756- idx++;
757- } else if (s.p [idx] == ' \\ ' && s.p [idx+1 ] == ' \\ ' ) {
758- x += " \\\\ " ;
759- idx++;
760- } else if (s.p [idx] == ' \\ ' && s.p [idx+1 ] == ' \' ' ) {
761- x += ' \' ' ;
762- idx++;
763- } else if (s.p [idx-1 ] != ' \\ ' && s.p [idx] == ' "' ) {
764- x += " \\\" " ;
765- } else {
766- x += s.p [idx];
767- }
768- }
769- return LCompilers::s2c (al, x);
770- }
771-
772723static inline ast_t* concat_string(Allocator &al, Location &l,
773724 expr_t *string, std::string str, expr_t *string_literal) {
774725 std::string str1 = " " ;
@@ -847,8 +798,8 @@ static inline ast_t* concat_string(Allocator &al, Location &l,
847798 x.c_str(p.m_a), expr_contextType::Load)
848799// `x.int_n` is of type BigInt but we store the int64_t directly in AST
849800#define INTEGER (x, l ) make_ConstantInt_t(p.m_a, l, x, nullptr )
850- #define STRING1 (x, l ) make_ConstantStr_t(p.m_a, l, escape_string (p.m_a, x), nullptr )
851- #define STRING2 (x, y, l ) concat_string(p.m_a, l, EXPR(x), escape_string (p.m_a, y), nullptr )
801+ #define STRING1 (x, l ) make_ConstantStr_t(p.m_a, l, unescape_string (p.m_a, x), nullptr )
802+ #define STRING2 (x, y, l ) concat_string(p.m_a, l, EXPR(x), unescape_string (p.m_a, y), nullptr )
852803#define STRING3 (id, x, l ) PREFIX_STRING(p.m_a, l, name2char(id), x.c_str(p.m_a))
853804#define STRING4 (x, s, l ) concat_string(p.m_a, l, EXPR(x), " " , EXPR(s))
854805#define FLOAT (x, l ) make_ConstantFloat_t(p.m_a, l, x, nullptr )
@@ -900,9 +851,6 @@ static inline ast_t *PREFIX_STRING(Allocator &al, Location &l, char *prefix, cha
900851 for (size_t i = 0 ; i < strs.size (); i++) {
901852 if (strs[i][0 ] == ' "' ) {
902853 strs[i] = strs[i].substr (1 , strs[i].length () - 2 );
903- if (strcmp (prefix, " fr" ) == 0 || strcmp (prefix, " rf" ) == 0 ) {
904- strs[i] = std::string (get_raw_string (al, strs[i]));
905- }
906854 tmp = make_ConstantStr_t (al, l, LCompilers::s2c (al, strs[i]), nullptr );
907855 exprs.push_back (al, down_cast<expr_t >(tmp));
908856 } else {
@@ -914,18 +862,16 @@ static inline ast_t *PREFIX_STRING(Allocator &al, Location &l, char *prefix, cha
914862 }
915863 tmp = make_JoinedStr_t (al, l, exprs.p , exprs.size ());
916864 } else if (strcmp (prefix, " b" ) == 0 ) {
917- std::string str_1 = std::string (s);
918- LCompilers::Str str_2;
919- str_2.from_str_view (str_1);
920- str_1 = escape_string (al, str_2);
921- str_1 = " b'" + str_1 + " '" ;
922- tmp = make_ConstantBytes_t (al, l, LCompilers::s2c (al, str_1), nullptr );
923- } else if (strcmp (prefix, " br" ) == 0 || strcmp (prefix, " rb" ) == 0 ) {
924- std::string str = std::string (get_raw_string (al, std::string (s)));
865+ LCompilers::Str s_;
866+ s_.from_str (al, std::string (s));
867+ std::string str = std::string (unescape_string (al, s_));
868+ str = " b'" + str + " '" ;
869+ tmp = make_ConstantBytes_t (al, l, LCompilers::s2c (al, str), nullptr );
870+ } else if ( strcmp (prefix, " br" ) == 0 || strcmp (prefix, " rb" ) == 0 ) {
871+ std::string str = std::string (s);
925872 str = " b'" + str + " '" ;
926873 tmp = make_ConstantBytes_t (al, l, LCompilers::s2c (al, str), nullptr );
927874 } else if (strcmp (prefix, " r" ) == 0 ) {
928- s = get_raw_string (al, std::string (s));
929875 tmp = make_ConstantStr_t (al, l, s, nullptr );
930876 } else if (strcmp (prefix, " u" ) == 0 ) {
931877 tmp = make_ConstantStr_t (al, l, s, LCompilers::s2c (al, " u" ));
0 commit comments