Functionality for working with text.
More...
#include <textfactory.h>
|
static bool | isCaseInsensitiveLessThan (const QString &lhs, const QString &rhs) |
| Does case-insensitive comparison of two strings. More...
|
|
static QDateTime | parseDateTime (const QString &date_time) |
| Tries to parse input textual date/time representation. More...
|
|
static QDateTime | parseDateTime (qint64 milis_from_epoch) |
| Converts 1970-epoch miliseconds to date/time. More...
|
|
static QString | shorten (const QString &input, int text_length_limit) |
| Shortens input string according to given length limit. More...
|
|
Functionality for working with text.
Definition at line 40 of file textfactory.h.
static bool TextFactory::isCaseInsensitiveLessThan |
( |
const QString & |
lhs, |
|
|
const QString & |
rhs |
|
) |
| |
|
inlinestatic |
Does case-insensitive comparison of two strings.
- Parameters
-
lhs | First string. |
rhs | Second string. |
- Returns
- Returns true if lhs is "smaller" than rhs.
Definition at line 50 of file textfactory.h.
51 return lhs.toLower() < rhs.toLower();
QDateTime TextFactory::parseDateTime |
( |
const QString & |
date_time | ) |
|
|
static |
Tries to parse input textual date/time representation.
- Parameters
-
date_time | String of date/time to parse. |
- Returns
- Returns invalid date/time if processing fails.
- Note
- This method tries to always return time in UTC+00:00.
Definition at line 43 of file textfactory.cpp.
44 QString date = date_time.simplified();
45 QStringList date_patterns;
46 QStringList timezone_offset_patterns;
48 QTime time_zone_offset;
49 QLocale locale(QLocale::C);
50 bool positive_time_zone_offset =
false;
52 date_patterns <<
"yyyy-MM-ddTHH:mm:ss" <<
"MMM dd yyyy hh:mm:ss" <<
53 "MMM d yyyy hh:mm:ss" <<
"ddd, dd MMM yyyy HH:mm:ss" <<
54 "dd MMM yyyy" <<
"yyyy-MM-dd HH:mm:ss.z" <<
"yyyy-MM-dd" <<
55 "yyyy" <<
"yyyy-MM" <<
"yyyy-MM-dd" <<
"yyyy-MM-ddThh:mm" <<
56 "yyyy-MM-ddThh:mm:ss";
58 timezone_offset_patterns <<
"+hh:mm" <<
"-hh:mm" <<
"+hhmm" <<
"-hhmm" <<
"+hh" <<
"-hh";
60 if (date.size() >= 5) {
61 foreach (
const QString &pattern, timezone_offset_patterns) {
62 time_zone_offset = QTime::fromString(date.right(pattern.size()), pattern);
64 if (time_zone_offset.isValid()) {
65 positive_time_zone_offset = pattern.at(0) ==
'+';
72 foreach (
const QString &pattern, date_patterns) {
73 dt = locale.toDateTime(date.left(pattern.size()), pattern);
77 dt.setTimeSpec(Qt::UTC);
79 if (time_zone_offset.isValid()) {
81 if (positive_time_zone_offset) {
84 return dt.addSecs(- QTime(0, 0, 0, 0).secsTo(time_zone_offset));
88 return dt.addSecs(QTime(0, 0, 0, 0).secsTo(time_zone_offset));
QDateTime TextFactory::parseDateTime |
( |
qint64 |
milis_from_epoch | ) |
|
|
static |
Converts 1970-epoch miliseconds to date/time.
- Parameters
-
milis_from_epoch | Number of miliseconds. |
- Returns
- This apparently returns date/time in localtime.
Definition at line 101 of file textfactory.cpp.
102 return QDateTime::fromMSecsSinceEpoch(milis_from_epoch);
QString TextFactory::shorten |
( |
const QString & |
input, |
|
|
int |
text_length_limit |
|
) |
| |
|
static |
Shortens input string according to given length limit.
- Parameters
-
input | Input string. |
text_length_limit | Limit length. |
- Returns
- Returns shortened string.
Definition at line 105 of file textfactory.cpp.
106 if (input.size() > text_length_limit) {
107 return input.left(text_length_limit - ELLIPSIS_LENGTH) + QString(ELLIPSIS_LENGTH,
'.');
The documentation for this class was generated from the following files: