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

Side by Side Diff: base/icu_util.cc

Issue 173233: Use U_ICU_VERSION_SHORT instead of hard-coding the icu data dll and module na... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 The Chromium 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 "build/build_config.h" 5 #include "build/build_config.h"
6 6
7 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 #include <windows.h> 8 #include <windows.h>
9 #endif 9 #endif
10 10
11 #include <string> 11 #include <string>
12 12
13 #include "base/icu_util.h" 13 #include "base/icu_util.h"
14 14
15 #include "base/file_path.h" 15 #include "base/file_path.h"
16 #include "base/file_util.h" 16 #include "base/file_util.h"
17 #include "base/logging.h" 17 #include "base/logging.h"
18 #include "base/path_service.h" 18 #include "base/path_service.h"
19 #include "base/string_util.h"
19 #include "base/sys_string_conversions.h" 20 #include "base/sys_string_conversions.h"
20 #include "unicode/putil.h" 21 #include "unicode/putil.h"
21 #include "unicode/udata.h" 22 #include "unicode/udata.h"
22 23
23 #define ICU_UTIL_DATA_FILE 0 24 #define ICU_UTIL_DATA_FILE 0
24 #define ICU_UTIL_DATA_SHARED 1 25 #define ICU_UTIL_DATA_SHARED 1
25 #define ICU_UTIL_DATA_STATIC 2 26 #define ICU_UTIL_DATA_STATIC 2
26 27
27 #ifndef ICU_UTIL_DATA_IMPL 28 #ifndef ICU_UTIL_DATA_IMPL
28 29
29 #if defined(OS_WIN) 30 #if defined(OS_WIN)
30 #define ICU_UTIL_DATA_IMPL ICU_UTIL_DATA_SHARED 31 #define ICU_UTIL_DATA_IMPL ICU_UTIL_DATA_SHARED
31 #elif defined(OS_MACOSX) 32 #elif defined(OS_MACOSX)
32 #define ICU_UTIL_DATA_IMPL ICU_UTIL_DATA_STATIC 33 #define ICU_UTIL_DATA_IMPL ICU_UTIL_DATA_STATIC
33 #elif defined(OS_LINUX) 34 #elif defined(OS_LINUX)
34 #define ICU_UTIL_DATA_IMPL ICU_UTIL_DATA_FILE 35 #define ICU_UTIL_DATA_IMPL ICU_UTIL_DATA_FILE
35 #endif 36 #endif
36 37
37 #endif // ICU_UTIL_DATA_IMPL 38 #endif // ICU_UTIL_DATA_IMPL
38 39
39 #if defined(OS_WIN) 40 #if defined(OS_WIN)
40 #define ICU_UTIL_DATA_SYMBOL "icudt38_dat" 41 #define ICU_UTIL_DATA_SYMBOL "icudt" U_ICU_VERSION_SHORT "_dat"
41 #define ICU_UTIL_DATA_SHARED_MODULE_NAME L"icudt38.dll" 42 #define ICU_UTIL_DATA_SHARED_MODULE_NAME "icudt" U_ICU_VERSION_SHORT ".dll"
42 #endif 43 #endif
43 44
44 namespace icu_util { 45 namespace icu_util {
45 46
46 bool Initialize() { 47 bool Initialize() {
47 #ifndef NDEBUG 48 #ifndef NDEBUG
48 // Assert that we are not called more than once. Even though calling this 49 // Assert that we are not called more than once. Even though calling this
49 // function isn't harmful (ICU can handle it), being called twice probably 50 // function isn't harmful (ICU can handle it), being called twice probably
50 // indicates a programming error. 51 // indicates a programming error.
51 static bool called_once = false; 52 static bool called_once = false;
52 DCHECK(!called_once); 53 DCHECK(!called_once);
53 called_once = true; 54 called_once = true;
54 #endif 55 #endif
55 56
56 #if (ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_SHARED) 57 #if (ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_SHARED)
57 // We expect to find the ICU data module alongside the current module. 58 // We expect to find the ICU data module alongside the current module.
58 std::wstring data_path; 59 std::wstring data_path;
59 PathService::Get(base::DIR_MODULE, &data_path); 60 PathService::Get(base::DIR_MODULE, &data_path);
60 file_util::AppendToPath(&data_path, ICU_UTIL_DATA_SHARED_MODULE_NAME); 61 file_util::AppendToPath(&data_path, ASCIIToWide(ICU_UTIL_DATA_SHARED_MODULE_NA ME));
61 62
62 HMODULE module = LoadLibrary(data_path.c_str()); 63 HMODULE module = LoadLibrary(data_path.c_str());
63 if (!module) 64 if (!module)
64 return false; 65 return false;
65 66
66 FARPROC addr = GetProcAddress(module, ICU_UTIL_DATA_SYMBOL); 67 FARPROC addr = GetProcAddress(module, ICU_UTIL_DATA_SYMBOL);
67 if (!addr) 68 if (!addr)
68 return false; 69 return false;
69 70
70 UErrorCode err = U_ZERO_ERROR; 71 UErrorCode err = U_ZERO_ERROR;
(...skipping 12 matching lines...) Expand all
83 u_setDataDirectory(data_path.value().c_str()); 84 u_setDataDirectory(data_path.value().c_str());
84 // Only look for the packaged data file; 85 // Only look for the packaged data file;
85 // the default behavior is to look for individual files. 86 // the default behavior is to look for individual files.
86 UErrorCode err = U_ZERO_ERROR; 87 UErrorCode err = U_ZERO_ERROR;
87 udata_setFileAccess(UDATA_ONLY_PACKAGES, &err); 88 udata_setFileAccess(UDATA_ONLY_PACKAGES, &err);
88 return err == U_ZERO_ERROR; 89 return err == U_ZERO_ERROR;
89 #endif 90 #endif
90 } 91 }
91 92
92 } // namespace icu_util 93 } // namespace icu_util
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698