OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "extensions/common/error_utils.h" | 5 #include "extensions/common/error_utils.h" |
6 | 6 |
7 #include "base/strings/string_util.h" | 7 #include "base/strings/string_util.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 | 9 |
10 namespace extensions { | 10 namespace extensions { |
11 | 11 |
12 std::string ErrorUtils::FormatErrorMessage(const std::string& format, | 12 std::string ErrorUtils::FormatErrorMessage(base::StringPiece format, |
13 const std::string& s1) { | 13 base::StringPiece s1) { |
14 std::string ret_val = format; | 14 std::string ret_val = format.as_string(); |
15 base::ReplaceFirstSubstringAfterOffset(&ret_val, 0, "*", s1); | 15 base::ReplaceFirstSubstringAfterOffset(&ret_val, 0, "*", s1); |
16 return ret_val; | 16 return ret_val; |
17 } | 17 } |
18 | 18 |
19 std::string ErrorUtils::FormatErrorMessage(const std::string& format, | 19 std::string ErrorUtils::FormatErrorMessage(base::StringPiece format, |
20 const std::string& s1, | 20 base::StringPiece s1, |
21 const std::string& s2) { | 21 base::StringPiece s2) { |
22 std::string ret_val = format; | 22 std::string ret_val = format.as_string(); |
23 base::ReplaceFirstSubstringAfterOffset(&ret_val, 0, "*", s1); | 23 base::ReplaceFirstSubstringAfterOffset(&ret_val, 0, "*", s1); |
24 base::ReplaceFirstSubstringAfterOffset(&ret_val, 0, "*", s2); | 24 base::ReplaceFirstSubstringAfterOffset(&ret_val, 0, "*", s2); |
25 return ret_val; | 25 return ret_val; |
26 } | 26 } |
27 | 27 |
28 std::string ErrorUtils::FormatErrorMessage(const std::string& format, | 28 std::string ErrorUtils::FormatErrorMessage(base::StringPiece format, |
29 const std::string& s1, | 29 base::StringPiece s1, |
30 const std::string& s2, | 30 base::StringPiece s2, |
31 const std::string& s3) { | 31 base::StringPiece s3) { |
32 std::string ret_val = format; | 32 std::string ret_val = format.as_string(); |
33 base::ReplaceFirstSubstringAfterOffset(&ret_val, 0, "*", s1); | 33 base::ReplaceFirstSubstringAfterOffset(&ret_val, 0, "*", s1); |
34 base::ReplaceFirstSubstringAfterOffset(&ret_val, 0, "*", s2); | 34 base::ReplaceFirstSubstringAfterOffset(&ret_val, 0, "*", s2); |
35 base::ReplaceFirstSubstringAfterOffset(&ret_val, 0, "*", s3); | 35 base::ReplaceFirstSubstringAfterOffset(&ret_val, 0, "*", s3); |
36 return ret_val; | 36 return ret_val; |
37 } | 37 } |
38 | 38 |
39 base::string16 ErrorUtils::FormatErrorMessageUTF16(const std::string& format, | 39 base::string16 ErrorUtils::FormatErrorMessageUTF16(base::StringPiece format, |
40 const std::string& s1) { | 40 base::StringPiece s1) { |
41 return base::UTF8ToUTF16(FormatErrorMessage(format, s1)); | 41 return base::UTF8ToUTF16(FormatErrorMessage(format, s1)); |
42 } | 42 } |
43 | 43 |
44 base::string16 ErrorUtils::FormatErrorMessageUTF16(const std::string& format, | 44 base::string16 ErrorUtils::FormatErrorMessageUTF16(base::StringPiece format, |
45 const std::string& s1, | 45 base::StringPiece s1, |
46 const std::string& s2) { | 46 base::StringPiece s2) { |
47 return base::UTF8ToUTF16(FormatErrorMessage(format, s1, s2)); | 47 return base::UTF8ToUTF16(FormatErrorMessage(format, s1, s2)); |
48 } | 48 } |
49 | 49 |
50 base::string16 ErrorUtils::FormatErrorMessageUTF16(const std::string& format, | 50 base::string16 ErrorUtils::FormatErrorMessageUTF16(base::StringPiece format, |
51 const std::string& s1, | 51 base::StringPiece s1, |
52 const std::string& s2, | 52 base::StringPiece s2, |
53 const std::string& s3) { | 53 base::StringPiece s3) { |
54 return base::UTF8ToUTF16(FormatErrorMessage(format, s1, s2, s3)); | 54 return base::UTF8ToUTF16(FormatErrorMessage(format, s1, s2, s3)); |
55 } | 55 } |
56 | 56 |
57 } // namespace extensions | 57 } // namespace extensions |
OLD | NEW |