Soprano
2.7.4
|
00001 /* 00002 * This file is part of Soprano Project. 00003 * 00004 * Copyright (C) 2009 Greg Beauchesne <greg_b@vision-play.com> 00005 * 00006 * This library is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU Library General Public 00008 * License as published by the Free Software Foundation; either 00009 * version 2 of the License, or (at your option) any later version. 00010 * 00011 * This library is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 * Library General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Library General Public License 00017 * along with this library; see the file COPYING.LIB. If not, write to 00018 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00019 * Boston, MA 02110-1301, USA. 00020 */ 00021 00022 #ifndef SOPRANO_LANGUAGETAG_H 00023 #define SOPRANO_LANGUAGETAG_H 00024 00025 #include <QtCore/QSharedDataPointer> 00026 #include <QtCore/QTextStream> 00027 #include <QtCore/QLocale> 00028 #include <QtCore/QFlags> 00029 #include <QtCore/QMetaType> 00030 00031 #include "soprano_export.h" 00032 00033 namespace Soprano 00034 { 00044 class SOPRANO_EXPORT LanguageTag 00045 { 00046 public: 00047 enum MatchFilter { 00055 MatchFilterBasic = 0, 00056 00062 MatchFilterExtended = 1 00063 }; 00064 00070 enum LookupFlag { 00071 LookupFlagNone = 0, 00073 LookupFlagNoFallback = 1 00074 }; 00075 Q_DECLARE_FLAGS(LookupFlags, LookupFlag) 00076 00077 public: 00086 LanguageTag(); 00087 00093 LanguageTag( const LanguageTag &other ); 00094 00100 LanguageTag( const char * tag ); 00101 00107 LanguageTag( const QLatin1String &tag ); 00108 00114 LanguageTag( const QString &tag ); 00115 00122 explicit LanguageTag( const QLocale &locale ); 00123 00131 LanguageTag( QLocale::Language lang, QLocale::Country country = QLocale::AnyCountry ); 00132 00136 ~LanguageTag(); 00138 00146 LanguageTag& operator=( const LanguageTag& other ); 00147 00154 bool operator==( const LanguageTag& other ) const; 00155 00161 bool operator!=( const LanguageTag& other ) const; 00162 00167 bool operator<( const LanguageTag& other ) const; 00168 00173 bool operator<=( const LanguageTag& other ) const; 00174 00179 bool operator>( const LanguageTag& other ) const; 00180 00185 bool operator>=( const LanguageTag& other ) const; 00186 00196 bool matches( const LanguageTag& range, MatchFilter scheme = MatchFilterBasic ) const; 00198 00203 00207 bool isEmpty() const; 00208 00224 bool isValid() const; 00225 00229 QStringList subTags() const; 00230 00232 00242 QString toString() const; 00243 00250 QString toPrettyString() const; 00251 00268 QLocale toLocale() const; 00269 00277 inline operator QString() const { return toString(); } 00279 00280 00321 static int lookup( 00322 const QList<LanguageTag> & choices, 00323 const QList<LanguageTag> & priority, 00324 LookupFlags flags = LookupFlagNone, 00325 MatchFilter scheme = MatchFilterBasic 00326 ); 00327 00344 static int lookup( 00345 const QList<LanguageTag> & choices, 00346 const LanguageTag & priority, 00347 LookupFlags flags = LookupFlagNone, 00348 MatchFilter scheme = MatchFilterBasic 00349 ); 00350 00351 private: 00352 class Private; 00353 QSharedDataPointer<Private> d; 00354 }; 00355 00356 SOPRANO_EXPORT uint qHash( const LanguageTag& node ); 00357 } 00358 00359 Q_DECLARE_METATYPE( Soprano::LanguageTag ) 00360 Q_DECLARE_TYPEINFO( Soprano::LanguageTag, Q_MOVABLE_TYPE ); 00361 00362 Q_DECLARE_OPERATORS_FOR_FLAGS(Soprano::LanguageTag::LookupFlags) 00363 00364 SOPRANO_EXPORT QDebug operator<<( QDebug s, const Soprano::LanguageTag& ); 00365 SOPRANO_EXPORT QTextStream& operator<<( QTextStream& s, const Soprano::LanguageTag& ); 00366 00367 #endif // SOPRANO_LANGUAGETAG_H