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

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

Issue 1410333006: Enough hacks to make wstring printfs unneeded (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 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
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/stringprintf.h" 5 #include "base/strings/stringprintf.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 8
9 #include <vector> 9 #include <vector>
10 10
(...skipping 11 matching lines...) Expand all
22 // large enough to accommodate the formatted string without truncation, they 22 // large enough to accommodate the formatted string without truncation, they
23 // return the number of characters that would be in the fully-formatted string 23 // return the number of characters that would be in the fully-formatted string
24 // (vsnprintf, and vswprintf on Windows), or -1 (vswprintf on POSIX platforms). 24 // (vsnprintf, and vswprintf on Windows), or -1 (vswprintf on POSIX platforms).
25 inline int vsnprintfT(char* buffer, 25 inline int vsnprintfT(char* buffer,
26 size_t buf_size, 26 size_t buf_size,
27 const char* format, 27 const char* format,
28 va_list argptr) { 28 va_list argptr) {
29 return base::vsnprintf(buffer, buf_size, format, argptr); 29 return base::vsnprintf(buffer, buf_size, format, argptr);
30 } 30 }
31 31
32 #if defined(OS_WIN) 32 /*#if defined(OS_WIN)
33 inline int vsnprintfT(wchar_t* buffer, 33 inline int vsnprintfT(wchar_t* buffer,
34 size_t buf_size, 34 size_t buf_size,
35 const wchar_t* format, 35 const wchar_t* format,
36 va_list argptr) { 36 va_list argptr) {
37 return base::vswprintf(buffer, buf_size, format, argptr); 37 return base::vswprintf(buffer, buf_size, format, argptr);
38 } 38 }
39 #endif 39 #endif*/
40 40
41 // Templatized backend for StringPrintF/StringAppendF. This does not finalize 41 // Templatized backend for StringPrintF/StringAppendF. This does not finalize
42 // the va_list, the caller is expected to do that. 42 // the va_list, the caller is expected to do that.
43 template <class StringType> 43 template <class StringType>
44 static void StringAppendVT(StringType* dst, 44 static void StringAppendVT(StringType* dst,
45 const typename StringType::value_type* format, 45 const typename StringType::value_type* format,
46 va_list ap) { 46 va_list ap) {
47 // First try with a small fixed size buffer. 47 // First try with a small fixed size buffer.
48 // This buffer size should be kept in sync with StringUtilTest.GrowBoundary 48 // This buffer size should be kept in sync with StringUtilTest.GrowBoundary
49 // and StringUtilTest.StringPrintfBounds. 49 // and StringUtilTest.StringPrintfBounds.
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 112
113 std::string StringPrintf(const char* format, ...) { 113 std::string StringPrintf(const char* format, ...) {
114 va_list ap; 114 va_list ap;
115 va_start(ap, format); 115 va_start(ap, format);
116 std::string result; 116 std::string result;
117 StringAppendV(&result, format, ap); 117 StringAppendV(&result, format, ap);
118 va_end(ap); 118 va_end(ap);
119 return result; 119 return result;
120 } 120 }
121 121
122 #if defined(OS_WIN) 122 /*#if defined(OS_WIN)
123 std::wstring StringPrintf(const wchar_t* format, ...) { 123 std::wstring StringPrintf(const wchar_t* format, ...) {
124 va_list ap; 124 va_list ap;
125 va_start(ap, format); 125 va_start(ap, format);
126 std::wstring result; 126 std::wstring result;
127 StringAppendV(&result, format, ap); 127 StringAppendV(&result, format, ap);
128 va_end(ap); 128 va_end(ap);
129 return result; 129 return result;
130 } 130 }
131 #endif 131 #endif*/
132 132
133 std::string StringPrintV(const char* format, va_list ap) { 133 std::string StringPrintV(const char* format, va_list ap) {
134 std::string result; 134 std::string result;
135 StringAppendV(&result, format, ap); 135 StringAppendV(&result, format, ap);
136 return result; 136 return result;
137 } 137 }
138 138
139 const std::string& SStringPrintf(std::string* dst, const char* format, ...) { 139 const std::string& SStringPrintf(std::string* dst, const char* format, ...) {
140 va_list ap; 140 va_list ap;
141 va_start(ap, format); 141 va_start(ap, format);
142 dst->clear(); 142 dst->clear();
143 StringAppendV(dst, format, ap); 143 StringAppendV(dst, format, ap);
144 va_end(ap); 144 va_end(ap);
145 return *dst; 145 return *dst;
146 } 146 }
147 147
148 #if defined(OS_WIN) 148 /*#if defined(OS_WIN)
149 const std::wstring& SStringPrintf(std::wstring* dst, 149 const std::wstring& SStringPrintf(std::wstring* dst,
150 const wchar_t* format, ...) { 150 const wchar_t* format, ...) {
151 va_list ap; 151 va_list ap;
152 va_start(ap, format); 152 va_start(ap, format);
153 dst->clear(); 153 dst->clear();
154 StringAppendV(dst, format, ap); 154 StringAppendV(dst, format, ap);
155 va_end(ap); 155 va_end(ap);
156 return *dst; 156 return *dst;
157 } 157 }
158 #endif 158 #endif*/
159 159
160 void StringAppendF(std::string* dst, const char* format, ...) { 160 void StringAppendF(std::string* dst, const char* format, ...) {
161 va_list ap; 161 va_list ap;
162 va_start(ap, format); 162 va_start(ap, format);
163 StringAppendV(dst, format, ap); 163 StringAppendV(dst, format, ap);
164 va_end(ap); 164 va_end(ap);
165 } 165 }
166 166
167 #if defined(OS_WIN) 167 /*#if defined(OS_WIN)
168 void StringAppendF(std::wstring* dst, const wchar_t* format, ...) { 168 void StringAppendF(std::wstring* dst, const wchar_t* format, ...) {
169 va_list ap; 169 va_list ap;
170 va_start(ap, format); 170 va_start(ap, format);
171 StringAppendV(dst, format, ap); 171 StringAppendV(dst, format, ap);
172 va_end(ap); 172 va_end(ap);
173 } 173 }
174 #endif 174 #endif*/
175 175
176 void StringAppendV(std::string* dst, const char* format, va_list ap) { 176 void StringAppendV(std::string* dst, const char* format, va_list ap) {
177 StringAppendVT(dst, format, ap); 177 StringAppendVT(dst, format, ap);
178 } 178 }
179 179
180 #if defined(OS_WIN) 180 /*#if defined(OS_WIN)
181 void StringAppendV(std::wstring* dst, const wchar_t* format, va_list ap) { 181 void StringAppendV(std::wstring* dst, const wchar_t* format, va_list ap) {
182 StringAppendVT(dst, format, ap); 182 StringAppendVT(dst, format, ap);
183 } 183 }
184 #endif 184 #endif*/
185 185
186 } // namespace base 186 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698