mirror of https://github.com/kiwix/libkiwix.git
Merge branch 'master' of ssh://git.code.sf.net/p/kiwix/kiwix
This commit is contained in:
commit
552d123b64
|
@ -33,6 +33,38 @@ const char *nsStringToCString(const nsAString &str) {
|
|||
return strdup(cStr);
|
||||
}
|
||||
|
||||
std::string nsStringToString(const nsEmbedString &str) {
|
||||
#ifdef _WIN32
|
||||
PRUnichar *start = (PRUnichar *)str.get();
|
||||
PRUnichar *end = start + str.Length();
|
||||
wchar_t wca[4096];
|
||||
wchar_t *wstart = wca;
|
||||
wchar_t *wpr = wstart;
|
||||
|
||||
for(; start < end; ++start)
|
||||
{
|
||||
*wstart = (wchar_t) *start;
|
||||
++wstart;
|
||||
}
|
||||
*wstart = 0;
|
||||
|
||||
std::string ptr;
|
||||
ptr.resize(4096);
|
||||
size_t size = wcstombs((char*)ptr.data(), wpr, 4096);
|
||||
ptr.resize(size);
|
||||
|
||||
return ptr;
|
||||
#else
|
||||
const char *cStr;
|
||||
nsCString tmpStr;
|
||||
|
||||
CopyUTF16toUTF8(str, tmpStr);
|
||||
NS_CStringGetData(tmpStr, &cStr);
|
||||
return std::string(cStr);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
const char *nsStringToUTF8(const nsAString &str) {
|
||||
const char *cStr;
|
||||
nsCString tmpStr;
|
||||
|
|
|
@ -20,14 +20,22 @@
|
|||
#ifndef KIWIX_COMPONENTTOOLS_H
|
||||
#define KIWIX_COMPONENTTOOLS_H
|
||||
|
||||
#include<string>
|
||||
|
||||
#ifdef __APPLE__
|
||||
#include <stdint.h>
|
||||
typedef uint16_t char16_t;
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
|
||||
#include "nsStringAPI.h"
|
||||
#include "nsEmbedString.h"
|
||||
|
||||
const char *nsStringToCString(const nsAString &str);
|
||||
std::string nsStringToString(const nsEmbedString &str);
|
||||
const char *nsStringToUTF8(const nsAString &str);
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue