Commit cfb4f5df authored by Pino Toscano's avatar Pino Toscano
Browse files

[cpp] add a byte_array typedef, and use it for utf8 string data

parent 2d13ac31
......@@ -47,27 +47,21 @@ ustring::~ustring()
{
}
char* ustring::to_utf_8(int *length) const
byte_array ustring::to_utf_8() const
{
if (!size()) {
if (length) {
*length = 0;
}
return 0;
return byte_array();
}
const value_type *me = data();
const size_t len = size() * 2 + 2;
char *str = new char[len];
byte_array str(len);
str[0] = 0xfe;
str[1] = 0xff;
for (size_t i = 0; i < size(); ++i, ++me) {
str[i * 2 + 2] = (*me & 0xff);
str[i * 2 + 3] = ((*me >> 8) & 0xff);
}
if (length) {
*length = len;
}
return str;
}
......
......@@ -34,6 +34,7 @@
#endif
#include <string>
#include <vector>
namespace poppler
{
......@@ -59,6 +60,8 @@ enum rotation_enum { rotate_0, rotate_90, rotate_180, rotate_270 };
enum page_box_enum { media_box, crop_box, bleed_box, trim_box, art_box };
typedef std::vector<char> byte_array;
class POPPLER_CPP_EXPORT ustring : public std::basic_string<unsigned short>
{
public:
......@@ -66,7 +69,7 @@ public:
ustring(size_type len, value_type ch);
~ustring();
char* to_utf_8(int *length = 0) const;
byte_array to_utf_8() const;
std::string to_latin1() const;
static ustring from_utf_8(const char *str, int len = -1);
......
......@@ -63,8 +63,7 @@ ustring detail::unicode_to_ustring(const Unicode *u, int length)
GooString* detail::ustring_to_unicode_GooString(const ustring &str)
{
char *u = str.to_utf_8();
GooString *goo = new GooString(u);
delete [] u;
const byte_array utf8_data = str.to_utf_8();
GooString *goo = new GooString(utf8_data.data());
return goo;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment