Commit 9c8d0511 authored by Oliver Sander's avatar Oliver Sander Committed by Albert Astals Cid

Implement UnicodeParsedString for std::string

parent be450045
......@@ -173,7 +173,9 @@ public:
bool endsWith(const char *suffix) const;
bool hasUnicodeMarker() const { return size() >= 2 && (*this)[0] == '\xfe' && (*this)[1] == '\xff'; }
static bool hasUnicodeMarker(const std::string& s) { return s.size() >= 2 && s[0] == '\xfe' && s[1] == '\xff'; }
bool hasUnicodeMarkerLE() const { return size() >= 2 && (*this)[0] == '\xff' && (*this)[1] == '\xfe'; }
static bool hasUnicodeMarkerLE(const std::string& s) { return s.size() >= 2 && s[0] == '\xff' && s[1] == '\xfe'; }
bool hasJustUnicodeMarker() const { return size() == 2 && hasUnicodeMarker(); }
void prependUnicodeMarker();
......
......@@ -59,12 +59,12 @@
#include "Lexer.h"
//return a newly allocated char* containing an UTF16BE string of size length
char* pdfDocEncodingToUTF16 (const GooString* orig, int* length)
char* pdfDocEncodingToUTF16 (const std::string& orig, int* length)
{
//double size, a unicode char takes 2 char, add 2 for the unicode marker
*length = 2+2*orig->getLength();
*length = 2+2*orig.size();
char *result = new char[(*length)];
const char *cstring = orig->c_str();
const char *cstring = orig.c_str();
//unicode marker
result[0] = '\xfe';
result[1] = '\xff';
......@@ -80,7 +80,7 @@ char* pdfDocEncodingToUTF16 (const GooString* orig, int* length)
static GooString *convertToUtf16(GooString *pdfDocEncodingString)
{
int tmp_length;
char* tmp_str = pdfDocEncodingToUTF16(pdfDocEncodingString, &tmp_length);
char* tmp_str = pdfDocEncodingToUTF16(pdfDocEncodingString->toStr(), &tmp_length);
delete pdfDocEncodingString;
pdfDocEncodingString = new GooString(tmp_str, tmp_length);
delete [] tmp_str;
......@@ -877,7 +877,7 @@ GooString* FormField::getFullyQualifiedName() {
full_name->insert(0, parent_name->c_str() + 2, parent_name->getLength() - 2); // Remove the unicode BOM
} else {
int tmp_length;
char* tmp_str = pdfDocEncodingToUTF16(parent_name, &tmp_length);
char* tmp_str = pdfDocEncodingToUTF16(parent_name->toStr(), &tmp_length);
full_name->insert(0, tmp_str + 2, tmp_length - 2); // Remove the unicode BOM
delete [] tmp_str;
}
......@@ -901,7 +901,7 @@ GooString* FormField::getFullyQualifiedName() {
full_name->append(partialName->c_str() + 2, partialName->getLength() - 2); // Remove the unicode BOM
} else {
int tmp_length;
char* tmp_str = pdfDocEncodingToUTF16(partialName, &tmp_length);
char* tmp_str = pdfDocEncodingToUTF16(partialName->toStr(), &tmp_length);
full_name->append(tmp_str + 2, tmp_length - 2); // Remove the unicode BOM
delete [] tmp_str;
}
......@@ -1189,7 +1189,7 @@ FormFieldText::FormFieldText(PDFDoc *docA, Object &&dictObj, const Ref refA, For
} else if (obj1.getString()->getLength() > 0) {
//non-unicode string -- assume pdfDocEncoding and try to convert to UTF16BE
int tmp_length;
char* tmp_str = pdfDocEncodingToUTF16(obj1.getString(), &tmp_length);
char* tmp_str = pdfDocEncodingToUTF16(obj1.getString()->toStr(), &tmp_length);
content = new GooString(tmp_str, tmp_length);
delete [] tmp_str;
}
......
......@@ -24,12 +24,14 @@
#ifndef PDFDOCENCODING_H
#define PDFDOCENCODING_H
#include <string>
#include "CharTypes.h"
class GooString;
extern const Unicode pdfDocEncoding[256];
char* pdfDocEncodingToUTF16 (const GooString* orig, int* length);
char* pdfDocEncodingToUTF16 (const std::string& orig, int* length);
#endif
......@@ -97,12 +97,16 @@ namespace Debug {
}
QString UnicodeParsedString(const GooString *s1) {
if ( !s1 || s1->getLength() == 0 )
return (s1) ? UnicodeParsedString(s1->toStr()) : QString();
}
QString UnicodeParsedString(const std::string& s1) {
if ( s1.empty() )
return QString();
if ( s1->hasUnicodeMarker() || s1->hasUnicodeMarkerLE() )
if ( GooString::hasUnicodeMarker(s1) || GooString::hasUnicodeMarkerLE(s1) )
{
return QString::fromUtf16(reinterpret_cast<const ushort *>(s1->c_str()), s1->getLength() / 2);
return QString::fromUtf16(reinterpret_cast<const ushort *>(s1.c_str()), s1.size() / 2);
}
else
{
......
......@@ -71,6 +71,8 @@ namespace Poppler {
POPPLER_QT5_EXPORT QString UnicodeParsedString(const GooString *s1);
POPPLER_QT5_EXPORT QString UnicodeParsedString(const std::string& s1);
POPPLER_QT5_EXPORT GooString *QStringToUnicodeGooString(const QString &s);
POPPLER_QT5_EXPORT GooString *QStringToGooString(const QString &s);
......
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