@@ -87,29 +87,6 @@ std::string replace(const std::string &s,
8787 return std::regex_replace (s, std::regex (regex), replace);
8888}
8989
90- std::string get_escaped_str (const std::string &s) {
91- std::ostringstream o;
92- for (auto c = s.cbegin (); c != s.cend (); c++) {
93- switch (*c) {
94- case ' "' : o << " \\\" " ; break ;
95- case ' \\ ' : o << " \\\\ " ; break ;
96- case ' \b ' : o << " \\ b" ; break ;
97- case ' \f ' : o << " \\ f" ; break ;
98- case ' \n ' : o << " \\ n" ; break ;
99- case ' \r ' : o << " \\ r" ; break ;
100- case ' \t ' : o << " \\ t" ; break ;
101- default :
102- if (' \x00 ' <= *c && *c <= ' \x1f ' ) {
103- o << " \\ u"
104- << std::hex << std::setw (4 ) << std::setfill (' 0' ) << static_cast <int >(*c);
105- } else {
106- o << *c;
107- }
108- }
109- }
110- return o.str ();
111- }
112-
11390std::string read_file (const std::string &filename)
11491{
11592 std::ifstream ifs (filename.c_str (), std::ios::in | std::ios::binary
@@ -154,9 +131,33 @@ std::string join_paths(const std::vector<std::string> &paths) {
154131 return p;
155132}
156133
157- char * unescape_string (Allocator &al, LCompilers::Str &s) {
158- std::string x;
159- for (size_t idx=0 ; idx < s.size (); idx++) {
134+ std::string str_escape_c (const std::string &s) {
135+ std::ostringstream o;
136+ for (auto c = s.cbegin (); c != s.cend (); c++) {
137+ switch (*c) {
138+ case ' "' : o << " \\\" " ; break ;
139+ case ' \\ ' : o << " \\\\ " ; break ;
140+ case ' \b ' : o << " \\ b" ; break ;
141+ case ' \f ' : o << " \\ f" ; break ;
142+ case ' \n ' : o << " \\ n" ; break ;
143+ case ' \r ' : o << " \\ r" ; break ;
144+ case ' \t ' : o << " \\ t" ; break ;
145+ default :
146+ if (' \x00 ' <= *c && *c <= ' \x1f ' ) {
147+ o << " \\ u"
148+ << std::hex << std::setw (4 ) << std::setfill (' 0' ) << static_cast <int >(*c);
149+ } else {
150+ o << *c;
151+ }
152+ }
153+ }
154+ return o.str ();
155+ }
156+
157+ char * str_unescape_c (Allocator &al, LCompilers::Str &s) {
158+ std::string x = " " ;
159+ size_t idx = 0 ;
160+ for (; idx + 1 < s.size (); idx++) {
160161 if (s[idx] == ' \\ ' && s[idx+1 ] == ' \n ' ) { // continuation character
161162 idx++;
162163 } else if (s[idx] == ' \\ ' && s[idx+1 ] == ' n' ) {
@@ -187,6 +188,36 @@ char* unescape_string(Allocator &al, LCompilers::Str &s) {
187188 x += s[idx];
188189 }
189190 }
191+ if (idx < s.size ()) {
192+ x += s[idx];
193+ }
194+ return LCompilers::s2c (al, x);
195+ }
196+
197+ std::string str_escape_fortran_double_quote (const std::string &s) {
198+ std::ostringstream o;
199+ for (auto c = s.cbegin (); c != s.cend (); c++) {
200+ switch (*c) {
201+ case ' "' : o << " \"\" " ; break ;
202+ }
203+ }
204+ return o.str ();
205+ }
206+
207+ char * str_unescape_fortran (Allocator &al, LCompilers::Str &s, char ch) {
208+ std::string x = " " ;
209+ size_t idx = 0 ;
210+ for (; idx + 1 < s.size (); idx++) {
211+ if (s[idx] == ch && s[idx + 1 ] == ch) {
212+ x += s[idx];
213+ idx++;
214+ } else {
215+ x += s[idx];
216+ }
217+ }
218+ if (idx < s.size ()) {
219+ x += s[idx];
220+ }
190221 return LCompilers::s2c (al, x);
191222}
192223
0 commit comments