Re-implemented the TCPSocket classes, using getaddrinfo().
[aesalon.git] / src / misc / String.h
blob4a0400c375f7bb5211269a990f52f576cd32364b
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;
43 } // namespace Misc
44 } // namespace Aesalon
46 #endif