-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathstringTools.h
More file actions
52 lines (44 loc) · 1.06 KB
/
stringTools.h
File metadata and controls
52 lines (44 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
* stringTools.h
*
* Created on: Dec 18, 2014
* Author: tobias
*/
#ifndef STRINGTOOLS_H_
#define STRINGTOOLS_H_
#include <string>
/**
* replaces every non-ASCII character in s with an escape sequence containing the hexadecimal representation of it's value.
*
* Additionally backslashes are escaped too, since this character is used to initiate an escape sequence.
*
* The value of a valid ASCII is [0, 127].
*
* replacement map:
* ----------------
* "\" --> "\\"
* non-ASCII --> "\x{2 digit hex value}"
* ASCII --> ASCII
*
*/
std::string escape_non_ascii(const std::string &s);
/**
* unescapes escaped (non-)ASCII characters.
*
* replacement map:
* ----------------
* "\\" --> "\"
* "\x{2 hex digits}" --> character
* ASCII --> ASCII
* everything else --> exception
*
* @see escape_non_ascii
*
*/
std::string unescape_non_ascii(const std::string &s);
/**
* @brief stem_filename
* stems the filename from a path
*/
std::string stem_filename(const std::string &s);
#endif /* STRINGTOOLS_H_ */