SeExpr

StringUtils.h
Go to the documentation of this file.
1 /*
2 Copyright Disney Enterprises, Inc. All rights reserved.
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License
6 and the following modification to it: Section 6 Trademarks.
7 deleted and replaced with:
8
9 6. Trademarks. This License does not grant permission to use the
10 trade names, trademarks, service marks, or product names of the
11 Licensor and its affiliates, except as required for reproducing
12 the content of the NOTICE file.
13
14 You may obtain a copy of the License at
15 http://www.apache.org/licenses/LICENSE-2.0
16 */
17 #ifndef StringUtils_h
18 #define StringUtils_h
19
20 #include <string>
21
24 inline std::string unescapeString(const std::string& string) {
25 std::string output(string);
26 int index = 0;
27 bool special = false;
28 for (char c : string) {
29 if (c == '\\') {
30 special = true;
31 } else {
32 if (special == true) {
33 special = false;
34 switch (c) {
35 case 'n': output[index++] = '\n'; break;
36 case 'r': output[index++] = '\r'; break;
37 case 't': output[index++] = '\t'; break;
38 case '\\': output[index++] = '\\'; break;
39 case '"': output[index++] = '\"'; break;
40 default:
41 // leave the escape sequence as it was
42 output[index++] = '\\';
43 output[index++] = c;
44 }
45 } else {
46 output[index++] = c;
47 }
48 }
49 }
50 output.resize(index);
51 return output;
52 }
53
54 #endif
unescapeString
std::string unescapeString(const std::string &string)
Definition: StringUtils.h:24
index
The result is computed int int< br >< div style="margin-left: 40px;"> Picks values randomly between loRange and hiRange based on supplied index(which is automatically hashed). &nbsp