Continued ripping up the source.
[aesalon.git] / monitor / src / misc / String.h
blob1d977c75d89e6bdf34b7ca74db414a541bbfc110
1 #ifndef AESALON_MISC_STRING_H
2 #define AESALON_MISC_STRING_H
4 #include <string>
5 #include <ios>
7 #include "StreamAsString.h"
9 namespace Aesalon {
10 namespace Misc {
12 /** Generic string operations class. */
13 class String {
14 public:
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;
42 /** Strips whitespace from the beginning of a string.
43 @param string The string to strip the whitespace from.
44 @return @a string, without whitespace.
46 static std::string strip_whitespace(std::string string);
49 } // namespace Misc
50 } // namespace Aesalon
52 #endif