Soprano  2.8.0
languagetag.h
Go to the documentation of this file.
1 /*
2  * This file is part of Soprano Project.
3  *
4  * Copyright (C) 2009 Greg Beauchesne <greg_b@vision-play.com>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public License
17  * along with this library; see the file COPYING.LIB. If not, write to
18  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  * Boston, MA 02110-1301, USA.
20  */
21 
22 #ifndef SOPRANO_LANGUAGETAG_H
23 #define SOPRANO_LANGUAGETAG_H
24 
25 #include <QtCore/QSharedDataPointer>
26 #include <QtCore/QTextStream>
27 #include <QtCore/QLocale>
28 #include <QtCore/QFlags>
29 #include <QtCore/QMetaType>
30 
31 #include "soprano_export.h"
32 
33 namespace Soprano
34 {
45  {
46  public:
47  enum MatchFilter {
55  MatchFilterBasic = 0,
56 
62  MatchFilterExtended = 1
63  };
64 
70  enum LookupFlag {
71  LookupFlagNone = 0,
73  LookupFlagNoFallback = 1
74  };
75  Q_DECLARE_FLAGS(LookupFlags, LookupFlag)
76 
77  public:
86  LanguageTag();
87 
93  LanguageTag( const LanguageTag &other );
94 
100  LanguageTag( const char * tag );
101 
107  LanguageTag( const QLatin1String &tag );
108 
114  LanguageTag( const QString &tag );
115 
122  explicit LanguageTag( const QLocale &locale );
123 
131  LanguageTag( QLocale::Language lang, QLocale::Country country = QLocale::AnyCountry );
132 
136  ~LanguageTag();
138 
146  LanguageTag& operator=( const LanguageTag& other );
147 
154  bool operator==( const LanguageTag& other ) const;
155 
161  bool operator!=( const LanguageTag& other ) const;
162 
167  bool operator<( const LanguageTag& other ) const;
168 
173  bool operator<=( const LanguageTag& other ) const;
174 
179  bool operator>( const LanguageTag& other ) const;
180 
185  bool operator>=( const LanguageTag& other ) const;
186 
196  bool matches( const LanguageTag& range, MatchFilter scheme = MatchFilterBasic ) const;
198 
203 
207  bool isEmpty() const;
208 
224  bool isValid() const;
225 
229  QStringList subTags() const;
230 
232 
242  QString toString() const;
243 
250  QString toPrettyString() const;
251 
268  QLocale toLocale() const;
269 
277  inline operator QString() const { return toString(); }
279 
280 
321  static int lookup(
322  const QList<LanguageTag> & choices,
323  const QList<LanguageTag> & priority,
324  LookupFlags flags = LookupFlagNone,
325  MatchFilter scheme = MatchFilterBasic
326  );
327 
344  static int lookup(
345  const QList<LanguageTag> & choices,
346  const LanguageTag & priority,
347  LookupFlags flags = LookupFlagNone,
348  MatchFilter scheme = MatchFilterBasic
349  );
350 
351  private:
352  class Private;
354  };
355 
356  SOPRANO_EXPORT uint qHash( const LanguageTag& node );
357 }
358 
359 Q_DECLARE_METATYPE( Soprano::LanguageTag )
360 Q_DECLARE_TYPEINFO( Soprano::LanguageTag, Q_MOVABLE_TYPE );
361 
362 Q_DECLARE_OPERATORS_FOR_FLAGS(Soprano::LanguageTag::LookupFlags)
363 
364 SOPRANO_EXPORT QDebug operator<<( QDebug s, const Soprano::LanguageTag& );
365 SOPRANO_EXPORT QTextStream& operator<<( QTextStream& s, const Soprano::LanguageTag& );
366 
367 #endif // SOPRANO_LANGUAGETAG_H