matrix-3ds-sdk/source/util.cpp

38 lines
846 B
C++
Raw Normal View History

2019-10-17 10:45:55 +02:00
#include "util.h"
#include <string>
#include <sstream>
2019-10-18 21:22:10 +02:00
#include <3ds.h>
2019-10-21 10:15:09 +02:00
#include <jansson.h>
2019-10-17 10:45:55 +02:00
// from http://www.zedwood.com/article/cpp-urlencode-function
std::string urlencode(std::string s) {
static const char lookup[]= "0123456789abcdef";
std::stringstream e;
for(int i = 0, ix = s.length(); i < ix; i++) {
const char& c = s[i];
if ( (48 <= c && c <= 57) ||//0-9
(65 <= c && c <= 90) ||//abc...xyz
(97 <= c && c <= 122) || //ABC...XYZ
(c=='-' || c=='_' || c=='.' || c=='~')
) {
e << c;
} else {
e << '%';
e << lookup[ (c&0xF0)>>4 ];
e << lookup[ (c&0x0F) ];
}
}
return e.str();
}
2019-10-18 21:22:10 +02:00
2019-10-21 10:15:09 +02:00
char* json_object_get_string_value(json_t* obj, const char* key) {
if (!obj) {
return NULL;
}
json_t* keyObj = json_object_get(obj, key);
if (!keyObj) {
return NULL;
}
return (char*)json_string_value(keyObj);
}