}
/**
- *
+ *
*/
static vector<string>
split_whitespace( const string& str, int maxsplit )
}
/**
- *
+ *
*/
vector<string>
split( const string& str, const char* sep, int maxsplit )
return do_strip( s, BOTHSTRIP );
}
- string
+ string
rpad( const string & s, string::size_type length, char c )
{
string::size_type l = s.length();
return reply.append( length-l, c );
}
- string
+ string
lpad( const string & s, size_t length, char c )
{
string::size_type l = s.length();
string result; // reserve size of 's'?
string::const_iterator it = s.begin(),
end = s.end();
-
+
// advance to first non-space char - simplifes logic in main loop,
- // since we can always prepend a single space when we see a
+ // since we can always prepend a single space when we see a
// space -> non-space transition
for (; (it != end) && isspace(*it); ++it) { /* nothing */ }
-
+
bool lastWasSpace = false;
for (; it != end; ++it) {
char c = *it;
lastWasSpace = true;
continue;
}
-
+
if (lastWasSpace) {
result.push_back(' ');
}
-
+
lastWasSpace = false;
result.push_back(c);
}
-
+
return result;
}
-
+
int to_int(const std::string& s, int base)
{
stringstream ss(s);
case 16: ss >> std::hex; break;
default: break;
}
-
+
int result;
ss >> result;
return result;
}
-
+
int compare_versions(const string& v1, const string& v2)
{
vector<string> v1parts(split(v1, "."));
// reached end - longer wins
return v1parts.size() - v2parts.size();
}
-
+
string join(const string_list& l, const string& joinWith)
{
string result;
result += joinWith;
}
}
-
+
return result;
}
-
+
string uppercase(const string &s) {
string rslt(s);
for(string::iterator p = rslt.begin(); p != rslt.end(); p++){
*p = tolower(*p);
}
}
-
+
#if defined(SG_WINDOWS)
#include <windows.h>
-
+
static WCharVec convertMultiByteToWString(DWORD encoding, const std::string& a)
{
WCharVec result;
DWORD flags = 0;
- int requiredWideChars = MultiByteToWideChar(encoding, flags,
+ int requiredWideChars = MultiByteToWideChar(encoding, flags,
a.c_str(), a.size(),
NULL, 0);
result.resize(requiredWideChars);
#ifdef SG_WINDOWS
DWORD flags = 0;
WCharVec wideString = convertMultiByteToWString(CP_ACP, a);
-
+
// convert down to UTF-8
std::vector<char> result;
int requiredUTF8Chars = WideCharToMultiByte(CP_UTF8, flags,
39, 40, 41, 42, 43, 44, 45, 46, 47, 48,
49, 50, 51, 127, 127, 127, 127, 127
};
-
-
+
+
static inline bool is_base64(unsigned char c) {
return (isalnum(c) || (c == '+') || (c == '/'));
}
int j = 0;
int in_ = 0;
unsigned char char_array_4[4], char_array_3[3];
-
+
while (in_len-- && ( encoded_string[in_] != '=')) {
if (is_whitespace( encoded_string[in_])) {
- in_++;
+ in_++;
continue;
}
-
+
if (!is_base64(encoded_string[in_])) {
break;
}
-
+
char_array_4[i++] = encoded_string[in_]; in_++;
if (i ==4) {
for (i = 0; i <4; i++)
char_array_4[i] = base64_decode_map[char_array_4[i]];
-
+
char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4);
char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2);
char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3];
-
+
for (i = 0; (i < 3); i++)
ret.push_back(char_array_3[i]);
i = 0;
}
}
-
+
if (i) {
for (j = i; j <4; j++)
char_array_4[j] = 0;
-
+
for (j = 0; j <4; j++)
char_array_4[j] = base64_decode_map[char_array_4[j]];
-
+
char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4);
char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2);
char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3];
-
+
for (j = 0; (j < i - 1); j++) ret.push_back(char_array_3[j]);
}
-}
+}
//------------------------------------------------------------------------------
const char hexChar[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
hex[i * 2] = hexChar[c >> 4];
hex[i * 2 + 1] = hexChar[c & 0x0f];
}
-
+
return hex;
}
SG_LOG(SG_IO, SG_WARN, "sanitizePrintfFormat: bad format string:" << input);
return string();
}
-
+
return input;
}
}
} // end namespace strutils
-
+
} // end namespace simgear