soprano
Soprano::LanguageTag Class Reference
A LanguageTag represents a language according to RFC 3066 and RFC 4646. More...
#include <Soprano/LanguageTag>
Public Types | |
| enum | LookupFlag { LookupFlagNone = 0, LookupFlagNoFallback = 1 } |
| enum | MatchFilter { MatchFilterBasic = 0, MatchFilterExtended = 1 } |
Public Member Functions | |
Constructors | |
| LanguageTag (QLocale::Language lang, QLocale::Country country=QLocale::AnyCountry) | |
| LanguageTag (const QLocale &locale) | |
| LanguageTag (const QString &tag) | |
| LanguageTag (const QLatin1String &tag) | |
| LanguageTag (const char *tag) | |
| LanguageTag (const LanguageTag &other) | |
| LanguageTag () | |
| ~LanguageTag () | |
Information | |
| bool | isEmpty () const |
| bool | isValid () const |
| QStringList | subTags () const |
Operators | |
| bool | matches (const LanguageTag &range, MatchFilter scheme=MatchFilterBasic) const |
| bool | operator!= (const LanguageTag &other) const |
| bool | operator< (const LanguageTag &other) const |
| bool | operator<= (const LanguageTag &other) const |
| LanguageTag & | operator= (const LanguageTag &other) |
| bool | operator== (const LanguageTag &other) const |
| bool | operator> (const LanguageTag &other) const |
| bool | operator>= (const LanguageTag &other) const |
Conversion | |
| operator QString () const | |
| QLocale | toLocale () const |
| QString | toPrettyString () const |
| QString | toString () const |
Static Public Member Functions | |
| static int | lookup (const QList< LanguageTag > &choices, const LanguageTag &priority, LookupFlags flags=LookupFlagNone, MatchFilter scheme=MatchFilterBasic) |
| static int | lookup (const QList< LanguageTag > &choices, const QList< LanguageTag > &priority, LookupFlags flags=LookupFlagNone, MatchFilter scheme=MatchFilterBasic) |
Detailed Description
A LanguageTag represents a language according to RFC 3066 and RFC 4646.
- Since:
- 2.3
Definition at line 44 of file languagetag.h.
Member Enumeration Documentation
Flags for performing LanguageTag lookups.
- See also:
- lookup()
Definition at line 70 of file languagetag.h.
- Enumerator:
Definition at line 47 of file languagetag.h.
Constructor & Destructor Documentation
| Soprano::LanguageTag::LanguageTag | ( | ) |
Default constructor.
Creates an empty language tag.
| Soprano::LanguageTag::LanguageTag | ( | const LanguageTag & | other | ) |
Copy constructor.
- Parameters:
-
other The language tag from which to copy
| Soprano::LanguageTag::LanguageTag | ( | const char * | tag | ) |
Creates a language tag.
- Parameters:
-
tag The language tag string
| Soprano::LanguageTag::LanguageTag | ( | const QLatin1String & | tag | ) |
Creates a language tag.
- Parameters:
-
tag The language tag string
| Soprano::LanguageTag::LanguageTag | ( | const QString & | tag | ) |
Creates a language tag.
- Parameters:
-
tag The language tag string
| Soprano::LanguageTag::LanguageTag | ( | const QLocale & | locale | ) | [explicit] |
Creates a language tag from a QLocale.
If the language is QLocale::C, then an empty LanguageTag is produced.
- Parameters:
-
locale the locale
| Soprano::LanguageTag::LanguageTag | ( | QLocale::Language | lang, | |
| QLocale::Country | country = QLocale::AnyCountry | |||
| ) |
Creates a language tag from a language and country.
If lang is QLocale::C, then an empty LanguageTag is produced.
- Parameters:
-
lang the language code country the country code
| Soprano::LanguageTag::~LanguageTag | ( | ) |
Destructor.
Member Function Documentation
| bool Soprano::LanguageTag::isEmpty | ( | ) | const |
- Returns:
trueif this language tag is empty.
| bool Soprano::LanguageTag::isValid | ( | ) | const |
Determines if this language tag is valid.
A valid language tag is divided into subtags that are divided by "-". The tag must adhere the following rules:
- Each subtag is composed only of characters in the ASCII range [a-zA-Z0-9] (letters and digits), with the exception of the first subtag, which must be composed of letters only
- No subtags are empty
- No subtags are longer than 8 characters
- Single-character subtags cannot end the tag unless after a private use ("x") subtag (e.g. "en-x-i" and "en-x-abcd-i" are legal; "en-x", "en-i", and "en-i-abcd-g" are illegal)
- Returns:
trueif this language tag is valid
| static int Soprano::LanguageTag::lookup | ( | const QList< LanguageTag > & | choices, | |
| const LanguageTag & | priority, | |||
| LookupFlags | flags = LookupFlagNone, |
|||
| MatchFilter | scheme = MatchFilterBasic | |||
| ) | [static] |
A convenience method to select a language tag based on a single search pattern.
- Parameters:
-
choices the list of available language choices priority the language range against which to match flags flags for the lookup operation scheme the matching scheme to use. RFC 4647 specifies that basic (MatchFilterBasic) processing should be used.
- Returns:
- the index of the matching language tag in choices, or < 0 if no tag matched.
| static int Soprano::LanguageTag::lookup | ( | const QList< LanguageTag > & | choices, | |
| const QList< LanguageTag > & | priority, | |||
| LookupFlags | flags = LookupFlagNone, |
|||
| MatchFilter | scheme = MatchFilterBasic | |||
| ) | [static] |
Compares a language tag against a list of language tags and selects the most suitable tag according to the rules of RFC 4647 Section 3.4.
The arguments consist of choices, a list of tags from which to select, and priority, a list of acceptable language ranges. Both lists must be sorted in descending order of preference.
The matching algorithm works as follows:
- For each item in the priority list, the choices list is scanned for matches. The wildcard value "*" is ignored in lookup operations, as it would match any tag. If a match occurs, the lookup is complete and the matching choices list index is returned.
- If no match has been found, the last subtag on the current priority item is truncated, and the choices list is scanned again. Single-character subtags are also truncated if they are at the end of the tag. This repeats until there are no subtags remaining. This fallback behavior can be skipped by specifying the LookupFlagsNoFallback flag.
- If neither the current priority item nor any of its fallback values matched the choices list, then the next item in the priority list is considered according to the above steps.
- If none of the priority items match the choices list, then a value < 0 is returned.
- Parameters:
-
choices the list of available language choices priority the language priority list flags flags for the lookup operation scheme the matching scheme to use. RFC 4647 specifies that basic (MatchFilterBasic) processing should be used.
- Returns:
- the index of the matching language tag in choices, or < 0 if no tag matched.
| bool Soprano::LanguageTag::matches | ( | const LanguageTag & | range, | |
| MatchFilter | scheme = MatchFilterBasic | |||
| ) | const |
Match this language tag against range using the specified filtering scheme.
- Parameters:
-
range the range against which to match scheme the filtering scheme to use
- Returns:
trueif this tag matches pattern,falseif not.
| Soprano::LanguageTag::operator QString | ( | ) | const [inline] |
A convenience operator to convert this LanguageTag to a string.
- Returns:
- the string representation of this LanguageTag
- See also:
- toString()
Definition at line 277 of file languagetag.h.
| bool Soprano::LanguageTag::operator!= | ( | const LanguageTag & | other | ) | const |
Comparison operator.
Language tag comparisons are case-insensitive.
- Returns:
trueif this tag andotherdiffer.
| bool Soprano::LanguageTag::operator< | ( | const LanguageTag & | other | ) | const |
Comparison operator.
- Returns:
trueif this tag is lexically less thanother.
| bool Soprano::LanguageTag::operator<= | ( | const LanguageTag & | other | ) | const |
Comparison operator.
- Returns:
trueif this tag is lexically less than or equal toother.
| LanguageTag& Soprano::LanguageTag::operator= | ( | const LanguageTag & | other | ) |
Assigns other to this tag.
| bool Soprano::LanguageTag::operator== | ( | const LanguageTag & | other | ) | const |
Comparison operator.
Language tag comparisons are case-insensitive.
- Returns:
trueif this tag andotherare equal.
| bool Soprano::LanguageTag::operator> | ( | const LanguageTag & | other | ) | const |
Comparison operator.
- Returns:
trueif this tag is lexically greater thanother.
| bool Soprano::LanguageTag::operator>= | ( | const LanguageTag & | other | ) | const |
Comparison operator.
- Returns:
trueif this tag is lexically greater than or equal toother.
| QStringList Soprano::LanguageTag::subTags | ( | ) | const |
- Returns:
- the subtag parts that make up this language tag
| QLocale Soprano::LanguageTag::toLocale | ( | ) | const |
Converts this LanguageTag to a locale, using the primary language tag and first two-letter language subtag, if any.
If the conversion could not be performed, then the "C" QLocale is returned.
- Returns:
- the converted locale
- Note:
- QLocale restricts the countries that can be paired with a particular language. If the language-country pair in this tag is not in the QLocale database, or if this language tag does not contain country information, then the most appropriate country will be used for the locale. For example, "de-US" (German as spoken in the United States) is not a valid combination, and the country would be changed to Germany.
| QString Soprano::LanguageTag::toPrettyString | ( | ) | const |
Converts this LanguageTag to a string formatted according to the case rules in RFC 4647 section 4.4 (page 44).
- Returns:
- the pretty string representation of this LanguageTag
| QString Soprano::LanguageTag::toString | ( | ) | const |
Converts this LanguageTag to a string.
- Returns:
- the string representation of this LanguageTag
The documentation for this class was generated from the following file:
KDE 4.4 API Reference