Chromium Code Reviews| Index: chromeos/dbus/ibus/ibus_util.cc |
| diff --git a/chromeos/dbus/ibus/ibus_util.cc b/chromeos/dbus/ibus/ibus_util.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..8f4c680d5a5f8a11395634c011b1d5ba1a4bc6b6 |
| --- /dev/null |
| +++ b/chromeos/dbus/ibus/ibus_util.cc |
| @@ -0,0 +1,61 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chromeos/dbus/ibus/ibus_util.h" |
| + |
| +#include "base/environment.h" |
| +#include "base/file_util.h" |
| +#include "base/memory/scoped_ptr.h" |
| +#include "base/string_util.h" |
| + |
| +#include <string> |
| +#include <vector> |
| + |
| +namespace chromeos { |
| + |
| +namespace { |
| +const char kIBusAddressFileEnvKey[] = "IBUS_ADDRESS_FILE"; |
| +const char kIBusAddressKey[] = "IBUS_ADDRESS"; |
| +} // namespace |
| + |
| +bool IBusUtil::GetIBusAddress(std::string* address) { |
| + DCHECK(address); |
| + scoped_ptr<base::Environment> env(base::Environment::Create()); |
| + std::string address_file_path; |
| + if (!env->GetVar(kIBusAddressFileEnvKey, &address_file_path)) { |
| + LOG(ERROR) << "Can not find " << kIBusAddressFileEnvKey |
| + << " in environment variables."; |
| + return false; |
| + } |
| + |
| + std::string address_file_contents; |
| + if (!file_util::ReadFileToString(FilePath(address_file_path), |
|
satorux1
2012/04/20 23:18:40
Ugh, you cannot do this here. DBusThreadManager is
Seigo Nonaka
2012/04/21 05:35:14
I found a command line flag to specify opening add
Seigo Nonaka
2012/04/23 23:03:21
I made another CL for above.
http://codereview.chr
|
| + &address_file_contents)) { |
| + LOG(ERROR) << "Can not read IBus address file:" << address_file_path; |
| + return false; |
| + } |
| + |
| + std::vector<std::string> lines; |
| + Tokenize(address_file_contents, "\r\n", &lines); |
|
satorux1
2012/04/20 23:18:40
Use SplitString instead? \r won't be used in the f
Seigo Nonaka
2012/04/23 23:03:21
Yes, but I removed this file.
Thanks
On 2012/04/20
|
| + |
| + // Prfix matching is enought for ibus address file parsing, because address |
| + // file is generated by ibus with fixed format. |
| + // https://github.com/ibus/ibus/blob/master/src/ibusshare.c#L234 |
| + const std::string address_entry_prefix = std::string(kIBusAddressKey) |
| + + std::string("="); |
| + for (std::vector<std::string>::const_iterator ite = lines.begin(); |
| + ite != lines.end(); ++ite) { |
|
satorux1
2012/04/20 23:18:40
matter of taste, but for (size_t i = 0; i < lines.
Seigo Nonaka
2012/04/23 23:03:21
I have not strong policy about iterator:)
I will d
|
| + |
| + if (!StartsWithASCII(*ite, address_entry_prefix, true)) { |
| + continue; |
| + } |
| + |
| + address->assign(ite->substr(address_entry_prefix.size())); |
| + return true; |
| + } |
| + LOG(ERROR) << "Can not find " << kIBusAddressKey << " entry."; |
| + return false; |
| +} |
| + |
| +} // namespace chromeos |