| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/strings/string_util.h" | 5 #include "base/strings/string_util.h" |
| 6 | 6 |
| 7 #include <ctype.h> | 7 #include <ctype.h> |
| 8 #include <errno.h> | 8 #include <errno.h> |
| 9 #include <math.h> | 9 #include <math.h> |
| 10 #include <stdarg.h> | 10 #include <stdarg.h> |
| (...skipping 945 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 956 std::vector<string16> subst; | 956 std::vector<string16> subst; |
| 957 subst.push_back(a); | 957 subst.push_back(a); |
| 958 string16 result = ReplaceStringPlaceholders(format_string, subst, &offsets); | 958 string16 result = ReplaceStringPlaceholders(format_string, subst, &offsets); |
| 959 | 959 |
| 960 DCHECK_EQ(1U, offsets.size()); | 960 DCHECK_EQ(1U, offsets.size()); |
| 961 if (offset) | 961 if (offset) |
| 962 *offset = offsets[0]; | 962 *offset = offsets[0]; |
| 963 return result; | 963 return result; |
| 964 } | 964 } |
| 965 | 965 |
| 966 string16 Uint8VectorToString16(const std::vector<uint8_t>& input) { |
| 967 if (input.empty()) |
| 968 return string16(); |
| 969 |
| 970 return string16(reinterpret_cast<const char16*>(&input.front()), |
| 971 input.size() / sizeof(char16)); |
| 972 } |
| 973 |
| 974 std::vector<uint8_t> String16ToUint8Vector(const string16& input) { |
| 975 std::vector<uint8_t> result(input.size() * sizeof(char16)); |
| 976 if (!input.empty()) |
| 977 memcpy(&result.front(), input.c_str(), input.size() * sizeof(char16)); |
| 978 return result; |
| 979 } |
| 980 |
| 966 // The following code is compatible with the OpenBSD lcpy interface. See: | 981 // The following code is compatible with the OpenBSD lcpy interface. See: |
| 967 // http://www.gratisoft.us/todd/papers/strlcpy.html | 982 // http://www.gratisoft.us/todd/papers/strlcpy.html |
| 968 // ftp://ftp.openbsd.org/pub/OpenBSD/src/lib/libc/string/{wcs,str}lcpy.c | 983 // ftp://ftp.openbsd.org/pub/OpenBSD/src/lib/libc/string/{wcs,str}lcpy.c |
| 969 | 984 |
| 970 namespace { | 985 namespace { |
| 971 | 986 |
| 972 template <typename CHAR> | 987 template <typename CHAR> |
| 973 size_t lcpyT(CHAR* dst, const CHAR* src, size_t dst_size) { | 988 size_t lcpyT(CHAR* dst, const CHAR* src, size_t dst_size) { |
| 974 for (size_t i = 0; i < dst_size; ++i) { | 989 for (size_t i = 0; i < dst_size; ++i) { |
| 975 if ((dst[i] = src[i]) == 0) // We hit and copied the terminating NULL. | 990 if ((dst[i] = src[i]) == 0) // We hit and copied the terminating NULL. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 988 } // namespace | 1003 } // namespace |
| 989 | 1004 |
| 990 size_t strlcpy(char* dst, const char* src, size_t dst_size) { | 1005 size_t strlcpy(char* dst, const char* src, size_t dst_size) { |
| 991 return lcpyT<char>(dst, src, dst_size); | 1006 return lcpyT<char>(dst, src, dst_size); |
| 992 } | 1007 } |
| 993 size_t wcslcpy(wchar_t* dst, const wchar_t* src, size_t dst_size) { | 1008 size_t wcslcpy(wchar_t* dst, const wchar_t* src, size_t dst_size) { |
| 994 return lcpyT<wchar_t>(dst, src, dst_size); | 1009 return lcpyT<wchar_t>(dst, src, dst_size); |
| 995 } | 1010 } |
| 996 | 1011 |
| 997 } // namespace base | 1012 } // namespace base |
| OLD | NEW |