Esempio n. 1
0
void CStdDeserializer::ReadStringUTF16(utf16string& str)
{
	uint32_t len;
	NumberU32_Unbounded("string length", len);
	str.resize(len); // TODO: should check len*2 <= bytes remaining in stream, before resizing
	Get((u8*)str.data(), len*2);
}
Esempio n. 2
0
// Print a UTF-16 string to a file
void Encoder::writeUtf16File(const char* filename, const utf16string& s)
{
    // Open the test file (will contain UTF-16 encoded text)
    // Because of conversions of newlines you cannot use wofstream - use an ofstream in binary mode.
    std::ofstream outFile(filename, std::ios::out | std::ios::binary);
    outFile.write((char *)s.c_str(), (std::streamsize)(s.length() * sizeof(utf8::uint16_t)));
    outFile.close();
}
Esempio n. 3
0
void CStdDeserializer::ReadStringUTF16(const char* name, utf16string& str)
{
	uint32_t len;
	NumberU32_Unbounded("string length", len);
	RequireBytesInStream(len*2);
	str.resize(len);
	Get(name, (u8*)str.data(), len*2);
}
Esempio n. 4
0
static jbyteArray doHttp(JNIEnv *env, const utf16string &url, CLowlaDBBson::ptr body) {
    jclass clazz = env->FindClass("io/lowla/lowladb/LDBClient");
    jmethodID mid = env->GetStaticMethodID(clazz, "doHttp", "(Ljava/lang/String;[B)[B");

    jstring jurl = env->NewStringUTF(url.c_str());
    jbyteArray jbody = nullptr;
    if (body) {
        utf16string json = lowladb_bson_to_json(body->data());
        const char *bytes = json.c_str();
        jbody = env->NewByteArray(strlen(bytes));
        env->SetByteArrayRegion(jbody, 0, strlen(bytes), (const jbyte *)bytes);
    }

    __android_log_print(ANDROID_LOG_VERBOSE, "Lowla", "Making http request to %s", url.c_str());

    return (jbyteArray)env->CallStaticObjectMethod(clazz, mid, jurl, jbody);
}
Esempio n. 5
0
utf16string utf16string::replace(utf16string const& target, utf16string const &replacement) const
{
	//UTF8
	std::string str(m_data->str());
	if (target.m_data->str().empty()) {
		return utf16string(str.c_str());
	}

	size_t start_pos = 0;
	while((start_pos = str.find(target.m_data->str(), start_pos)) != std::string::npos) {
		str.replace(start_pos, target.m_data->str().length(), replacement.m_data->str());
		start_pos += replacement.length(); // In case 'to' contains 'from', like replacing 'x' with 'yx'
	}

	return utf16string(str.c_str());
}
Esempio n. 6
0
bool operator<(const utf16string &lhs, const utf16string &rhs)
{
    return lhs.compareTo(rhs) < 0;
}
Esempio n. 7
0
bool operator==(const utf16string &lhs, const char *rhs)
{
    return lhs.equals(rhs);
}
Esempio n. 8
0
bool operator==(const char *lhs, const utf16string &rhs)
{
    return rhs.equals(lhs);
}