root/trunk/whisperlib/common/base/third-party/string_util.h

Revision 7, 2.2 kB (checked in by whispercastorg, 2 years ago)

version 0.2.0

Line 
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 //
5 // This file defines utility functions for working with strings.
6
7
8 //////////////////////////////////////////////////////////////////////
9
10 // WhisperSoft note: Picked from chromium/src/base/string_util.h
11
12 //////////////////////////////////////////////////////////////////////
13
14 #ifndef __COMMON_BASE_THIRD_PARTY_STRING_UTIL_H__
15 #define __COMMON_BASE_THIRD_PARTY_STRING_UTIL_H__
16
17 #include <string>
18 #include <vector>
19 #include <stdarg.h>   // va_list
20 #include <glib-2.0/glib/gmacros.h>
21 #include <whisperlib/common/base/types.h>
22 #include <whisperlib/common/base/common.h>
23
24 namespace strutil {
25
26 // Wrapper for vsnprintf that always null-terminates and always returns the
27 // number of characters that would be in an untruncated formatted
28 // string, even when truncation occurs.
29 int vsnprintf(char* buffer, size_t size, const char* format, va_list arguments);
30
31 // Some of these implementations need to be inlined.
32
33 inline int snprintf(char* buffer, size_t size, const char* format, ...) {
34   va_list arguments;
35   va_start(arguments, format);
36   int result = vsnprintf(buffer, size, format, arguments);
37   va_end(arguments);
38   return result;
39 }
40
41
42 // Specialized string-conversion functions.
43 std::string IntToString(int value);
44 std::string UintToString(unsigned int value);
45 std::string Int64ToString(int64 value);
46 std::string Uint64ToString(uint64 value);
47
48 // Return a C++ string given printf-like input.
49 std::string StringPrintf(const char* format, ...) G_GNUC_PRINTF (1, 2);
50
51
52 // Store result into a supplied string and return it
53 const std::string& SStringPrintf(std::string* dst,
54                                  const char* format, ...) G_GNUC_PRINTF (2, 3);;
55
56 // Append result to a supplied string
57 void StringAppendF(std::string* dst,
58                    const char* format, ...) G_GNUC_PRINTF (2, 3);;
59
60 // Lower-level routine that takes a va_list and appends to a specified
61 // string.  All other routines are just convenience wrappers around it.
62 void StringAppendV(std::string* dst, const char* format, va_list ap);
63
64 }
65
66
67 #endif  // __COMMON_BASE_THIRD_PARTY_STRING_UTIL_H__
Note: See TracBrowser for help on using the browser.