Reformat the WebRTC code base
Running clang-format with chromium's style guide.
The goal is n-fold:
* providing consistency and readability (that's what code guidelines are for)
* preventing noise with presubmit checks and git cl format
* building on the previous point: making it easier to automatically fix format issues
* you name it
Please consider using git-hyper-blame to ignore this commit.
Bug: webrtc:9340
Change-Id: I694567c4cdf8cee2860958cfe82bfaf25848bb87
Reviewed-on: https://webrtc-review.googlesource.com/81185
Reviewed-by: Patrik Höglund <phoglund@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#23660}
diff --git a/rtc_base/stringutils.h b/rtc_base/stringutils.h
index b42cfa5..d92ba02 100644
--- a/rtc_base/stringutils.h
+++ b/rtc_base/stringutils.h
@@ -37,7 +37,8 @@
// Generic string/memory utilities
///////////////////////////////////////////////////////////////////////////////
-#define STACK_ARRAY(TYPE, LEN) static_cast<TYPE*>(::alloca((LEN)*sizeof(TYPE)))
+#define STACK_ARRAY(TYPE, LEN) \
+ static_cast<TYPE*>(::alloca((LEN) * sizeof(TYPE)))
namespace rtc {
@@ -88,7 +89,7 @@
const size_t SIZE_UNKNOWN = static_cast<size_t>(-1);
-template<class CTYPE>
+template <class CTYPE>
struct Traits {
// STL string type
// typedef XXX string;
@@ -105,10 +106,10 @@
return str ? str : (def_str ? def_str : Traits<CTYPE>::empty_str());
}
-template<class CTYPE>
+template <class CTYPE>
const CTYPE* strchr(const CTYPE* str, const CTYPE* chs) {
- for (size_t i=0; str[i]; ++i) {
- for (size_t j=0; chs[j]; ++j) {
+ for (size_t i = 0; str[i]; ++i) {
+ for (size_t j = 0; chs[j]; ++j) {
if (str[i] == chs[j]) {
return str + i;
}
@@ -117,9 +118,9 @@
return 0;
}
-template<class CTYPE>
+template <class CTYPE>
const CTYPE* strchrn(const CTYPE* str, size_t slen, CTYPE ch) {
- for (size_t i=0; i < slen && str[i]; ++i) {
+ for (size_t i = 0; i < slen && str[i]; ++i) {
if (str[i] == ch) {
return str + i;
}
@@ -127,7 +128,7 @@
return 0;
}
-template<class CTYPE>
+template <class CTYPE>
size_t strlenn(const CTYPE* buffer, size_t buflen) {
size_t bufpos = 0;
while (buffer[bufpos] && (bufpos < buflen)) {
@@ -139,9 +140,11 @@
// Safe versions of strncpy, strncat, snprintf and vsnprintf that always
// null-terminate.
-template<class CTYPE>
-size_t strcpyn(CTYPE* buffer, size_t buflen,
- const CTYPE* source, size_t srclen = SIZE_UNKNOWN) {
+template <class CTYPE>
+size_t strcpyn(CTYPE* buffer,
+ size_t buflen,
+ const CTYPE* source,
+ size_t srclen = SIZE_UNKNOWN) {
if (buflen <= 0)
return 0;
@@ -155,9 +158,11 @@
return srclen;
}
-template<class CTYPE>
-size_t strcatn(CTYPE* buffer, size_t buflen,
- const CTYPE* source, size_t srclen = SIZE_UNKNOWN) {
+template <class CTYPE>
+size_t strcatn(CTYPE* buffer,
+ size_t buflen,
+ const CTYPE* source,
+ size_t srclen = SIZE_UNKNOWN) {
if (buflen <= 0)
return 0;
@@ -167,8 +172,10 @@
// Some compilers (clang specifically) require vsprintfn be defined before
// sprintfn.
-template<class CTYPE>
-size_t vsprintfn(CTYPE* buffer, size_t buflen, const CTYPE* format,
+template <class CTYPE>
+size_t vsprintfn(CTYPE* buffer,
+ size_t buflen,
+ const CTYPE* format,
va_list args) {
int len = vsnprintf(buffer, buflen, format, args);
if ((len < 0) || (static_cast<size_t>(len) >= buflen)) {
@@ -178,9 +185,9 @@
return len;
}
-template<class CTYPE>
+template <class CTYPE>
size_t sprintfn(CTYPE* buffer, size_t buflen, const CTYPE* format, ...);
-template<class CTYPE>
+template <class CTYPE>
size_t sprintfn(CTYPE* buffer, size_t buflen, const CTYPE* format, ...) {
va_list args;
va_start(args, format);
@@ -206,16 +213,22 @@
inline int ascnicmp(const char* s1, const char* s2, size_t n) {
return _strnicmp(s1, s2, n);
}
-inline size_t asccpyn(char* buffer, size_t buflen,
- const char* source, size_t srclen = SIZE_UNKNOWN) {
+inline size_t asccpyn(char* buffer,
+ size_t buflen,
+ const char* source,
+ size_t srclen = SIZE_UNKNOWN) {
return strcpyn(buffer, buflen, source, srclen);
}
#if defined(WEBRTC_WIN)
-typedef wchar_t(*CharacterTransformation)(wchar_t);
-inline wchar_t identity(wchar_t c) { return c; }
-int ascii_string_compare(const wchar_t* s1, const char* s2, size_t n,
+typedef wchar_t (*CharacterTransformation)(wchar_t);
+inline wchar_t identity(wchar_t c) {
+ return c;
+}
+int ascii_string_compare(const wchar_t* s1,
+ const char* s2,
+ size_t n,
CharacterTransformation transformation);
inline int asccmp(const wchar_t* s1, const char* s2) {
@@ -230,8 +243,10 @@
inline int ascnicmp(const wchar_t* s1, const char* s2, size_t n) {
return ascii_string_compare(s1, s2, n, tolowercase);
}
-size_t asccpyn(wchar_t* buffer, size_t buflen,
- const char* source, size_t srclen = SIZE_UNKNOWN);
+size_t asccpyn(wchar_t* buffer,
+ size_t buflen,
+ const char* source,
+ size_t srclen = SIZE_UNKNOWN);
#endif // WEBRTC_WIN
@@ -239,7 +254,7 @@
// Traits<char> specializations
///////////////////////////////////////////////////////////////////////////////
-template<>
+template <>
struct Traits<char> {
typedef std::string string;
inline static const char* empty_str() { return ""; }
@@ -251,7 +266,7 @@
#if defined(WEBRTC_WIN)
-template<>
+template <>
struct Traits<wchar_t> {
typedef std::wstring string;
inline static const wchar_t* empty_str() { return L""; }
@@ -297,17 +312,17 @@
#endif // WEBRTC_WIN
// Replaces all occurrences of "search" with "replace".
-void replace_substrs(const char *search,
+void replace_substrs(const char* search,
size_t search_len,
- const char *replace,
+ const char* replace,
size_t replace_len,
- std::string *s);
+ std::string* s);
// True iff s1 starts with s2.
-bool starts_with(const char *s1, const char *s2);
+bool starts_with(const char* s1, const char* s2);
// True iff s1 ends with s2.
-bool ends_with(const char *s1, const char *s2);
+bool ends_with(const char* s1, const char* s2);
// Remove leading and trailing whitespaces.
std::string string_trim(const std::string& s);