~ubuntu-branches/ubuntu/saucy/libv8/saucy

« back to all changes in this revision

Viewing changes to src/extensions/experimental/language-matcher.h

  • Committer: Package Import Robot
  • Author(s): Jérémy Lal
  • Date: 2012-04-07 16:26:13 UTC
  • mfrom: (15.1.27 sid)
  • Revision ID: package-import@ubuntu.com-20120407162613-dqo1m6w9r3fh8tst
Tags: 3.8.9.16-3
* mipsel build fixes :
  + v8_use_mips_abi_hardfloat=false, this lowers EABI requirements.
  + v8_can_use_fpu_instructions=false, detect if FPU is present.
  + set -Wno-unused-but-set-variable only on mipsel.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
4
 
// met:
5
 
//
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.
15
 
//
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.
27
 
 
28
 
#ifndef V8_EXTENSIONS_EXPERIMENTAL_LANGUAGE_MATCHER_H_
29
 
#define V8_EXTENSIONS_EXPERIMENTAL_LANGUAGE_MATCHER_H_
30
 
 
31
 
#include "v8.h"
32
 
 
33
 
#include "unicode/uloc.h"
34
 
 
35
 
namespace v8_i18n {
36
 
 
37
 
struct LocaleIDMatch {
38
 
  LocaleIDMatch();
39
 
 
40
 
  LocaleIDMatch& operator=(const LocaleIDMatch& rhs);
41
 
 
42
 
  // Bcp47 locale id - "de-Latn-DE-u-co-phonebk".
43
 
  char bcp47_id[ULOC_FULLNAME_CAPACITY];
44
 
 
45
 
  // ICU locale id - "de_Latn_DE@collation=phonebk".
46
 
  char icu_id[ULOC_FULLNAME_CAPACITY];
47
 
 
48
 
  // Score for this locale.
49
 
  int score;
50
 
};
51
 
 
52
 
class LanguageMatcher {
53
 
 public:
54
 
  // Default locale.
55
 
  static const char* const kDefaultLocale;
56
 
 
57
 
  // Finds best supported locale for a given a list of locale identifiers.
58
 
  // It preserves the extension for the locale id.
59
 
  static void GetBestMatchForPriorityList(
60
 
      v8::Handle<v8::Array> locale_list, LocaleIDMatch* result);
61
 
 
62
 
  // Finds best supported locale for a single locale identifier.
63
 
  // It preserves the extension for the locale id.
64
 
  static void GetBestMatchForString(
65
 
      v8::Handle<v8::String> locale_id, LocaleIDMatch* result);
66
 
 
67
 
 private:
68
 
  // If langauge subtags match add this amount to the score.
69
 
  static const unsigned int kLanguageWeight;
70
 
 
71
 
  // If script subtags match add this amount to the score.
72
 
  static const unsigned int kScriptWeight;
73
 
 
74
 
  // If region subtags match add this amount to the score.
75
 
  static const unsigned int kRegionWeight;
76
 
 
77
 
  // LocaleID match score has to be over this number to accept the match.
78
 
  static const int kThreshold;
79
 
 
80
 
  // For breaking ties in priority queue.
81
 
  static const unsigned int kPositionBonus;
82
 
 
83
 
  LanguageMatcher();
84
 
 
85
 
  // Compares locale_id to the supported list of locales and returns best
86
 
  // match.
87
 
  // Returns false if it fails to convert locale id from ICU to BCP47 format.
88
 
  static bool CompareToSupportedLocaleIDList(v8::Handle<v8::String> locale_id,
89
 
                                             LocaleIDMatch* result);
90
 
};
91
 
 
92
 
}  // namespace v8_i18n
93
 
 
94
 
#endif  // V8_EXTENSIONS_EXPERIMENTAL_LANGUAGE_MATCHER_H_