Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(274)

Side by Side Diff: base/strings/string_util.cc

Issue 1223983002: Move WriteInto to base namespace. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/strings/string_util.h ('k') | base/strings/utf_string_conversions_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 790 matching lines...) Expand 10 before | Expand all | Expand 10 after
801 } 801 }
802 802
803 void ReplaceSubstringsAfterOffset(std::string* str, 803 void ReplaceSubstringsAfterOffset(std::string* str,
804 size_t start_offset, 804 size_t start_offset,
805 StringPiece find_this, 805 StringPiece find_this,
806 StringPiece replace_with) { 806 StringPiece replace_with) {
807 DoReplaceSubstringsAfterOffset<std::string>( 807 DoReplaceSubstringsAfterOffset<std::string>(
808 str, start_offset, find_this, replace_with, true); // Replace all. 808 str, start_offset, find_this, replace_with, true); // Replace all.
809 } 809 }
810 810
811 template <class string_type>
812 inline typename string_type::value_type* WriteIntoT(string_type* str,
813 size_t length_with_null) {
814 DCHECK_GT(length_with_null, 1u);
815 str->reserve(length_with_null);
816 str->resize(length_with_null - 1);
817 return &((*str)[0]);
818 }
819
820 char* WriteInto(std::string* str, size_t length_with_null) {
821 return WriteIntoT(str, length_with_null);
822 }
823
824 char16* WriteInto(base::string16* str, size_t length_with_null) {
825 return WriteIntoT(str, length_with_null);
826 }
827
811 } // namespace base 828 } // namespace base
812 829
813 template<typename STR> 830 template<typename STR>
814 static STR JoinStringT(const std::vector<STR>& parts, const STR& sep) { 831 static STR JoinStringT(const std::vector<STR>& parts, const STR& sep) {
815 if (parts.empty()) 832 if (parts.empty())
816 return STR(); 833 return STR();
817 834
818 STR result(parts[0]); 835 STR result(parts[0]);
819 typename std::vector<STR>::const_iterator iter = parts.begin(); 836 typename std::vector<STR>::const_iterator iter = parts.begin();
820 ++iter; 837 ++iter;
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
956 } 973 }
957 974
958 } // namespace 975 } // namespace
959 976
960 size_t base::strlcpy(char* dst, const char* src, size_t dst_size) { 977 size_t base::strlcpy(char* dst, const char* src, size_t dst_size) {
961 return lcpyT<char>(dst, src, dst_size); 978 return lcpyT<char>(dst, src, dst_size);
962 } 979 }
963 size_t base::wcslcpy(wchar_t* dst, const wchar_t* src, size_t dst_size) { 980 size_t base::wcslcpy(wchar_t* dst, const wchar_t* src, size_t dst_size) {
964 return lcpyT<wchar_t>(dst, src, dst_size); 981 return lcpyT<wchar_t>(dst, src, dst_size);
965 } 982 }
OLDNEW
« no previous file with comments | « base/strings/string_util.h ('k') | base/strings/utf_string_conversions_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698