From f2d74fb7a7f37ec8de6586a1a2c1672934b2a2eb Mon Sep 17 00:00:00 2001 From: Jakub Kucharski Date: Thu, 19 May 2016 16:11:04 +0200 Subject: [PATCH] cpp: switched from detail::convert_date() to core's dateStringToTime() --- cpp/poppler-document.cpp | 4 +++- cpp/poppler-embedded-file.cpp | 6 ++++-- cpp/poppler-global.cpp | 6 +++++- cpp/poppler-private.cpp | 25 +------------------------ cpp/poppler-private.h | 3 +-- 5 files changed, 14 insertions(+), 30 deletions(-) diff --git a/cpp/poppler-document.cpp b/cpp/poppler-document.cpp index 1c24b47..3b2c066 100644 --- a/cpp/poppler-document.cpp +++ b/cpp/poppler-document.cpp @@ -1,5 +1,6 @@ /* * Copyright (C) 2009-2011, Pino Toscano + * Copyright (C) 2016 Jakub Kucharski * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -27,6 +28,7 @@ #include "poppler-toc-private.h" #include "Catalog.h" +#include "DateInfo.h" #include "ErrorCodes.h" #include "GlobalParams.h" #include "Outline.h" @@ -379,7 +381,7 @@ time_type document::info_date(const std::string &key) const Object obj; time_type result = time_type(-1); if (info_dict->lookup(PSTR(key.c_str()), &obj)->isString()) { - result = detail::convert_date(obj.getString()->getCString()); + result = dateStringToTime(obj.getString()); } obj.free(); info.free(); diff --git a/cpp/poppler-embedded-file.cpp b/cpp/poppler-embedded-file.cpp index 2c5d077..f87649c 100644 --- a/cpp/poppler-embedded-file.cpp +++ b/cpp/poppler-embedded-file.cpp @@ -1,5 +1,6 @@ /* * Copyright (C) 2009-2011, Pino Toscano + * Copyright (C) 2016 Jakub Kucharski * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -25,6 +26,7 @@ #include "Stream.h" #include "Catalog.h" #include "FileSpec.h" +#include "DateInfo.h" using namespace poppler; @@ -107,7 +109,7 @@ int embedded_file::size() const time_type embedded_file::modification_date() const { GooString *goo = d->file_spec->getEmbeddedFile()->modDate(); - return goo ? detail::convert_date(goo->getCString()) : time_type(-1); + return goo ? dateStringToTime(goo) : time_type(-1); } /** @@ -117,7 +119,7 @@ time_type embedded_file::modification_date() const time_type embedded_file::creation_date() const { GooString *goo = d->file_spec->getEmbeddedFile()->createDate(); - return goo ? detail::convert_date(goo->getCString()) : time_type(-1); + return goo ? dateStringToTime(goo) : time_type(-1); } /** diff --git a/cpp/poppler-global.cpp b/cpp/poppler-global.cpp index b99259f..db2953e 100644 --- a/cpp/poppler-global.cpp +++ b/cpp/poppler-global.cpp @@ -3,6 +3,7 @@ * Copyright (C) 2010, Hib Eris * Copyright (C) 2014, 2015 Hans-Peter Deifel * Copyright (C) 2015, Tamas Szekeres + * Copyright (C) 2016 Jakub Kucharski * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -23,6 +24,8 @@ #include "poppler-private.h" +#include "DateInfo.h" + #include #include @@ -315,7 +318,8 @@ ustring ustring::from_latin1(const std::string &str) */ time_type poppler::convert_date(const std::string &date) { - return detail::convert_date(date.c_str()); + GooString gooDateStr(date.c_str()); + return dateStringToTime(&gooDateStr); } std::ostream& poppler::operator<<(std::ostream& stream, const byte_array &array) diff --git a/cpp/poppler-private.cpp b/cpp/poppler-private.cpp index 3c3fe95..4362319 100644 --- a/cpp/poppler-private.cpp +++ b/cpp/poppler-private.cpp @@ -2,6 +2,7 @@ * Copyright (C) 2009-2010, Pino Toscano * Copyright (C) 2013 Adrian Johnson * Copyright (C) 2014, Hans-Peter Deifel + * Copyright (C) 2016 Jakub Kucharski * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -20,7 +21,6 @@ #include "poppler-private.h" -#include "DateInfo.h" #include "GooString.h" #include "Page.h" @@ -115,26 +115,3 @@ GooString* detail::ustring_to_unicode_GooString(const ustring &str) GooString *goo = new GooString(&ba[0]); return goo; } - -time_type detail::convert_date(const char *date) -{ - int year, mon, day, hour, min, sec, tzHours, tzMins; - char tz; - - if (!parseDateString(date, &year, &mon, &day, &hour, &min, &sec, - &tz, &tzHours, &tzMins)) { - return time_type(-1); - } - - struct tm time; - time.tm_sec = sec; - time.tm_min = min; - time.tm_hour = hour; - time.tm_mday = day; - time.tm_mon = mon - 1; - time.tm_year = year - 1900; - time.tm_wday = -1; - time.tm_yday = -1; - time.tm_isdst = -1; - return mktime(&time); -} diff --git a/cpp/poppler-private.h b/cpp/poppler-private.h index 8d315c8..7d554d0 100644 --- a/cpp/poppler-private.h +++ b/cpp/poppler-private.h @@ -2,6 +2,7 @@ * Copyright (C) 2009, Pino Toscano * Copyright (C) 2013 Adrian Johnson * Copyright (C) 2014, Hans-Peter Deifel + * Copyright (C) 2016 Jakub Kucharski * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -50,8 +51,6 @@ ustring unicode_GooString_to_ustring(GooString *str); ustring unicode_to_ustring(const Unicode *u, int length); GooString* ustring_to_unicode_GooString(const ustring &str); -time_type convert_date(const char *date); - } template -- 2.8.2