Skip to content

Commit 0102452

Browse files
author
Daniel Kroening
committed
move escape(s) to string_utils
1 parent 10aeae8 commit 0102452

File tree

5 files changed

+22
-18
lines changed

5 files changed

+22
-18
lines changed

src/util/format_expr.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ Author: Daniel Kroening, [email protected]
1818
#include "format_type.h"
1919
#include "ieee_float.h"
2020
#include "invariant.h"
21-
#include "lispexpr.h"
2221
#include "mp_arith.h"
2322
#include "rational.h"
2423
#include "rational_tools.h"
2524
#include "std_code.h"
2625
#include "std_expr.h"
2726
#include "string2int.h"
27+
#include "string_utils.h"
2828

2929
#include <ostream>
3030
#include <stack>

src/util/lispexpr.cpp

+2-15
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ Author: Daniel Kroening, [email protected]
88

99
#include "lispexpr.h"
1010

11+
#include "string_utils.h"
12+
1113
#include <iostream>
1214

1315
std::string lispexprt::expr2string() const
@@ -147,21 +149,6 @@ bool lispexprt::parse(
147149
return false;
148150
}
149151

150-
std::string escape(const std::string &s)
151-
{
152-
std::string result;
153-
154-
for(std::size_t i=0; i<s.size(); i++)
155-
{
156-
if(s[i]=='\\' || s[i]=='"')
157-
result+='\\';
158-
159-
result+=s[i];
160-
}
161-
162-
return result;
163-
}
164-
165152
int test_lispexpr()
166153
{
167154
std::string line;

src/util/lispexpr.h

-2
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,6 @@ inline std::ostream &operator<<(
9999
return out << expr.expr2string();
100100
}
101101

102-
std::string escape(const std::string &s);
103-
104102
int test_lispexpr();
105103

106104
#endif // CPROVER_UTIL_LISPEXPR_H

src/util/string_utils.cpp

+15
Original file line numberDiff line numberDiff line change
@@ -133,3 +133,18 @@ std::string trim_from_last_delimiter(
133133
result=s.substr(0, index);
134134
return result;
135135
}
136+
137+
std::string escape(const std::string &s)
138+
{
139+
std::string result;
140+
141+
for(std::size_t i=0; i<s.size(); i++)
142+
{
143+
if(s[i]=='\\' || s[i]=='"')
144+
result+='\\';
145+
146+
result+=s[i];
147+
}
148+
149+
return result;
150+
}

src/util/string_utils.h

+4
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,8 @@ Stream &join_strings(
6363
return os;
6464
}
6565

66+
/// Generic escaping of strings; this is not meant to be a particular
67+
/// programming language.
68+
std::string escape(const std::string &);
69+
6670
#endif

0 commit comments

Comments
 (0)