1 #ifndef AESALON_MISC_STRING_H
2 #define AESALON_MISC_STRING_H
7 #include "StreamAsString.h"
12 /** Generic string operations class. */
15 /** Returns true if a given position within a string is escaped.
16 @param string The string to check.
17 @param position The position within @a string to check.
18 @return True if the position is escaped, false otherwise.
20 static bool is_escaped(std::string string
, std::string::size_type position
);
21 /** Removes the escapes from a string. Turns '\n' into (char)10, for example.
22 @param string The string to de-escape.
23 @return @a string, de-escaped.
25 static std::string
remove_escapes(std::string string
);
26 /** Checks if a string begins with another string.
27 @param string The string to check.
28 @param beginning The beginning to check for.
29 @return True if @a string starts with @a beginning.
31 static bool begins_with(std::string string
, std::string beginning
);
33 template<typename Type
> static void to(std::string string
, Type
&instance
, bool hex
= false) {
34 std::istringstream
parser(string
);
35 if(hex
) parser
>> std::hex
>> instance
;
36 else parser
>> instance
;
38 template<typename Type
> static std::string
from(Type
&instance
) {
39 return Misc::StreamAsString() << instance
;
44 } // namespace Aesalon