license.bot | f003cfe | 2008-08-24 09:55:55 +0900 | [diff] [blame^] | 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 |
| 3 | // found in the LICENSE file. |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 4 | |
avi@google.com | 981d057 | 2008-08-07 22:41:24 +0900 | [diff] [blame] | 5 | #include "build/build_config.h" |
| 6 | |
evanm@google.com | e41d3b3 | 2008-08-15 10:04:11 +0900 | [diff] [blame] | 7 | #if defined(OS_WIN) |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 8 | #include <windows.h> |
avi@google.com | 981d057 | 2008-08-07 22:41:24 +0900 | [diff] [blame] | 9 | #endif |
| 10 | |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 11 | #include <string> |
| 12 | |
| 13 | #include "base/icu_util.h" |
| 14 | |
| 15 | #include "base/logging.h" |
| 16 | #include "base/file_util.h" |
| 17 | #include "base/path_service.h" |
evanm@google.com | e41d3b3 | 2008-08-15 10:04:11 +0900 | [diff] [blame] | 18 | #include "base/sys_string_conversions.h" |
| 19 | #include "unicode/putil.h" |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 20 | #include "unicode/udata.h" |
| 21 | |
| 22 | namespace icu_util { |
| 23 | |
| 24 | bool Initialize() { |
evanm@google.com | e41d3b3 | 2008-08-15 10:04:11 +0900 | [diff] [blame] | 25 | #if defined(OS_WIN) |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 26 | // Assert that we are not called more than once. Even though calling this |
| 27 | // function isn't harmful (ICU can handle it), being called twice probably |
| 28 | // indicates a programming error. |
avi@google.com | 981d057 | 2008-08-07 22:41:24 +0900 | [diff] [blame] | 29 | #ifndef NDEBUG |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 30 | static bool called_once = false; |
| 31 | DCHECK(!called_once); |
| 32 | called_once = true; |
| 33 | #endif |
| 34 | |
| 35 | // We expect to find the ICU data module alongside the current module. |
| 36 | std::wstring data_path; |
| 37 | PathService::Get(base::DIR_MODULE, &data_path); |
| 38 | file_util::AppendToPath(&data_path, L"icudt38.dll"); |
| 39 | |
| 40 | HMODULE module = LoadLibrary(data_path.c_str()); |
| 41 | if (!module) |
| 42 | return false; |
| 43 | |
| 44 | FARPROC addr = GetProcAddress(module, "icudt38_dat"); |
| 45 | if (!addr) |
| 46 | return false; |
| 47 | |
| 48 | UErrorCode err = U_ZERO_ERROR; |
| 49 | udata_setCommonData(reinterpret_cast<void*>(addr), &err); |
| 50 | return err == U_ZERO_ERROR; |
evanm@google.com | e41d3b3 | 2008-08-15 10:04:11 +0900 | [diff] [blame] | 51 | #elif defined(OS_MACOSX) |
| 52 | // Mac bundles the ICU data in. |
avi@google.com | 981d057 | 2008-08-07 22:41:24 +0900 | [diff] [blame] | 53 | return true; |
evanm@google.com | e41d3b3 | 2008-08-15 10:04:11 +0900 | [diff] [blame] | 54 | #elif defined(OS_LINUX) |
| 55 | // For now, expect the data file to be alongside the executable. |
| 56 | // This is sufficient while we work on unit tests, but will eventually |
| 57 | // likely live in a data directory. |
| 58 | std::wstring data_path; |
| 59 | bool path_ok = PathService::Get(base::DIR_EXE, &data_path); |
| 60 | DCHECK(path_ok); |
| 61 | u_setDataDirectory(base::SysWideToNativeMB(data_path).c_str()); |
| 62 | return true; |
| 63 | #endif |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | } // namespace icu_util |
license.bot | f003cfe | 2008-08-24 09:55:55 +0900 | [diff] [blame^] | 67 | |