diff options
author | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-17 03:45:37 +0000 |
---|---|---|
committer | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-17 03:45:37 +0000 |
commit | e6811ed52ec6c97dfb6d9073c8841d7f67bba082 (patch) | |
tree | 3d6a1abc880b89e94382f9f7c8e028d765f33508 /base/stringprintf.h | |
parent | e486aef731a84a591451ec7e92e79724757a737d (diff) | |
download | chromium_src-e6811ed52ec6c97dfb6d9073c8841d7f67bba082.zip chromium_src-e6811ed52ec6c97dfb6d9073c8841d7f67bba082.tar.gz chromium_src-e6811ed52ec6c97dfb6d9073c8841d7f67bba082.tar.bz2 |
Move StringPrintf into its own file and use the base namespace. Currently this has using
directives for the functions so I don't have to change all files to use the namespace.
No code changes to logic.
TEST=it compiles + the included unit tests
BUG=none
Review URL: http://codereview.chromium.org/3181016
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@56299 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/stringprintf.h')
-rw-r--r-- | base/stringprintf.h | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/base/stringprintf.h b/base/stringprintf.h new file mode 100644 index 0000000..43d60d4 --- /dev/null +++ b/base/stringprintf.h @@ -0,0 +1,56 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef BASE_STRINGPRINTF_H_ +#define BASE_STRINGPRINTF_H_ + +#include <stdarg.h> // va_list + +#include <string> + +#include "base/compiler_specific.h" + +namespace base { + +// Return a C++ string given printf-like input. +std::string StringPrintf(const char* format, ...) PRINTF_FORMAT(1, 2); +std::wstring StringPrintf(const wchar_t* format, ...) WPRINTF_FORMAT(1, 2); + +// Return a C++ string given vprintf-like input. +std::string StringPrintV(const char* format, va_list ap) PRINTF_FORMAT(1, 0); + +// Store result into a supplied string and return it. +const std::string& SStringPrintf(std::string* dst, const char* format, ...) + PRINTF_FORMAT(2, 3); +const std::wstring& SStringPrintf(std::wstring* dst, + const wchar_t* format, ...) + WPRINTF_FORMAT(2, 3); + +// Append result to a supplied string. +void StringAppendF(std::string* dst, const char* format, ...) + PRINTF_FORMAT(2, 3); +void StringAppendF(std::wstring* dst, const wchar_t* format, ...) + WPRINTF_FORMAT(2, 3); + +// Lower-level routine that takes a va_list and appends to a specified +// string. All other routines are just convenience wrappers around it. +void StringAppendV(std::string* dst, const char* format, va_list ap) + PRINTF_FORMAT(2, 0); +void StringAppendV(std::wstring* dst, const wchar_t* format, va_list ap) + WPRINTF_FORMAT(2, 0); + +} // namespace base + +// Don't require the namespace for legacy code. New code should use "base::" or +// have its own using decl. +// +// TODO(brettw) remove these when calling code is converted. +using base::StringPrintf; +using base::StringPrintV; +using base::SStringPrintf; +using base::StringAppendV; +using base::StringAppendF; +using base::StringAppendV; + +#endif // BASE_STRINGPRINTF_H_ |