@@ -43,6 +43,126 @@ namespace Utils
4343 return values;
4444 }
4545
46+ std::string encodeHtmlSymbols (const std::string &str)
47+ {
48+ std::string buf;
49+ buf.reserve (str.length () );
50+
51+ for (size_t pos = 0 ; pos < str.length (); ++pos)
52+ {
53+ switch (str[pos])
54+ {
55+ case ' &' : buf.append (" &" ); break ;
56+ case ' \" ' : buf.append (" "" ); break ;
57+ case ' \' ' : buf.append (" '" ); break ;
58+ case ' <' : buf.append (" <" ); break ;
59+ case ' >' : buf.append (" >" ); break ;
60+ default : buf.push_back (str[pos]); break ;
61+ }
62+ }
63+
64+ return buf;
65+ }
66+
67+ std::string binToHexString (const char *binData, const size_t dataSize)
68+ {
69+ std::string str (dataSize * 2 , 0 );
70+
71+ const uint8_t *bin = reinterpret_cast <const uint8_t *>(binData);
72+
73+ const char hexDigits[] = { " 0123456789abcdef" };
74+
75+ for (size_t i = dataSize - 1 ; std::numeric_limits<size_t >::max () != i; --i)
76+ {
77+ str[(i << 1 ) + 0 ] = hexDigits[bin[i] >> 4 ];
78+ str[(i << 1 ) + 1 ] = hexDigits[bin[i] & 0x0F ];
79+ }
80+
81+ return str;
82+ }
83+
84+ static unsigned char hexStringToBinEncodeSymbol (const char c)
85+ {
86+ if (c >= ' 0' && c <= ' 9' )
87+ {
88+ return c - 0x30 ;
89+ }
90+ else if (c >= ' a' && c <= ' f' )
91+ {
92+ return c - 0x57 ;
93+ }
94+ else if (c >= ' A' && c <= ' F' )
95+ {
96+ return c - 0x37 ;
97+ }
98+
99+ return 0 ;
100+ }
101+
102+ std::string hexStringToBin (const std::string &hexStr)
103+ {
104+ std::string bin (hexStr.length () / 2 , 0 );
105+
106+ for (size_t i = 0 ; i < bin.length (); ++i)
107+ {
108+ char a = hexStr[(i << 1 ) + 0 ];
109+ char b = hexStr[(i << 1 ) + 1 ];
110+
111+ bin[i] = (
112+ (hexStringToBinEncodeSymbol (a) << 4 ) | hexStringToBinEncodeSymbol (b)
113+ );
114+ }
115+
116+ return bin;
117+ }
118+
119+ unsigned long long htonll (const unsigned long long src)
120+ {
121+ enum Endianness {
122+ INIT = 0 ,
123+ LITE = 1 ,
124+ BIGE = 2
125+ };
126+
127+ static int endian = Endianness::INIT;
128+
129+ union {
130+ unsigned long long ull;
131+ unsigned char c[8 ];
132+ } x;
133+
134+ if (endian == Endianness::INIT)
135+ {
136+ x.ull = 0x01 ;
137+ endian = (x.c [7 ] == 0x01ULL ) ? Endianness::BIGE : Endianness::LITE;
138+ }
139+
140+ if (endian == Endianness::BIGE)
141+ {
142+ return src;
143+ }
144+
145+ x.ull = src;
146+
147+ unsigned char c;
148+
149+ c = x.c [0 ]; x.c [0 ] = x.c [7 ]; x.c [7 ] = c;
150+ c = x.c [1 ]; x.c [1 ] = x.c [6 ]; x.c [6 ] = c;
151+ c = x.c [2 ]; x.c [2 ] = x.c [5 ]; x.c [5 ] = c;
152+ c = x.c [3 ]; x.c [3 ] = x.c [4 ]; x.c [4 ] = c;
153+
154+ return x.ull ;
155+ }
156+
157+ std::string getUniqueName ()
158+ {
159+ size_t time = std::chrono::high_resolution_clock::now ().time_since_epoch ().count ();
160+
161+ time = htonll (time);
162+
163+ return binToHexString (reinterpret_cast <const char *>(&time), sizeof (time) );
164+ }
165+
46166 char *stlStringToPChar (const std::string &str)
47167 {
48168 const size_t length = str.length ();
@@ -146,7 +266,7 @@ namespace Utils
146266 const size_t str_mon_length = 64 ;
147267 std::vector<char > s_mon (str_mon_length);
148268
149- struct ::tm tc = { 0 };
269+ struct ::tm tc = { 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 };
150270
151271 // Parse RFC 822
152272 #ifdef WIN32
0 commit comments