| 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 "base/string_util.h" | 5 #include "base/string_util.h" |
| 6 | 6 |
| 7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
| 8 | 8 |
| 9 #include <ctype.h> | 9 #include <ctype.h> |
| 10 #include <errno.h> | 10 #include <errno.h> |
| (...skipping 813 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 824 } | 824 } |
| 825 | 825 |
| 826 string16 JoinString(const std::vector<string16>& parts, char16 sep) { | 826 string16 JoinString(const std::vector<string16>& parts, char16 sep) { |
| 827 return JoinStringT(parts, sep); | 827 return JoinStringT(parts, sep); |
| 828 } | 828 } |
| 829 | 829 |
| 830 template<class FormatStringType, class OutStringType> | 830 template<class FormatStringType, class OutStringType> |
| 831 OutStringType DoReplaceStringPlaceholders(const FormatStringType& format_string, | 831 OutStringType DoReplaceStringPlaceholders(const FormatStringType& format_string, |
| 832 const std::vector<OutStringType>& subst, std::vector<size_t>* offsets) { | 832 const std::vector<OutStringType>& subst, std::vector<size_t>* offsets) { |
| 833 size_t substitutions = subst.size(); | 833 size_t substitutions = subst.size(); |
| 834 DCHECK(substitutions < 10); | |
| 835 | 834 |
| 836 size_t sub_length = 0; | 835 size_t sub_length = 0; |
| 837 for (typename std::vector<OutStringType>::const_iterator iter = subst.begin(); | 836 for (typename std::vector<OutStringType>::const_iterator iter = subst.begin(); |
| 838 iter != subst.end(); ++iter) { | 837 iter != subst.end(); ++iter) { |
| 839 sub_length += iter->length(); | 838 sub_length += iter->length(); |
| 840 } | 839 } |
| 841 | 840 |
| 842 OutStringType formatted; | 841 OutStringType formatted; |
| 843 formatted.reserve(format_string.length() + sub_length); | 842 formatted.reserve(format_string.length() + sub_length); |
| 844 | 843 |
| 845 std::vector<ReplacementOffset> r_offsets; | 844 std::vector<ReplacementOffset> r_offsets; |
| 846 for (typename FormatStringType::const_iterator i = format_string.begin(); | 845 for (typename FormatStringType::const_iterator i = format_string.begin(); |
| 847 i != format_string.end(); ++i) { | 846 i != format_string.end(); ++i) { |
| 848 if ('$' == *i) { | 847 if ('$' == *i) { |
| 849 if (i + 1 != format_string.end()) { | 848 if (i + 1 != format_string.end()) { |
| 850 ++i; | 849 ++i; |
| 851 DCHECK('$' == *i || '1' <= *i) << "Invalid placeholder: " << *i; | 850 DCHECK('$' == *i || '1' <= *i) << "Invalid placeholder: " << *i; |
| 852 if ('$' == *i) { | 851 if ('$' == *i) { |
| 853 while (i != format_string.end() && '$' == *i) { | 852 while (i != format_string.end() && '$' == *i) { |
| 854 formatted.push_back('$'); | 853 formatted.push_back('$'); |
| 855 ++i; | 854 ++i; |
| 856 } | 855 } |
| 857 --i; | 856 --i; |
| 858 } else { | 857 } else { |
| 859 uintptr_t index = *i - '1'; | 858 uintptr_t index = 0; |
| 859 while ('0' <= *i && '9' >= *i) { |
| 860 index *= 10; |
| 861 index += *i - '0'; |
| 862 ++i; |
| 863 } |
| 864 --i; |
| 865 index -= 1; |
| 860 if (offsets) { | 866 if (offsets) { |
| 861 ReplacementOffset r_offset(index, | 867 ReplacementOffset r_offset(index, |
| 862 static_cast<int>(formatted.size())); | 868 static_cast<int>(formatted.size())); |
| 863 r_offsets.insert(std::lower_bound(r_offsets.begin(), | 869 r_offsets.insert(std::lower_bound(r_offsets.begin(), |
| 864 r_offsets.end(), | 870 r_offsets.end(), |
| 865 r_offset, | 871 r_offset, |
| 866 &CompareParameter), | 872 &CompareParameter), |
| 867 r_offset); | 873 r_offset); |
| 868 } | 874 } |
| 869 if (index < substitutions) | 875 if (index < substitutions) |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1088 } | 1094 } |
| 1089 | 1095 |
| 1090 } // namespace | 1096 } // namespace |
| 1091 | 1097 |
| 1092 size_t base::strlcpy(char* dst, const char* src, size_t dst_size) { | 1098 size_t base::strlcpy(char* dst, const char* src, size_t dst_size) { |
| 1093 return lcpyT<char>(dst, src, dst_size); | 1099 return lcpyT<char>(dst, src, dst_size); |
| 1094 } | 1100 } |
| 1095 size_t base::wcslcpy(wchar_t* dst, const wchar_t* src, size_t dst_size) { | 1101 size_t base::wcslcpy(wchar_t* dst, const wchar_t* src, size_t dst_size) { |
| 1096 return lcpyT<wchar_t>(dst, src, dst_size); | 1102 return lcpyT<wchar_t>(dst, src, dst_size); |
| 1097 } | 1103 } |
| OLD | NEW |