Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(342)

Side by Side Diff: src/icu_util.cc

Issue 2042253002: [icu] Support loading data file from default location (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Format Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/icu_util.h ('k') | src/snapshot/mksnapshot.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/icu_util.h" 5 #include "src/icu_util.h"
6 6
7 #if defined(_WIN32) 7 #if defined(_WIN32)
8 #include <windows.h> 8 #include <windows.h>
9 #endif 9 #endif
10 10
11 #if defined(V8_I18N_SUPPORT) 11 #if defined(V8_I18N_SUPPORT)
12 #include <stdio.h> 12 #include <stdio.h>
13 #include <stdlib.h> 13 #include <stdlib.h>
14 14
15 #include "unicode/putil.h" 15 #include "unicode/putil.h"
16 #include "unicode/udata.h" 16 #include "unicode/udata.h"
17 17
18 #include "src/base/file-utils.h"
19
18 #define ICU_UTIL_DATA_FILE 0 20 #define ICU_UTIL_DATA_FILE 0
19 #define ICU_UTIL_DATA_SHARED 1 21 #define ICU_UTIL_DATA_SHARED 1
20 #define ICU_UTIL_DATA_STATIC 2 22 #define ICU_UTIL_DATA_STATIC 2
21 23
22 #define ICU_UTIL_DATA_SYMBOL "icudt" U_ICU_VERSION_SHORT "_dat" 24 #define ICU_UTIL_DATA_SYMBOL "icudt" U_ICU_VERSION_SHORT "_dat"
23 #define ICU_UTIL_DATA_SHARED_MODULE_NAME "icudt.dll" 25 #define ICU_UTIL_DATA_SHARED_MODULE_NAME "icudt.dll"
24 #endif 26 #endif
25 27
26 namespace v8 { 28 namespace v8 {
27 29
28 namespace internal { 30 namespace internal {
29 31
30 #if defined(V8_I18N_SUPPORT) && (ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_FILE) 32 #if defined(V8_I18N_SUPPORT) && (ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_FILE)
31 namespace { 33 namespace {
32 char* g_icu_data_ptr = NULL; 34 char* g_icu_data_ptr = NULL;
33 35
34 void free_icu_data_ptr() { 36 void free_icu_data_ptr() {
35 delete[] g_icu_data_ptr; 37 delete[] g_icu_data_ptr;
36 } 38 }
37 39
38 } // namespace 40 } // namespace
39 #endif 41 #endif
40 42
43 bool InitializeICUDefaultLocation(const char* exec_path,
44 const char* icu_data_file) {
45 #if !defined(V8_I18N_SUPPORT)
46 return true;
47 #else
48 #if ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_FILE
49 if (icu_data_file) {
50 return InitializeICU(icu_data_file);
51 }
52 char* icu_data_file_default;
53 RelativePath(&icu_data_file_default, exec_path, "icudtl.dat");
54 bool result = InitializeICU(icu_data_file_default);
55 free(icu_data_file_default);
56 return result;
57 #else
58 return InitializeICU(NULL);
59 #endif
60 #endif
61 }
62
41 bool InitializeICU(const char* icu_data_file) { 63 bool InitializeICU(const char* icu_data_file) {
42 #if !defined(V8_I18N_SUPPORT) 64 #if !defined(V8_I18N_SUPPORT)
43 return true; 65 return true;
44 #else 66 #else
45 #if ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_SHARED 67 #if ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_SHARED
46 // We expect to find the ICU data module alongside the current module. 68 // We expect to find the ICU data module alongside the current module.
47 HMODULE module = LoadLibraryA(ICU_UTIL_DATA_SHARED_MODULE_NAME); 69 HMODULE module = LoadLibraryA(ICU_UTIL_DATA_SHARED_MODULE_NAME);
48 if (!module) return false; 70 if (!module) return false;
49 71
50 FARPROC addr = GetProcAddress(module, ICU_UTIL_DATA_SYMBOL); 72 FARPROC addr = GetProcAddress(module, ICU_UTIL_DATA_SYMBOL);
(...skipping 30 matching lines...) Expand all
81 103
82 UErrorCode err = U_ZERO_ERROR; 104 UErrorCode err = U_ZERO_ERROR;
83 udata_setCommonData(reinterpret_cast<void*>(g_icu_data_ptr), &err); 105 udata_setCommonData(reinterpret_cast<void*>(g_icu_data_ptr), &err);
84 return err == U_ZERO_ERROR; 106 return err == U_ZERO_ERROR;
85 #endif 107 #endif
86 #endif 108 #endif
87 } 109 }
88 110
89 } // namespace internal 111 } // namespace internal
90 } // namespace v8 112 } // namespace v8
OLDNEW
« no previous file with comments | « src/icu_util.h ('k') | src/snapshot/mksnapshot.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698