KSeExpr 6.0.0.0
StringUtils.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2011-2019 Disney Enterprises, Inc.
2// SPDX-License-Identifier: LicenseRef-Apache-2.0
3// SPDX-FileCopyrightText: 2020 L. E. Segovia <amy@amyspark.me>
4// SPDX-License-Identifier: GPL-3.0-or-later
5
6#ifndef StringUtils_h
7#define StringUtils_h
8
9#include <string>
10
13inline std::string unescapeString(const std::string& string) {
14 std::string output(string);
15 int index = 0;
16 bool special = false;
17 for (char c : string) {
18 if (special == true) {
19 special = false;
20 switch (c) {
21 case 'n': output[index++] = '\n'; break;
22 case 'r': output[index++] = '\r'; break;
23 case 't': output[index++] = '\t'; break;
24 case '\\': output[index++] = '\\'; break;
25 case '"': output[index++] = '\"'; break;
26 default:
27 // leave the escape sequence as it was
28 output[index++] = '\\';
29 output[index++] = c;
30 }
31 } else {
32 if (c == '\\') {
33 special = true;
34 } else {
35 output[index++] = c;
36 }
37 }
38 }
39 output.resize(index);
40 return output;
41}
42
43#endif
std::string unescapeString(const std::string &string)
Definition StringUtils.h:13