BuildmLearn Toolkit  2.0.4
BuildmLearn Toolkit is an easy-to-use program that helps users make mobile apps without any knowledge of application development.
 All Classes Functions Enumerations Groups Pages
TextFactory Class Reference

Functionality for working with text. More...

#include <textfactory.h>

Collaboration diagram for TextFactory:
Collaboration graph

Static Public Member Functions

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...
 

Detailed Description

Functionality for working with text.

Definition at line 40 of file textfactory.h.

Member Function Documentation

static bool TextFactory::isCaseInsensitiveLessThan ( const QString &  lhs,
const QString &  rhs 
)
inlinestatic

Does case-insensitive comparison of two strings.

Parameters
lhsFirst string.
rhsSecond string.
Returns
Returns true if lhs is "smaller" than rhs.

Definition at line 50 of file textfactory.h.

50  {
51  return lhs.toLower() < rhs.toLower();
52  }
QDateTime TextFactory::parseDateTime ( const QString &  date_time)
static

Tries to parse input textual date/time representation.

Parameters
date_timeString 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.

43  {
44  QString date = date_time.simplified();
45  QStringList date_patterns;
46  QStringList timezone_offset_patterns;
47  QDateTime dt;
48  QTime time_zone_offset;
49  QLocale locale(QLocale::C);
50  bool positive_time_zone_offset = false;
51 
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";
57 
58  timezone_offset_patterns << "+hh:mm" << "-hh:mm" << "+hhmm" << "-hhmm" << "+hh" << "-hh";
59 
60  if (date.size() >= 5) {
61  foreach (const QString &pattern, timezone_offset_patterns) {
62  time_zone_offset = QTime::fromString(date.right(pattern.size()), pattern);
63 
64  if (time_zone_offset.isValid()) {
65  positive_time_zone_offset = pattern.at(0) == '+';
66  break;
67  }
68  }
69  }
70 
71  // Iterate over patterns and check if input date/time matches the pattern.
72  foreach (const QString &pattern, date_patterns) {
73  dt = locale.toDateTime(date.left(pattern.size()), pattern);
74 
75  if (dt.isValid()) {
76  // Make sure that this date/time is considered UTC.
77  dt.setTimeSpec(Qt::UTC);
78 
79  if (time_zone_offset.isValid()) {
80  // Time zone offset was detected.
81  if (positive_time_zone_offset) {
82  // Offset is positive, so we have to subtract it to get
83  // the original UTC.
84  return dt.addSecs(- QTime(0, 0, 0, 0).secsTo(time_zone_offset));
85  }
86  else {
87  // Vice versa.
88  return dt.addSecs(QTime(0, 0, 0, 0).secsTo(time_zone_offset));
89  }
90  }
91  else {
92  return dt;
93  }
94  }
95  }
96 
97  // Parsing failed, return invalid datetime.
98  return QDateTime();
99 }

Here is the caller graph for this function:

QDateTime TextFactory::parseDateTime ( qint64  milis_from_epoch)
static

Converts 1970-epoch miliseconds to date/time.

Parameters
milis_from_epochNumber of miliseconds.
Returns
This apparently returns date/time in localtime.

Definition at line 101 of file textfactory.cpp.

101  {
102  return QDateTime::fromMSecsSinceEpoch(milis_from_epoch);
103 }
QString TextFactory::shorten ( const QString &  input,
int  text_length_limit 
)
static

Shortens input string according to given length limit.

Parameters
inputInput string.
text_length_limitLimit length.
Returns
Returns shortened string.

Definition at line 105 of file textfactory.cpp.

105  {
106  if (input.size() > text_length_limit) {
107  return input.left(text_length_limit - ELLIPSIS_LENGTH) + QString(ELLIPSIS_LENGTH, '.');
108  }
109  else {
110  return input;
111  }
112 }

The documentation for this class was generated from the following files: