Skip to content

Commit

Permalink
cpp: replace detail::unicode_GooString_to_ustring() by ustring::from_…
Browse files Browse the repository at this point in the history
…utf8()
  • Loading branch information
mpsuzuki committed Mar 25, 2018
1 parent 5e7aef9 commit 7404f5e
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 48 deletions.
16 changes: 8 additions & 8 deletions cpp/poppler-document.cpp
Expand Up @@ -342,7 +342,7 @@ ustring document::info_key(const std::string &key) const
return ustring();
}

return detail::unicode_GooString_to_ustring(goo_value.get());
return ustring::from_utf8(goo_value->getCString(), goo_value->getLength());
}

/**
Expand Down Expand Up @@ -433,7 +433,7 @@ ustring document::get_title() const
return ustring();
}

return detail::unicode_GooString_to_ustring(goo_title.get());
return ustring::from_utf8(goo_title->getCString(), goo_title->getLength());
}

/**
Expand Down Expand Up @@ -477,7 +477,7 @@ ustring document::get_author() const
return ustring();
}

return detail::unicode_GooString_to_ustring(goo_author.get());
return ustring::from_utf8(goo_author->getCString(), goo_author->getLength());
}

/**
Expand Down Expand Up @@ -521,7 +521,7 @@ ustring document::get_subject() const
return ustring();
}

return detail::unicode_GooString_to_ustring(goo_subject.get());
return ustring::from_utf8(goo_subject->getCString(), goo_subject->getLength());
}

/**
Expand Down Expand Up @@ -565,7 +565,7 @@ ustring document::get_keywords() const
return ustring();
}

return detail::unicode_GooString_to_ustring(goo_keywords.get());
return ustring::from_utf8(goo_keywords->getCString(), goo_keywords->getLength());
}

/**
Expand Down Expand Up @@ -609,7 +609,7 @@ ustring document::get_creator() const
return ustring();
}

return detail::unicode_GooString_to_ustring(goo_creator.get());
return ustring::from_utf8(goo_creator->getCString(), goo_creator->getLength());
}

/**
Expand Down Expand Up @@ -653,7 +653,7 @@ ustring document::get_producer() const
return ustring();
}

return detail::unicode_GooString_to_ustring(goo_producer.get());
return ustring::from_utf8(goo_producer->getCString(), goo_producer->getLength());
}

/**
Expand Down Expand Up @@ -838,7 +838,7 @@ ustring document::metadata() const
{
std::unique_ptr<GooString> md(d->doc->getCatalog()->readMetadata());
if (md.get()) {
return detail::unicode_GooString_to_ustring(md.get());
return ustring::from_utf8(md->getCString(), md->getLength());
}
return ustring();
}
Expand Down
2 changes: 1 addition & 1 deletion cpp/poppler-embedded-file.cpp
Expand Up @@ -88,7 +88,7 @@ std::string embedded_file::name() const
ustring embedded_file::description() const
{
GooString *goo = d->file_spec->getDescription();
return goo ? detail::unicode_GooString_to_ustring(goo) : ustring();
return goo ? ustring::from_utf8(goo->getCString(), goo->getLength()) : ustring();
}

/**
Expand Down
6 changes: 3 additions & 3 deletions cpp/poppler-page.cpp
Expand Up @@ -163,7 +163,7 @@ ustring page::label() const
return ustring();
}

return detail::unicode_GooString_to_ustring(&goo);
return ustring::from_utf8(goo.getCString(), goo.getLength());
}

/**
Expand Down Expand Up @@ -285,7 +285,7 @@ ustring page::text(const rectf &r, text_layout_enum layout_mode) const
} else {
s.reset(td.getText(r.left(), r.top(), r.right(), r.bottom()));
}
return ustring::from_utf8(s->getCString());
return ustring::from_utf8(s->getCString(), s->getLength());
}

/*
Expand Down Expand Up @@ -355,7 +355,7 @@ std::vector<text_box> page::text_list() const
TextWord *word = word_list->get(i);

std::unique_ptr<GooString> gooWord{word->getText()};
ustring ustr = detail::unicode_GooString_to_ustring(gooWord.get());
ustring ustr = ustring::from_utf8(gooWord->getCString(), gooWord->getLength());

double xMin, yMin, xMax, yMax;
word->getBBox(&xMin, &yMin, &xMax, &yMax);
Expand Down
35 changes: 0 additions & 35 deletions cpp/poppler-private.cpp
Expand Up @@ -56,41 +56,6 @@ rectf detail::pdfrectangle_to_rectf(const PDFRectangle &pdfrect)
return rectf(pdfrect.x1, pdfrect.y1, pdfrect.x2 - pdfrect.x1, pdfrect.y2 - pdfrect.y1);
}

ustring detail::unicode_GooString_to_ustring(GooString *str)
{
const char *data = str->getCString();
const int len = str->getLength();

int i = 0;
bool is_unicode = false;
if ((data[0] & 0xff) == 0xfe && (len > 1 && (data[1] & 0xff) == 0xff)) {
is_unicode = true;
i = 2;
}
ustring::size_type ret_len = len - i;
if (is_unicode) {
ret_len >>= 1;
}
ustring ret(ret_len, 0);
size_t ret_index = 0;
ustring::value_type u;
if (is_unicode) {
while (i < len) {
u = ((data[i] & 0xff) << 8) | (data[i + 1] & 0xff);
i += 2;
ret[ret_index++] = u;
}
} else {
while (i < len) {
u = data[i] & 0xff;
++i;
ret[ret_index++] = u;
}
}

return ret;
}

ustring detail::unicode_to_ustring(const Unicode *u, int length)
{
ustring str(length * 2, 0);
Expand Down
1 change: 0 additions & 1 deletion cpp/poppler-private.h
Expand Up @@ -49,7 +49,6 @@ void error_function(void *data, ErrorCategory category, Goffset pos, char *msg);

rectf pdfrectangle_to_rectf(const PDFRectangle &pdfrect);

ustring unicode_GooString_to_ustring(GooString *str);
ustring unicode_to_ustring(const Unicode *u, int length);
GooString* ustring_to_unicode_GooString(const ustring &str);

Expand Down

0 comments on commit 7404f5e

Please sign in to comment.