1
// Copyright 2011 the V8 project authors. All rights reserved.
2
// Redistribution and use in source and binary forms, with or without
3
// modification, are permitted provided that the following conditions are
6
// * Redistributions of source code must retain the above copyright
7
// notice, this list of conditions and the following disclaimer.
8
// * Redistributions in binary form must reproduce the above
9
// copyright notice, this list of conditions and the following
10
// disclaimer in the documentation and/or other materials provided
11
// with the distribution.
12
// * Neither the name of Google Inc. nor the names of its
13
// contributors may be used to endorse or promote products derived
14
// from this software without specific prior written permission.
16
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
#ifndef V8_EXTENSIONS_EXPERIMENTAL_LANGUAGE_MATCHER_H_
29
#define V8_EXTENSIONS_EXPERIMENTAL_LANGUAGE_MATCHER_H_
31
#include "include/v8.h"
33
#include "unicode/uloc.h"
38
struct LocaleIDMatch {
41
LocaleIDMatch& operator=(const LocaleIDMatch& rhs);
43
// Bcp47 locale id - "de-Latn-DE-u-co-phonebk".
44
char bcp47_id[ULOC_FULLNAME_CAPACITY];
46
// ICU locale id - "de_Latn_DE@collation=phonebk".
47
char icu_id[ULOC_FULLNAME_CAPACITY];
49
// Score for this locale.
53
class LanguageMatcher {
56
static const char* const kDefaultLocale;
58
// Finds best supported locale for a given a list of locale identifiers.
59
// It preserves the extension for the locale id.
60
static void GetBestMatchForPriorityList(
61
v8::Handle<v8::Array> locale_list, LocaleIDMatch* result);
63
// Finds best supported locale for a single locale identifier.
64
// It preserves the extension for the locale id.
65
static void GetBestMatchForString(
66
v8::Handle<v8::String> locale_id, LocaleIDMatch* result);
69
// If langauge subtags match add this amount to the score.
70
static const unsigned int kLanguageWeight;
72
// If script subtags match add this amount to the score.
73
static const unsigned int kScriptWeight;
75
// If region subtags match add this amount to the score.
76
static const unsigned int kRegionWeight;
78
// LocaleID match score has to be over this number to accept the match.
79
static const unsigned int kThreshold;
81
// For breaking ties in priority queue.
82
static const unsigned int kPositionBonus;
86
// Compares locale_id to the supported list of locales and returns best
88
// Returns false if it fails to convert locale id from ICU to BCP47 format.
89
static bool CompareToSupportedLocaleIDList(v8::Handle<v8::String> locale_id,
90
LocaleIDMatch* result);
93
} } // namespace v8::internal
95
#endif // V8_EXTENSIONS_EXPERIMENTAL_LANGUAGE_MATCHER_H_